linux rsync stands for remote sync which was written by Andrew Tridgell and Paul Mackerras back in 1996. It’s one of the most used and power ‘tools’ in the UNIX world and almost a standard for syncing data. Most Linux distributions have rsync pre-installed, but if it’s not there you can install the ‘rsync’ package for your distribution.
What is Rsync
Advantages and features of Rsync command
- rsync faster than scp (Secure Copy) ,because rsync uses remote-update protocol which allows to transfer just the differences between two sets of files. First time rysnc copies the whole content of a file or a directory from source to destination then the next time rsync copies only the changed blocks and bytes to the destination.
- Rsync consumes less bandwidth because it uses compression and decompression method while sending and receiving data both ends.
- Rsync Supports copying links, devices, owners, groups and permissions.
- its support remote copy.
Install rsync in Linux
yum install rsync
apt-get install rsync
The basic syntax of rsync
Common linux rsync options command
- -v : verbose
- -r : copies data recursively (but don’t preserve timestamps and permission while transferring data).
- -a : archive mode, archive mode allows copying files recursively .
- -z : Saves bandwidth over the network, by compress file data
- -h : human-readable, output numbers in a human-readable format
- -P : for partial progress.
- -e : To specify protocol name you want to use,for example if you are going to use the rsync with ssh protocol to backup or copy data remotely.
Use of –– delete Option :
rsync -a –-delete Source Destination
How to sync directories (remotely) over network
rsync -avzP ––delete -e ssh user@remote-server:source-directory /local-server-destination_directory/
Automate rsync backup
Now the best benefit and powerful part is to automate backup.
You can achieve this feature by creating cron job on Linux OS.
Run ‘crontab -e’ to create cron jobs. It will open an empty file where you can configure the command that you want to run at a desired time.
The format of crontab is quite simple; just pass the five fields followed by your rsync command:
m h dm m dw command
the following will run corn rsync every day at 6.30 PM:
30 18 * * * rsync your-source your-Destination