How to use the Rsync utility to synchronize files on ubuntu server 20.04

Louis SanchezAugust 14th 2021, 10:59

Follow these steps to synchronize files with Rsync:

Step 1 : Create a sample directory structure on the source server

cd ~
mkdir sampledir
touch sampledir/file{1..10}
ls -l sampledir

Step 2 : Now, use the following command to synchronize the entire directory from the source server to your local system.

rsync -azP -e ssh root@ backup

As this is the first time, all files from sampledir on the remote server will be downloaded in a backup directory on your local system.

Step 3 : You can check the downloaded files with the ls command:

ls -l backup

Step 4 : Add one new file on the remote server under sampledir

touch sampledir/file22

Step 5 : Now re-execute the rsync command on the destination server. This time, rsync will only download a new file and any other update files.

rsync -azP -e ssh root@ backup

Step 6 : To synchronize two local directories, you can simply specify the source and destination path with rsync, as follows:

rsync -azP /var/log/nginx ~/mysql_log_backup

Step 7 : Use the following command to push files to the remote server:

rsync -azP -e ssh backup/ root@