Rsync ( Remote Sync) is an open source command utility that provides fast incremental file transfer from one host to another. You can copy and synchronize your data with sync remotely and locally across directories, across disks and networks, perform data backups and mirroring between two Linux and Unix machines.
It is one of the lightweight application, because the file transfers are incremental. Rsync copies only the differences of files that have actually changed, compressed through ssh.You don’t need to be root user to run rsync command.
Some advantages and features of Rsync command
- Rsync allows encryption of data using ssh protocol during transfer.
- Supports copying links, devices, owners, groups and permissions.
- No special privileges are required to install and execute rsync
- 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 uses compression and decompression of data block by block at the sending and receiving end respectively. So the bandwidth used by rsync will be always less compared to other file transfer protocols.
Before you install Rsync on your server, make sure to run below commands as root user.
yum install rsync (On Red Hat based systems) apt-get install rsync (On Debian based systems)
Basic syntax of rsync command
# rsync options source destination
Some common options used with rsync commands
- -v : verbose
- -r : copies data recursively (but don’t preserve timestamps and permission while transferring data
- -a : archive mode, archive mode 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.
1. Copy/Sync Files and Directory Locally
The following command will sync a single file on a local machine from one location to another location.
[root@instance-1 log]# rsync -zvh log.tar /root/emre/newdirectory log.tar sent 43.61K bytes received 31 bytes 87.28K bytes/sec total size is 532.48K speedup is 12.20 "newdirectory" automatically created.