Rsync is a versatile command-line tool that can be used for efficiently transferring and synchronizing files between local and remote systems. It is commonly used for backups, file transfer, mirroring, and everyday file copying.
How Rsync Works
Rsync uses a delta-transfer algorithm to reduce the amount of data that needs to be transferred. This algorithm works by comparing the checksums of the source and destination files. If the checksums of two files are the same, then the files are identical and no data needs to be transferred. If the checksums are different, then only the differences between the two files need to be transferred.
This delta-transfer algorithm is very efficient, especially for transferring files that have only been modified in small ways. For example, if you have a 100MB file that has only been changed by a single character, then rsync will only need to transfer that one character.
Rsync has a wide range of features that make it a powerful tool for file transfer and synchronization. These features include:
- Support for local and remote transfers: Rsync can be used to transfer files between local systems, as well as between local and remote systems.
- Support for recursive transfers: Rsync can be used to recursively transfer entire directories and subdirectories.
- Support for selective transfers: Rsync can be used to transfer only specific files or directories.
- Support for checksums: Rsync can be used to verify the integrity of files during transfer.
How to Use Rsync
The syntax for using rsync is relatively simple. The basic syntax is as follows:
rsync [options] source_path destination_path
For example, to transfer the contents of the
/etc/ directory on the local system to the
/backups/ directory on the remote system, you would use the following command:
rsync -a /etc/ remote_host:/backups/
-a option tells rsync to transfer all files and directories recursively, including hidden files and directories.
Rsync has a wide range of options that can be used to control its behavior. Some of the most commonly used options include:
-a: Transfer all files and directories recursively, including hidden files and directories.
-r: Transfer directories recursively.
-t: Transfer only files that have been modified since the last transfer.
-u:** Transfer only files that are newer on the destination system.
-v:** Display verbose output.
Examples of Rsync Usage
Here are some examples of how rsync can be used:
- To create a backup of the
rsync -a /etc/ /backups/
- To mirror the contents of the
/home/directory on two systems:
rsync -a -r /home/ local_host:/home/
- To transfer only the files that have been modified since the last transfer:
rsync -a -t /home/ local_host:/home/
- To transfer only the files that are newer on the destination system:
rsync -a -u /home/ local_host:/home/
Rsync is a powerful tool that can be used for a variety of file transfer and synchronization tasks. It is efficient, versatile, and easy to use.