作者:张华 发表于:2015-12-28
版权声明:可以任意转载,转载时请务必以超链接形式标明文章原始出处和作者信息及本版权声明
( http://blog.csdn.net/quqi99 )
急需使用rsync在家里的多台机器上同步相片。
sudo apt-get install rsync
sudo update-rc.d -f rsync remove
sudo update-rc.d rsync start 20 2 3 4 5 . stop 20 0 1 6 .
sudo update-rc.d rsync enable
[email protected]:~$ sudo sysv-rc-conf --list rsync
rsync 0:off 1:off 2:on 3:on 4:on 5:on 6:off
这时候就可以在一台机器上同步目录了:
rsync -avzur --progress --delete /bak/tmp/qnap/ /qnap/
在多台机器上同步目录:
rsync -rave "ssh -p 22 -l hua" -avzur --progress --delete 192.168.99.124:/qnap/ /qnap/
等价于:rsync -avzur --progress --delete [email protected]:/qnap/ /qnap/
也可以配置使用::qnap使用下列配置文件/etc/rsyncd.conf中的[qnap]模块:
sudo rsync -avrzP [email protected]::qnap qnap
[email protected]:~$ sudo rsync --list-only [email protected]::
++++++++++++++++++++++++++++++++++++++++++++++
Welcome to use quqi rsync services!
++++++++++++++++++++++++++++++++++++++++++++++
qnap This is qnap backup data
配置[qnap]模块的步骤如下:
sudo touch /etc/rsyncd.conf
sudo touch /etc/rsyncd.motd
[email protected]:~$ sudo cat /etc/rsyncd.motd
++++++++++++++++++++++++++++++++++++++++++++++
Welcome to use quqi rsync services!
++++++++++++++++++++++++++++++++++++++++++++++
sudo touch /etc/rsyncd.secrets
[email protected]:~$ sudo cat /etc/rsyncd.secrets
hua:Passw0rd
sudo chmod 600 /etc/rsyncd.secrets
sudo chown root:root /etc/rsyncd.secrets
[email protected]:~$ sudo cat /etc/default/rsync |grep ‘RSYNC_ENABLE‘
RSYNC_ENABLE=true
sudo /etc/init.d/rsync restart
sudo iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 873 -j ACCEPT
vi /etc/rsyncd.conf
pid file = /var/run/rsyncd.pid
port = 873
address = 192.168.99.124
#usermod -g root hua
uid = hua
gid = root
use chroot = yes
read only = yes
hosts allow=192.168.99.0/255.255.255.0 10.0.1.0/255.255.255.0
hosts deny=*
max connections = 5
motd file = /etc/rsyncd.motd
log file = /var/log/rsync.log
#transfer logging = yes
log format = %t %a %m %f %b
syslog facility = local3
timeout = 300
[qnap]
path = /qnap
list=yes # 可以使用rsync --list-only [email protected]::命令列出目录
ignore errors
auth users = hua,root
secrets file = /etc/rsyncd.secrets
comment = This is qnap backup data
exclude = tmp/ test/
例如,下列的/qnap目录是我通过iscsi挂载的qnap nas的一个目录,一次性通过一个命令(rsync -avzur --progress --delete /bak/Qsync/ /qnap/)将要在各个电脑上同步的数据拷到qnap之后,今后对数据的修改统一在/qnap目录修改,然后其他机器通过下列命令同步最新的数据:
sudo rsync -avrzP [email protected]::qnap /bak/Qsync/