Backing up with RSYNC


Backing up with RSYNC

RSYNC is a program that is widely used for backing up data. RSYNC is able to create full, as well as incremental backups, and is pretty easy to use. Moreover, RSYNC can also be used to backup data into remote machines. When backing up to remote machine, RSYNC can utilize SSH which means the communication is being protected by one of the world’s strongest protections. Here’s how RSYNC can be used –

Objective

  1. All files in the directory /original needs to be backed up at /backup. The process must be repeated every 10 days.
  2. The directory /backup needs to be backed up at 192.168.10.254:/backup2. The process must be repeated every 15 days.

Phase 1:

We are using the –a option for ‘archive’ . Archive is used to preserve permissions. The –v option is used for ‘verbose’ output.

root@firefly:~# ls -l /original/
total 0
-rw-r--r-- 1 root root 0 Dec 21 19:40 f1
-rw-r--r-- 1 root root 0 Dec 21 19:40 f2
-rw-r--r-- 1 root root 0 Dec 21 19:40 f3
-rw-r--r-- 1 root root 0 Dec 21 19:40 f4
-rw-r--r-- 1 root root 0 Dec 21 19:40 f5
-rw-r--r-- 1 root root 0 Dec 21 19:40 f6
-rw-r--r-- 1 root root 0 Dec 21 19:40 f7
-rw-r--r-- 1 root root 0 Dec 21 19:40 f8

This is the list of files to be backed up.

root@firefly:~# rsync -av /original/ /backup/
sending incremental file list
./
f1
f2
f3
f4
f5
f6
f7
f8

sent 401 bytes  received 167 bytes  1136.00 bytes/sec
total size is 0  speedup is 0.00

root@firefly:~# ls -l /backup/
total 0
-rw-r--r-- 1 root root 0 Dec 21 19:40 f1
-rw-r--r-- 1 root root 0 Dec 21 19:40 f2
-rw-r--r-- 1 root root 0 Dec 21 19:40 f3
-rw-r--r-- 1 root root 0 Dec 21 19:40 f4
-rw-r--r-- 1 root root 0 Dec 21 19:40 f5
-rw-r--r-- 1 root root 0 Dec 21 19:40 f6
-rw-r--r-- 1 root root 0 Dec 21 19:40 f7
-rw-r--r-- 1 root root 0 Dec 21 19:40 f8

As we can see, all the files have been copied to the destination directory. While using RSYNC, we need to keep in mind that RSYNC is sensitive about the trailing ‘/’ in the source argument. To RSYNC, ‘/original’ and ‘/original/’ are not the same thing.

To repeat the task every 10 days, we would add the following crond rule-

Min
Hour
Day of Month
Month
Day of Week
Command
00
02
*/10
*
*
rsync -av /original/ /backup/

 

Phase 2

Here, we would copy the directory /backup from the source machine to the remote machine’s directory /backup2. Here’s how it’s done-

root@localhost:~# rsync -av -e ssh /backup/ 192.168.10.254:/backup2

That wasn’t hard, was it? The only remaining thing to do is to add a scheduled task with the help of crond.

Min
Hour
Day of Month
Month
Day of Week
Command
00
04
*/15
*
*
rsync -av -e ssh /backup/ 192.168.10.254:/backup2


And that’s it. Hope it helps.  ^_^

Comments