Sync Up the Repository by Rsync

rsync server : 192.168.0.132 rsync client : 192.168.0.133
1. Check and Install rsync : [codesyntax lang="bash"]
$ rpm -q rsync
$ yum install rsync
[/codesyntax] or download and install from http://rsync.samba.org/
2. Configurations of rsync server (192.168.0.132) : [codesyntax lang="bash"]
$ vi /etc/rsyncd.conf
uid = root
gid = root
use chroot = no
max connections = 5
timeout = 3600
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log

[st]
path=/data/synctest/
auth user = kim
uid = root
gid = root
read only = true
list = false
ignore errors
host_allow =192.168.0.133
hosts deny = 0.0.0.0/32
secrets file = /etc/rsyncd.secrets
[/codesyntax]
3. User & Password : [codesyntax lang="bash"]
$ echo "kim:password" >> /etc/rsyncd.secrets
$ chown root:root /etc/rsyncd.secrets
$ chmod 600 /etc/rsyncd.secrets
[/codesyntax]
4. Open port 873 on both server and client : [codesyntax lang="bash"]
$ iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 873 -j ACCEPT
[/codesyntax]
5. Rsync daemon : [codesyntax lang="bash"]
# start
$ nohup /usr/bin/rsync --daemon --config=/etc/rsyncd.conf &
# stop
$ kill `cat /var/run/rsyncd.pid`
[/codesyntax]
6. Set autorun : [codesyntax lang="bash"]
$ echo '/usr/bin/rsync --daemon --config=/etc/rsyncd.conf' >> /etc/rc.local
[/codesyntax]or [codesyntax lang="bash"]
$ vi /etc/xinetd.d/rsync
set "disable" to no
[/codesyntax]


7. List all the files of remote dst-dir : [codesyntax lang="bash"]
$ rsync -r kim@192.168.0.133:/home/kim/
[/codesyntax]
8. Sync dir : [codesyntax lang="bash"]
# sync /data/synctest/ to /data/synctest2/
$ rsync -av --progress /data/synctest/ /data/synctest2/

# sync /data/synctest/ to /data/synctest2/ and delete the unsync files
$ rsync -av --progress --delete /data/synctest/ /data/synctest2/

# sync local /data/synctest/ to remote /home/kim/st/ :
$ rsync -avz --progress /data/synctest/ kim@192.168.0.133:/home/kim/st/

# sync remote folder /home/kim/st to be under /data/synctest/st
rsync -avz --progress kim@192.168.0.133:/home/kim/st /data/synctest/

# sync remote folder /home/kim/st/ to be /data/synctest/
rsync -avz --progress kim@192.168.0.133:/home/kim/st/ /data/synctest/
[/codesyntax]
Posted in RHEL| Tagged , |

Comments are closed.