CentOS Linux使用rsync备份

rsync是Linux系统下的一个数据备份工具,很好用。假设服务端(被镜像端)IP为192.168.1.100,镜像端IP为192.168.1.200。

一、服务端设置

安装rsync:

yum install rsync

编辑配置文件:

vim /etc/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
hosts allow = *

[test]
path = /home/aaa
comment = this is a test
read only = true
list = yes
auth users = backup
secrets file = /root/rsync.pass

编辑rsync用户和密码:

vim /root/rsync.pass

输入:

backup:123456

格式为“用户名:密码”。

设置权限为600:

chmod 600 /root/rsync.pass

建立测试目录,里面随便放点东西:

mkdir /home/aaa

后台启动rsync:

/usr/bin/rsync –daemon –config=/etc/rsyncd.conf

二、镜像端设置

也要安装rsync:

yum install rsync

建立密码文件:

vim /root/rsyncpass

输入密码:

123456

设置权限为600:

chmod 600 /root/rsyncpass

执行备份命令:

/usr/bin/rsync -vrtopg –progress –delete backup@192.168.1.100::test /tmp –password-file=/root/rsyncpass

说明:
-v, –verbose 详细模式输出。
-r, –recursive 对子目录以递归模式处理。
-topg 保持文件原有属性。
–progress 指显示出详细的进度情况。
–delete 指如果服务器端删除了这一文件,那么客户端也相应把文件删除,保持一致。
backup@192.168.1.100::test表示,指定的用户@服务端IP::rsyncd.conf设置的那个模块。
/tmp,是这里镜像端保存目录。
–password-file 指定密码文件。

参考资料:
http://kangxiaowei.com/archives/8008.aspx