Rsync is a very useful and widely used tool that can be used to transfer or synchronize files between local and remote servers. Rsync commands are executed through the shell, so an active Linux server is required, as well as an SSH client such as Terminal or PuTTY (for Windows). This tool is usually pre-installed into many Linux Operating Systems, however, it is possible to install it by running
sudo apt install rsync on Ubuntu and Debian or by executing
sudo yum install rsync on CentOS and Fedora.
The default syntax of file transfer using rsync is very simple
rsync [option] [source] [destination]
Here are some of the many options available:
-a | copy files recursively
-h | produce a readable output
--progress | displays the process while the command is being run
-q | processes running in the background will not be shown
-v | processes that are run will be written out for the user to read
-z | compress the data
More available options can be visible by running
To send files from local source to a remote server, you may follow this format
rsync [option] [source] user@hostname-or-ip:[destination path]
rsync -avh /home/test-rsync/ firstname.lastname@example.org:/home/receive-rsync/
In this example above, we are copying
test-rsync directory contents from a local server to a remote server
220.127.116.11. Files will be transferred to
receive-rsync directory on the new server while displaying the progress on the local server.
It is also possible to send files from a remote origin to a local server
A simple change in syntax will do the opposite:
rsync -avh email@example.com:/home/receive-rsync/ /home/test-rsync/
In this case, we have copied files from a remote server
18.104.22.168 to our local directory
Keep in mind that in both cases, we had to use the SSH password of a remote server for verification.
This is an easy way to migrate your files between the servers or easily sync them. However, it is important to note that this tool only transfers files but not services or packages so in case you are migrating from one server to another, make sure to manually install them.