服务器端:
1 安装:
# tar xvf sync-xxxx.tar.gz 或sync-xxx.tar.bz2
# cd sync-xxx
# ./configure --prefix=/usr/local/rsync ;make ;make install
or # rpm sync-XXXX.rpm
# cd sync-xxx
# ./configure --prefix=/usr/local/rsync ;make ;make install
or # rpm sync-XXXX.rpm
2 建立配置文件及密码文件:
配置文件:
vim /usr/local/rsync/rsyncd.conf
uid = nobody
gid = nobody
use chroot = no
max connections = 10
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
[web]
path = /usr/local/apache2/htdocs
comment = backup client is web
ignore errors
list = no
auth users = liuyu
secrets file = /usr/local/rsync/web.pas
uid = nobody
gid = nobody
use chroot = no
max connections = 10
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
[web]
path = /usr/local/apache2/htdocs
comment = backup client is web
ignore errors
list = no
auth users = liuyu
secrets file = /usr/local/rsync/web.pas
建立密码文件:
vim /usr/local/rsync/web.pas
liuyu:111111
chmod 600 /usr/local/rsync/web.pas
liuyu:111111
chmod 600 /usr/local/rsync/web.pas
3 启动服务:
/usr/bin/rsync --daemon --config=/usr/local/rsync/rsyncd.conf
4 查看启动情况 ps aux |grep rsync
root 26515 0.0 0.0 1760 460 ? S 2007 0:00 rsync --daemon --config=/usr/local/rsync/rsyncd.conf
备份服务器:
1 建立同步脚本
1 建立同步脚本
vim web.sh
#!/sbin/sh
#! backup web
DATE='date +%w'
/usr/bin/rsync -avzP --delete --password-file=/usr/local/rsync/web.pas liuyu@服务器IP::web /backup/web/$DATE > /var/log/rsync.$DATE
#!/sbin/sh
#! backup web
DATE='date +%w'
/usr/bin/rsync -avzP --delete --password-file=/usr/local/rsync/web.pas liuyu@服务器IP::web /backup/web/$DATE > /var/log/rsync.$DATE
2 建立密码文件
# echo "11111" > /backup/web.pas
#chmod 600 /backup/web.pas
#chmod 600 /backup/web.pas
3 运行脚本 可看到同步信息
4 加入crontab 每天晚上2点执行一次
0 2 * * * /backup/web.sh
配置完成!
本文转自守住每一天51CTO博客,原文链接:http://blog.51cto.com/liuyu/64067,如需转载请自行联系原作者