Rsync is an acronym for “remote sync” which is a remote and local file synchronization tool. Rsync uses an algorithm that minimizes the amount of data copied by moving only parts of the files that have changed. Rsync came to life as a replacement in 1996 for the older rcp tool, with its new special features rsync quickly obsoleted rcp.
What is Rsync
Rsync is a remote data synchronization protocol. It allows a user to synchronize data between two node’s. When synchronizing the data rsync makes sure that both nodes hold the exact same data structure. If there are any differences, rsync detects these differences and sends across the differences, so the client or server can update their copy of the data.
Using Rsync
When transferring data between two nodes one must always pay attention to the underlying transport protocol, which can make a difference for your data security. Since rsync does not provide any security while transferring data it is recommended that you always use rsync over ssh session. This will allow you to setup a secure remote connection. Some common rsync command options are:
-a : archive mode
-r : recurse into directories
-z : compress file data
--delete : delete files that don't exist on sender (system)
-v : Verbose (try -vv for more detailed information)
-e "ssh options" : specify the ssh as remote shell
Copying data from a local node to a remote server
Below we will synchronize data from /var/www/ to a remote location called home.myserver.com:/var/www/ :
# rsync –avzr –e ssh /var/www/* someuser@home.myserver.com:/var/www/This will ensure that all the files and directories found on your local machine under /var/www will be copied over to your remote server home.myserver.com to /var/www. Copying data from a remote server to a local node Below we will copy a file called random.txt from one remote server home.myserver.com to a local computer /root directory:
# rsync –av -e ssh someuser@home.myserver.com:~/random.txt /rootMirror two directories
You can mirror a directory between two different nodes thus making sure that both sides hold the same data structure.
# rsync –zavrR –delete someuser@home.myserver.com:/etc/httpd /etc/httpd RSync Use Cases
Backup and restore of data
Incremental Versioning
Data upload/Download
The primary use case for rsync is to backup data from one node to another but people also use it to move large amounts of data between nodes. Users need to consider using rsync whenever large data transfers are required, here rsync will simplify file transfers between two or more nodes. Once you discover all features of rsync, it will allow you to configure complex backup operations and obtain more control over the data you want to transfer and how. Along the same topic, you can see another article about 11 Linux commands that could help you save some time ! Make sure to have a look !