rsync同步备份

一、服务器端、备份客户端安装 rsync 服务。

1、环境:

CentOS 6
主 IP:172.16.3.18
备 IP:172.16.3.19

2、安装 rsync 软件

#yum install rsync -y

3、iptables 开放 873 端口

#iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 873 -j ACCEPT
#service iptables save
#service iptables restart

二、server 服务端操作
IP: 172.16.3.18
1、需要备份的文件

web、service1、service2

2、rsync 配置文件示例(默认没有、需要收到创建)

# cat /etc/rsyncd.conf 
uid
= root gid = root use chroot = no max connections = 100 timeout = 30 strict modes = yes pid file = /var/run/rsyncd.pid lock file = /var/run/rsync.lock log file = /var/log/rsyncd.log hosts allow = 172.16.3.18 # hosts deny = * list = false auth users = user
# rsync同步使用的账户 secrets file
= /etc/user.passwd
# 需要手动创建密码文件 [web] path
= /home/web/ ignore errors read only = no write only = no [service1] path = /opt/service1/ ignore errors read only = no write only = no [service2] path = /opt/service2/ ignore errors read only = no write only = no

3、密码文件 /etc/user.passwd , (默认没有、需要收到创建)

# cat /etc/user.passwd
user:passwd
# 格式
用户:密码

4、启动默认守护进行:

#/usr/bin/rsync --daemon

5、检测进程

#ps -ef |grep rsync 
#netstat -ano |grep 873

二、客户端 bak 设置操作
备 IP:172.16.3.19

1.创建密码文件 /etc/user.passwd , 只写密码就可以。 (默认没有、需要收到创建)

#cat /etc/user.passwd
passwd
# 格式
密码

2、服务的目录 同步 到备机 bak 上:

1、备机 bak 同步服务端上的web
/usr/bin/rsync -vzrtopg --delete --progress --password-file=/etc/user.passwd salt@172.16.3.18::service /opt/bak/web/

2、bak 同步 service1 服务
/usr/bin/rsync -vzrtopg --delete --progress --password-file=/etc/user.passwd salt@172.16.3.18::service1 /opt/bak/service1/
3、bak 同步 service2 服务
/usr/bin/rsync -vzrtopg --delete --progress --password-file=/etc/user.passwd salt@172.16.3.18::service2 /opt/bak/service2/ # 注意 被同步的bak目录 在后,如果在前就是备的同步主的了。 # 备机本地的 bak 同步到服务端; /usr/bin/rsync -vzrtopg --delete --progress --password-file=/etc/user.passwd /opt/bak/web salt@172.16.3.18::web

三、 设置定时备份

1、同步脚本

# vi /opt/script/rsync-user.sh
/usr/bin/rsync -vzrtopg --delete --progress --password-file=/etc/user.passwd salt@172.16.3.18::service /opt/bak/web

2、定时同步(每周日零点进行同步)

crontab -e
0 0 * * 0 /opt/script/rsync-user.sh > /opt/script/rsync-user.txt

 

转载于:https://www.cnblogs.com/sharesdk/p/11481563.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值