Synchronize files and folders between two remote servers with rsync

If you need to synchronize files or folders between one linux server and another you can use the rsync command from the linux command line.
This command is faster and has many options than the famous scp command.

Synchronize files and folders between two remote servers with rsync

rsync

First step, check the SSH connection between the two servers.

gabriele@server_1:~$ ssh gabriele@server_2

For the first connection, server_1 asks to be able to save the fingerprint key of server_2.

The authenticity of host 'server_1 (server_1)' can't be established.
ECDSA key fingerprint is f4:47:6a:f3:c2:e1:57:1d:e7:b9:9a:45:08:fe:bd:2a.
Are you sure you want to continue connecting (yes/no)?

Type Y or Yes then Enter.

If you have not configured authentication via public key, server_2 will ask for the password

Warning: Permanently added 'server_2' (RSA) to the list of known hosts.
Password:

Type your password and press enter to continue.

Now you have added the connection between server_1 to server_2, it is a good idea to configure this connection without password with a pub key, you will get a direct connection with no password prompt.

now you can synchronize with command “rsync source destination”

gabriele@server_1:~$ rsync -rtvz /home/gabriele/* server_2:/home/gabriele/

Wait until the process is complete, regardless of which user you are using for the transfer, check the permissions and privileges on the remote server after the transfer is complete.

The -rtvu option instead of -rtvz will update the files:

gabriele@server_1:~$ rsync -rtvu /home/gabriele/* server_2:/home/gabriele/