Ubuntu 18.04
Sponsored Link

Rsync : Sync Files/Directories2018/11/29

 
Configure Rsync to sync files or directories to localhost or remotehost.
Basic usage of rsync command is here.
For Local <=> Remote sync, when using rsync command, SSH protocol is used by default, so it needs SSH Server is running on the remotehost.
On this example, Configure Rsync as a service.
To run Rsync daemon, it's easy to configute synchronization settings and also Rsync uses 873/TCP port, not uses SSH, so it doesn't need SSH Service on remotehost.
For example, Configure Rsync to copy files and directories under the [/root/work] on dlp.srv.world to [/home/backup] on node01.srv.world.

+----------------------+          |          +----------------------+
|     dlp.srv.world    |10.0.0.30 | 10.0.0.51|   node01.srv.world   |
|                      +----------+----------+                      |
|     /root/work/*     |   ------------->    |     /home/backup/*   |
+----------------------+        copy         +----------------------+

[1] Configure on source host.
root@dlp:~#
apt -y install rsync
root@dlp:~#
vi /etc/rsync_exclude.lst
# specify files or directories you'd like to exclude to copy

test
test.txt

[2] Configure on destination host.
root@node01:~#
apt -y install rsync
root@node01:~#
vi /etc/rsyncd.conf
# create new

# any name you like
[backup]
# destination directory to copy
path = /home/backup
# hosts you allow to access
hosts allow = 10.0.0.30
hosts deny = *
list = true
uid = root
gid = root
read only = false

root@node01:~#
mkdir /home/backup

root@node01:~#
systemctl start rsync

[3] It's OK. Execute rsync on Source Host like follows.
root@dlp:~#
rsync -avz --delete --exclude-from=/etc/rsync_exclude.lst /root/work/ node01.srv.world::backup
# Add in cron if you'd like to run reguraly

root@dlp:~#
# for example, run at 2:00 AM in a day

00 02 * * * rsync -avz --delete --exclude-from=/etc/rsync_exclude.lst /root/work/ node01.srv.world::backup
Matched Content