What exactly is Rsync?
Rsync is an efficient utility most commonly used when synchronizing files and directories between separate hosts. A typical example of rsync usage would be the following:
rsync -avz file root@remote-host:/home/
This command will open an SSH connection to the remote host, afterwards it will run rsync on the remote host which will compare which specific parts of the locally stored file are required to be transferred so that the remotely stored file is identical to the locally stored file. Then the file will be recursively transferred. The file titled “file1,” which is being transferred, will be stored in the directory “home” on the remote host. Compression using zlib will be used during the transfer. Verbose mode is also activated in order to give more information about the transfer.
Incremental and Differential Backups
In terms of design, Rsync is primarily intended as a tool for creating remote backups, therefore there are numerous advantages compared to other file transfer protocols, such as SCP or SFTP, especially if a large quantity of data is to be transferred. A differential backup takes a complete copy of a file and during the first transfer it only copies what differs from the first copy. While a differential backup may prove to be useful, if the number of your files increases in the future it becomes quite time-consuming to create a differential backup, especially if it is to be scheduled on a regular basis which is a typical approach when storing critical data.
This is where an incremental backup may prove to be useful. For example, let’s say we are transferring a large quantity of files stored in a directory on the local host to a remote host. Rsync transfers a whole file only the first time, the second time the directory is transferred, Rsync compares the file stored on the local host with the remote host and only transfers any changes or new files that exist in the local directory. This is based on the fact that by default Rsync uses the lqquick checkrq algorithm which finds files that have changed in size or in last-modified time through a checksum. Any changes in the other attributes are made on the destination file directly when the quick check indicates that the file’s data does not need to be updated. This is an example of an incremental backup method.
Rsync is able to transfer files partially, that means that if the transfer is interrupted, for example if the connection is dropped, Rsync will keep the partially transferred file on the remote host, this can be activated using the parameter –partial. By default, Rsync will delete the partially transferred file on the remote host if this parameter is not specified.
rsync -avz --partial file root@remote-host:/home/
Rsync uses the zlib compression library, it is therefore possible to use compression when transfering files to a remote host, this is particularly useful when you are limited by a slow connection. Compression can be specified with the following parameter -z
rsync -a -z files root@remote-host:/home/
Runs under non-superusers
Rsync does not require superuser privileges in order to start a transfer, this is particularly useful when creating various user accounts which are able to transfer files to a remote storage, since giving root permissions to everybody would normally pose a security risk.
Do you have any questions or comments? Contact Us