How To Synchronize A Directory From One Linux Server To Another Using Rsync

By Jason


...

In this tutorial we will be using Rsync to synchronize a directory from Linux ServerA to Linux ServerB over SSH using two CentOS servers.
To begin we recommend you setup SSH keys between the two servers. To do this you can follow our below tutorials though is not required :

How to Set Up SSH Keys with Linux Commandline
How to add your SSH public key to CentOS

First lets make sure RSYNC is installed.
yum install rsync

Ok now that we have confirmed rsync is installed lets synchronize a directory from one server to another using it.

In the different options provided we will assume the below: Server A (local server that we are logged into): 10.10.10.1 Server B (remote server): 10.10.10.2 Option 1: Synchronize a folder from a remote server to the local server
rsync -r -a -v -e "ssh -l root" --delete 10.10.10.2:/home/test /home


The command above will sync the directory /home/test from the remote server to our local server in the directory /home. The output should look similar :
# rsync -r -a -v -e "ssh -l root" --delete 10.10.10.2:/home/test /home
root@10.10.10.2's password:
receiving incremental file list
test/
test/test.txt

sent 34 bytes  received 103 bytes  39.14 bytes/sec
total size is 0  speedup is 0.00
**NOTE : If your server uses a different SSH port then 22, then you would use the command below. **
rsync -r -a -v -e "ssh -p2222 -l root" --delete 10.10.10.2:/home/test /home
Option 2: Synchronize a folder from the local server to the remote server
rsync -r -a -v -e "ssh -l root" --delete /home/test 10.10.10.2:/home


The command above will sync the directory /home/test from the local server to our remote server in the directory /home. The output should look similar :
# rsync -r -a -v -e "ssh -l root" --delete /home/test 10.10.10.2:/home
root@10.10.10.2's password:
sending incremental file list
test/
test/test.txt

sent 102 bytes  received 35 bytes  30.44 bytes/sec
total size is 0  speedup is 0.00
**NOTE : If your server uses a different SSH port then 22, then you would use the command below. **
rsync -r -a -v -e "ssh -p2222 -l root" --delete /home/test 10.10.10.2:/home



Tags: , , , , ,

Spin up a cloud server in no time flat

Simple setup. Full root access. Straightforward pricing.

DEPLOY SERVER

Leave a Reply



Feedbacks