Rsync+sersync实现数据实时同步(小白的“升级打怪”成长之路)

rsync部署及数据同步脚本编写

目录

一、rsync部署

push推数据

1、编写rsync配置文件

2、备份测试

3、检验结果

二、rsync+sersync 实现数据实时同步

1、安装sersync服务

2、检验结果

pull拉取数据

1、编写rsync配置文件

2、检验结果

三、脚本编写

1、客户端脚本编写

2、服务器脚本编写


一、rsync部署

  • 服务器:source 192.168.58.130 (进行数据备份的主机)

  • 客户端:targetpc 192.168.58.131 (备份存储的主机)

push推数据

1、编写rsync配置文件

#192.168.58.131
# 在客户端上编写rsync配置文件,创建一个存放备份的同步目录
[root@targetpc ~]# vim /etc/rsyncd.conf 
# /etc/rsyncd: configuration file for rsync daemon mode
# See rsyncd.conf man page for more options.
# configuration example:
# uid = nobody
# gid = nobody
# use chroot = yes
# max connections = 4
# pid file = /var/run/rsyncd.pid
# exclude = lost+found/
# transfer logging = yes
# timeout = 900
# ignore nonreadable = yes
# dont compress   = *.gz *.tgz *.zip *.z *.Z *.rpm *.deb *.bz2
# [ftp]
#        path = /home/ftp
#        comment = ftp export area
​
​
#在这些内容后面加上下面的内容
#加上
port=873
address = 192.168.58.131
uid = root
gid = root
use chroot = yes
max connections = 4
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
motd file = /etc/rsyncd.motd
hosts allow = 192.168.58.0/24
[data]
path = /data/backup
comment = bakcup data
read only = false
list = yes
auth users = rsyncuser
secrets file = /etc/rsync.passwd
#192.168.58.131
# 创建密码文件,格式   用户名:密码
# 设置密码文件权限为600或者700
[root@targetpc ~]# touch /etc/rsync.passwd
[root@targetpc ~]# vim /etc/rsync.passwd 
rsyncuser:123456
[root@targetpc ~]# chmod 600 /etc/rsync.passwd
#192.168.58.131
# 创建欢迎信息文件
[root@targetpc ~]# echo "Welcome to Backup Server" > /etc/rsyncd.motd
​
[root@targetpc ~]# systemctl start rsyncd
[root@targetpc ~]# mkdir -p /data/backup
[root@targetpc ~]# cd /data/backup

2、备份测试

#192.168.58.130
[root@source ~]# mkdir /data
[root@source ~]# cd /data
[root@source data]# touch 1.txt
[root@source data]# mkdir aaa
[root@source data]# rsync -avz /data/* rsyncuser@192.168.58.131::data
Welcome to Backup Server
​
Password: 
sending incremental file list
1.txt
aaa/
​
sent 124 bytes  received 43 bytes  9.03 bytes/sec
total size is 0  speedup is 0.00
[root@source data]# touch 2.txt
[root@source data]# ls
1.txt  2.txt  aaa
[root@source data]# rsync -avz /data/* rsyncuser@192.168.58.131::data
Welcome to Backup Server
​
Password: 
sending incremental file list
2.txt
​
sent 137 bytes  received 36 bytes  9.89 bytes/sec
total size is 0  speedup is 0.00

3、检验结果

#192.168.58.131
[root@targetpc backup]# ls
1.txt  2.txt  aaa
​
​
[root@targetpc backup]# touch 3.txt
[root@targetpc backup]# ls
1.txt  2.txt  3.txt  aaa

#192.168.58.130
[root@source data]# rsync -avz --delete /data/ rsyncuser@192.168.58.131::data
Welcome to Backup Server
​
Password: 
sending increm
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值