ubuntu下rsync同步文件

有两个本 都写自己的一些文档 同步是个问题 所以想到了rsync
步骤如下:
服务端:IP 为192.168.1.94
root@lxu-laptop:/usr/share/doc/rsync/examples# pwd
/usr/share/doc/rsync/examples
root@lxu-laptop:/usr/share/doc/rsync/examples# ls
logrotate.conf.rsync rsyncd.conf
root@lxu-laptop:/usr/share/doc/rsync/examples# cp rsyncd.conf /etc/
root@lxu-laptop:/usr/share/doc/rsync/examples# > /etc/rsyncd.conf
root@lxu-laptop:/home/lxu# cat /etc/rsyncd.conf
uid = root
gid = root
use chroot = no
max connections = 4
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
[home]                                
path = /home/lxu/aibang                
comment = BACKUP DOCUMENT        
ignore errors                   
read only = yes                
list = no                     
hosts allow = 192.168.1.0/24
auth users = root           
secrets file = /etc/backserver.pass
root@lxu-laptop:/home/lxu# ls -al /etc/backserver.pass
-rw------- 1 root root 13 2009-07-27 16:09 /etc/backserver.pass
root@lxu-laptop:/home/lxu# cat /etc/backserver.pass
root:suantop

/usr/bin/rsync --daemon
lsof -i:873
客户端 192.168.1.198
cat /etc/backserver.pass
suantop
权限是600

/usr/bin/rsync -vzrtopg --delete --progress --password-file=/etc/backserver.pass root@192.168.1.94::home /home/lxu/aibang
这样就同步我的192.168.1.94 的/home/lxu/aibang 到我客户端192.168.1.198

同样道理如果198这边更新了要同步到94那边
把198配置成一个服务端
如下:
root@lxu:~# cat /etc/rsyncd.conf
uid = root
gid = root
use chroot = no
max connections = 4
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
[home]                                
path = /home/lxu/aibang/                 
comment = BACKUP DOCUMENT        
ignore errors                   
read only = yes                
list = no                     
hosts allow = 192.168.1.0/24    
auth users = root           
secrets file = /etc/backserver.pas

root@lxu:~# ls -al /etc/rsyncd.conf
-rw-r--r-- 1 root root 469 2009-07-27 17:08 /etc/rsyncd.conf
root@lxu:~# cat /etc/backserver.pas
root:aibang
在现在的客户端94上执行下面
/usr/bin/rsync -vzrtopg --delete --progress --password-file=/etc/backserver.pas root@192.168.1.198::home /home/lxu/aibang
root@lxu-laptop:~# ls -al /etc/backserver.pas
-rw------- 1 root root 7 2009-07-27 17:10 /etc/backserver.pas
root@lxu-laptop:~# cat /etc/backserver.pas
aibang


发表评论

电子邮件地址不会被公开。 必填项已用*标注

9 + 1 =