使用 rsync 实现远程增量备份
A:服务器端
安装 rysnc
复制代码 代码如下:
Wget
http://rsync.samba.org/ftp/rsync/src/rsync-3.0.9.tar.gz
Tar zxvf rsync-3.0.9.tar.gz
Cd rsync-3.0.9
./configure
Make
Make install
建立rsync的配置文件
Vi /etc/rsyncd.conf
复制代码 代码如下:
uid = nobody
gid = nobody
use chroot = no
max connections = 10
strict modes = yes
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
[app]
path = /data0/htdocs/www/dz/ #备份的目录
comment = app file
ignore errors
read only = no
write only = no
hosts allow = *
hosts deny = 192.168.64.110
list = false
uid = root
gid = root
auth users = backup
secrets file = /etc/server.pass #认证文件
vim /etc/server.pass
复制代码 代码如下:
backup:123!@#qwe
chmod 600 /etc/server.pass #注意权限
防火墙端口873
启动rsync守护进程
/usr/local/bin/rsync –daemon
提示库文件不存在libiconv.so.2
Echo /usr/local/lib >/etc/ld.so.conf
Ldconfig
B客户端安装rsync
步骤同上
安装完成后 添加文件
Vi /etc/server.pass
复制代码 代码如下:
123!@#qwe
Chmod 600 /etc/server.pass
执行同步操作命令:
复制代码 代码如下:
/usr/local/bin/rsync -vzrtopg --delete --progress --exclude "*access*" --exclude "debug*" backup@192.168.64.200::app /home/sunyl/ --password-file=/etc/server.pass
sent 57309 bytes received 9366306 bytes 1108660.59 bytes/sec
total size is 23722989 speedup is 2.52
若出现错误 检查路径,密码等
查看日志 server: /var/log/rsyncd.log
在每天凌晨3点30分执行备份操作:
复制代码 代码如下:
Crontab –e
30 3 * * * /usr/local/bin/rsync -vzrtopg --delete --progress --exclude "*access*" --exclude "debug*" backup@192.168.64.200::app /home/sunyl/ --password-file=/etc/server.pass
本文为大家介绍了一个简单的rsync同步方法,供大家学习参考。