Introduction
Rsync, sometimes known as Remote Sync, is a free command-line utility that allows you to transfer files and directories to both local and remote locations. Rsync is used for mirroring, backups, and data migration to other servers.
This program is quick and efficient, replicating only the changes from the source and allowing for customization.
Set up an SSH connection with the destination server.
Rsync over SSH can use a standard login with a password or a Private key for SSH authentication
In this example, I’m going to copy a file from Server A (192.168.182.130) located in /root/file-to-send.zip to Server B (192.168.182.131) and save it to /root/new-file.zip.
Step 1 : Connect to server A and locate the file.
$ ssh root@ServerA_ip
$ ls
Output:
root@local:~# ssh [email protected] [email protected]'s password: root@ServerA:~# ls file-to-send.zip
Step 2 : Use rsync to transfer the file.
$ rsync -avz /root/file-to-send.zip root@ServerB_ip:/root/new-file.zip
Output:
root@ServerA:~# rsync -avz /root/file-to-send.zip [email protected]:/root/new-file.zip sending incremental file list file-to-send.zip sent 10,600 bytes received 35 bytes 21,270.00 bytes/sec total size is 131,604 speedup is 12.37
When you transfer large files, it’s more user-friendly to have a progress bar with --progress.
Our command will become :
$ rsync -avz /root/file-to-send.zip root@ServerB_ip:/root/new-file.zip --progress
Output:
root@ServerA:~# rsync -avz /root/file-to-send.zip [email protected]:/root/new-file.zip --progress sending incremental file list file-to-send.zip 131,604 100% 94.26MB/s 0:00:00 (xfr#1, to-chk=0/1) sent 10,600 bytes received 35 bytes 7,090.00 bytes/sec total size is 131,604 speedup is 12.37
-v, –verbose:This option is used if the user wishes to know what the computer is doing while running the command.
-a, –archive:This option can be used to archive files when synchronization is taking place.
-z, –compress:This option can be used to compress the file being transferred to reduce data usage during synchronization.
Step 3 : Checking the transfer of file.
Finally, do not forget to verify that you have received the file on server B.
$ ssh rooot@ServerB_ip
$ ls
Output :
root@ServerA:~# ssh [email protected] root@ServerB:~# ls new-file.zip snap