Rsync Command
Rsync (Remote Sync) is a most commonly used command for copying and synchronizing files and directories remotely as well as locally in Linux/Unix systems.
Some advantages and features of Rsync command
- It efficiently copies and sync files to or from a remote system.
- Supports copying links, devices, owners, groups and permissions.
- It’s 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, it copies the whole content of a file or a directory from source to destination but from next time, it copies only the changed blocks and bytes to the destination.
- Rsync consumes less bandwidth as it uses compression and decompression method while sending and receiving data both ends.
Install rsync in your Linux machine
# yum install rsync
Copy/Sync Files and Directory Locally
[root@feenixdv]# rsync -zvh backup.tar /tmp/backups/
Copy/Sync a Directory on Local Computer
[root@feenixdv]# rsync -avzh /root/rpmpkgs /tmp/backups/
Copy/Sync Files and Directory to or From a Server
[root@feenixdv]$ rsync -avz rpmpkgs/ root@192.168.0.101:/home/
Copy/Sync a Remote Directory to a Local Machine
[root@feenixdv]# rsync -avzh root@192.168.0.100:/home/rpmpkgs /tmp/myrpms
Use of –include and –exclude Options
[root@feenixdv]# rsync -avze ssh –include 'R*' –exclude '*' root@192.168.0.101:/var/lib/rpm/ /root/rp
[root@feenixdv]# rsync -rav -e ssh –include '*/' –exclude='*.dump' feenix@feenixd.com:/var/opt/data/flat/dba /opt/data/
Set the Max Size of Files to be transferred. Max file size is 200k, so this command will transfer only those files which are equal or smaller than 200k.
[root@feenixdv]# rsync -avzhe ssh –max-size='200k' /var/lib/rpm/ root@192.168.0.100:/root/tmprpm
Automatically Delete source Files after successful Transfer
[root@feenixdv]# rsync –remove-source-files -zvh backup.tar /tmp/backups/