Linux 下配置rsync同步备份数据

好久前安装的了,呵呵,好久不用了~~~现在整理出来,如果有不对的地方,望高手指正哈~~~电脑里东西太多了,有时间再好好验证一下:)

安装r sync 服务端

# tar zxvf rsync-3.0.4.tar.gz -C /opt/

# cd /opt/rsync-3.0.4/

# ./configure

# make

# make install

启动服务

# /usr/local/bin/rsync --daemon

自动启动设定

# echo "/usr/local/bin/rsync --daemon" >> /etc/rc.local

服务停止

# kill `cat /var/run/rsyncd.pid`

服务器端配置文件/etc/rsyncd.conf

# vi /etc/rsyncd.conf

uid = nobody

gid = nobody

use chroot = no

max connections = 2

pid file = /var/run/rsyncd.pid

lock file = /var/run/rsync.lock

log file = /var/log/rsyncd.log

[data]

path = /var/data            // 同步备份文件目录

ignore errors

read only = true

list = false

hosts allow = client_ip     // 客户端IP地址

hosts deny = 0.0.0.0/32

auth users =username

secrets file =/etc/backserver.pas

密码文件设定

# echo "username:password" >> /etc/backserver.pas

# chmod 400 /etc/backserver.pas

安装rsync客户端

# tar zxvf rsync-3.0.4.tar.gz -C /opt/

# cd /opt/rsync-3.0.4/

# ./configure

# make

# make install

密码文件设定

# echo "password" >> /etc/backserver.pas

# chmod 400 /etc/backserver.pas

备份计划设定

# crontab -e

* 1 * * *       /usr/local/bin/rsync -vzrtopg --delete --progress username@serverip::data /opt/rsync_bk/ --password-file=/etc/backserver.pas

前面五个*号含义如下:

分钟(0-59)小時(0-23) 日期(1-31) 月份(1-12) 星期(0-6//0是星期天

端命令:

# /usr/local/bin/rsync -vzrtopg --delete --progress backup@ serverip ::d

ata /opt/rsync_bk/ --password-file=/etc/backserver.pas

查看密码文件:

# cat /etc/backserver.pas

123     // 客户端的密码文件里只保存了密码