Rsync : Synchronize Files / Directories
2025/01/04 |
Copy files or directories from one location to an another localtion by [rsync]. Basic usage of [rsync] is here. For Localhost ⇔ RemoteHost synchronizing, SSH is used for secure connection, so SSH Server is needed on RemoteHost.
On this example, Configure and Run [rsync] as a daemon. This example is based on the environment like follows. +----------------------+ | +----------------------+ | [dlp.srv.world] |10.0.0.30 | 10.0.0.51| [node01.srv.world] | | +----------+----------+ rsyncd | | /home/work/* | -------------> | /home/backup/* | +----------------------+ copy +----------------------+ |
[1] | Configure on source host. |
[root@dlp ~]#
dnf -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 target host. |
[root@node01 ~]#
dnf -y install rsync rsync-daemon
[root@node01 ~]#
vi /etc/rsyncd.conf # add to last line pid file = /var/run/rsyncd.pid log file = /var/log/rsyncd.log max connections = 4 # logs transfer results or not transfer logging = yes # any name you like [backup] # target 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 mkdir /home/backup [root@node01 ~]# systemctl enable --now rsyncd |
[3] | On target host, if SELinux is enabled, change boolean setting. |
[root@node01 ~]# setsebool -P rsync_full_access on |
[4] | On target host, if Firewalld is running, allow service. |
[root@node01 ~]# firewall-cmd --add-service=rsyncd success [root@node01 ~]# firewall-cmd --runtime-to-permanent success |
[5] | That's OK, try to run [rsync] command on source Host. |
[root@dlp ~]#
rsync -avz --delete --exclude-from=/etc/rsync_exclude.lst /home/work/ node01.srv.world::backup sending incremental file list ./ anaconda-ks.cfg testfile.txt testscript.py testdir/ sent 141,832 bytes received 84 bytes 283,832.00 bytes/sec total size is 702,703 speedup is 4.95 |
|