How to use the rsync command?
If you're wondering how to use rsync and what it is all about, you have come to the right place! Let's start with what rsync is, and then dive into an example.
What is rsync?
Rsync stands for "Remote Sync" and is a very popular remote and local file synchronization tool. t uses an algorithm that minimizes the amount of data copied by only moving the portions of files that have changed.
Features and advantages of the 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 a remote-update protocol which allows transferring just the differences between two sets of files. The 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 utilization as it uses compression and decompression method while sending and receiving data on both ends.
Basic syntax
The rsync command has the following syntax.
# rsync options source destination
The options are:
-v : verbose
-r : copies data recursively (but don’t preserve timestamps and permission while transferring data.
-a : archive mode, which allows copying files recursively and it also preserves symbolic links, file permissions, user & group ownerships, and timestamps.
-z : compress file data.
-h : human-readable, output numbers in a human-readable format.
Example
The most common example for this would be to copy or sync a file or directory from a local server to a remote server.
# rsync -avzh /root/rpmpkgs root@192.168.0.141:/root/
The authenticity of host '192.168.0.141 (192.168.0.141)' can't be established.
ED25519 key fingerprint is SHA256:bH2tiWQn4S5o6qmZhmtXcBROV5TU5H4t2C42QDEMx1c.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '192.168.0.141' (ED25519) to the list of known hosts.
root@192.168.0.141's password:
sending incremental file list
rpmpkgs/
rpmpkgs/httpd-2.4.37-40.module_el8.5.0+852+0aafc63b.x86_64.rpm
rpmpkgs/mod_ssl-2.4.37-40.module_el8.5.0+852+0aafc63b.x86_64.rpm
rpmpkgs/nagios-4.4.6-4.el8.x86_64.rpm
rpmpkgs/nagios-plugins-2.3.3-5.el8.x86_64.rpm
sent 3.74M bytes received 96 bytes 439.88K bytes/sec
total size is 3.74M speedup is 1.00
For more information on how to use rsync, please check out the source of the article that is listed here!
Hope this helps! ☺️