架构的拓朴图如下:
部署实施:
Rsync服务端(备份服务器):
[[email protected] ~]# uname -r
3.10.0-327.el7.x86_64
#是否安装Rsync服务
[[email protected] ~]# rpm -qa | grep rsync
rsync-3.0.9-17.el7.x86_64
#建立用于备份的账户
[[email protected] ~]# useradd backup
[[email protected] ~]# passwd backup
#建立配置文件
[[email protected] ~]# vim /etc/rsyncd.conf
uid = root
gid = root
use chroot = yes
address = 127.76.88.55
port = 873
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
[backup114]
path = /backup/61.177.274.152
read only = false
auth users = backup
secrets file = /etc/rsyuser.db
[backup2]
path = /backup/192.168.10.2
read only = false
auth users = backup
secrets file = /etc/rsyuser.db
[backup143]
path = /backup/183.3.277.122
read only = false
auth users = backup
secrets file = /etc/rsyuser.db
[backup107]
path = /backup/61.111.244.117
read only = false
auth users = backup
secrets file = /etc/rsyuser.db
#建立授权备份的账户文件
[[email protected] ~]# vim /etc/rsyuser.db
backup:backup
[[email protected] ~]#chmod 600 /etc/rsyuser.db
#建立备份目录
[[email protected] backup]# mkdir /backup
[[email protected] backup]#chown -R backup.backup backup
[[email protected] backup]#mkdir -pv {61.177.274.152,192.168.10.2,183.3.277.122,61.111.244.117}
#启动服务
[[email protected] ~]# rsync --daemon
Rsync客户端(客户端操作基本一致,只是备份目录需要根据实际情况决定):
#建立密码文件:
[[email protected] ~]# cat > /etc/rsync.pass
backup
[[email protected] ~]#chmod 600 /etc/rsync.pass
#建立备份脚本,并且保留20天的备份数据:
#!/bin/bash
cd /root
tar -zcf phpstudy$(date +%F).tar.gz /phpstudy
rsync -arz --password-file=/etc/rsync.pass /root/phpstudy$(date +%F).tar.gz [email protected]::backup114/
find /root -mtime +20 -name "*.tar.gz" -exec rm -fr {} \;