Votes: 0Posted On: Jan 03, 2018 12:40:56
Rsync command is used to synchronize files between two directories between a local and a remote server. This can be used to backup files to a remote server. In case the local server crashes, your data is secured to a remote server that can be retrieved. Rsync comes with different variations with which you can sync files by as per your requirement.
There are generally two types of operations that can be performed using rsync. These are called Push and Pull operation. Copying of files from local to a remote server is called a "push" operation. Whereas, Copying of files from remote to local machine is called a pull operation.
Thera are some basic conditions that should be fulfilled before using the rsync command.
1. "rsync" should be installed on your system. To check if rsync is installed, run the following command.
2. If the rsync command is not installed, install it by running the following command.
RPM based Operating Systems - yum -y install rsync
Debian/Ubuntu - apt-get install rsync
3. Make sure that the IP is whitelisted on the firewall of both the remote and local system.
4. An established SSH connection between remote and local machine.
There are certain variations that can be used with the rsync command.
Copying files at a certain speed
You can specify the bandwidth limit in the rsync command to limit the transfer speed.
rsync -apW --bwlimit=xxxx /home/file/* firstname.lastname@example.org.:/home/file
(Note: Substitute the bandwidth in place of xxxx)
Displaying the progress of the operation
The "--progress" option displays the progress while the files are being transferred.
rsync -pavW --progress /home/file/* email@example.com.:/home/file
Slow network connections
For slow network connections, please use the following command as the "-z" option is used for file compression.
rsync -pavz --progress /home/file/* firstname.lastname@example.org.:/home/file
Sending files to remote machines with a different ssh port.
Sometimes the ssh port on the remote server is different from port 22 which is the default ssh port. In such a case, use the following command.
rsync -pavW --progress --inplace --rsh='ssh -p 2244' file/* email@example.com:/file
The options used above perform the various functions.
# "-a" option is the same as -rlptgoD. Here are some of the functions that "-a" option performs.
1.Descend recursively into all directories (-r),
2.copy symlinks as symlinks (-l),
3.Preserve file permissions (-p),
4.Preserve modification times (-t),
5.Preserve groups (-g),
6.Preserve file ownership (-o), and
7.preserve devices as devices (-D).
# "-z" option is used to compress files while sending them.
# "-P" option is the same as --partial and --progress.
--partial - It is used to resume the interrupted transfers.
--progress - It is used to display the progress bar of the transfers.
# "-v" - It is used to display the result in a more verbose manner.
The "rsync" command comes with numerous options. It is recommended to use the "man" command with rsync to master all the options.