Backup in Linux

How to make sure the application has a backup!!

Table of contents

No heading

No headings in the article.

What to expect from a backup tool and when to consider a backup tool is sufficient

  1. Should provide incremental and full backup Incremental backup: Take care of backup from the last backup date Full backup: Take care of full backup

  2. File permission and ownership preservation: File permission and ownership should not change when the backup tool must retain it

  3. Backup must happen when system is least used and processed must be automated

RSYNC is linux tool to sync up files and directory

It copies files from one machine to one more server

Let us check on how to achieve this by below example

Step 1: Install git on your linux machine

sudo yum install git

image.png

Step 2: Clone the git project on your linux machine

git clone https://github.com/banago/simple-php-website.git

image.png

Step 3: Install rsync using below command. Please not as I am using centos, I have to use yum install if incase you are using a ubuntu machine please install using apt-get

sudo yum install rsync

image.png

Step 4: Create a directory for backup

mkdir backup

image.png

Step 5: Now run the below rsync command and specify the source and destination address

rsync -vr simple-php-website/ /home/osboxes/linux/backup/

In the above command -v is the verbose command -r is recursive -z will compress the files and be efficient when we copy the files over the network

image.png

We can see that files and directories present in the source directory are created in the destination

image.png

Please note :

  1. If in case we omit the '/' after the source directory then it will create the source directory as sub-directory in the destination
rsync -vr simple-php-website  /home/osboxes/linux/backup/
  1. Also observe that the timestamp won't be preserved in the above command at the destination

image.png

To preserve the timestamp use -a "archive mode"

Archive mode combines recursive mode, it preserves ownership and permission, it preserves symbolic links, and timestamp

Also, note that in case we have to preserve the ownership then we have to use rsycn in sudo mode

sudo rsync -avz simple-php-website  /home/osboxes/linux/backup/
  1. When we run the rsync command again observe it won't copy all the files again and intelligently only copy the files that are changed