Rsync同步备份

一、Rsync 安装

每台服务器均需要安装rsync,但只要备份服务器端开启rsync即可

yum install rsync -y

#备份服务器开启
systemctl start rsynd
systemctl enable rsyncd

二、配置rsync【备份服务器端】

配置文件位置:/etc/rsyncd.conf

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

uid = root
gid = root
use chroot = no
max connections = 200
timeout = 300
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log

#同步xxxx目录
[test]                                #同步模块
path = /backups/test1/test-data/      #本地存放路径
ignore errors                         #忽略掉错误
read only = false                     #关闭只读模式
list = false
hosts allow =*                        #允许所有主机
auth users = root                     #认证用户
secrets file = /etc/rsyncd.secrets    #密码存放位置

三、配置秘钥

vim /etc/rsyncd.secrets
root:test1          #用户:密码 建议直接使用服务器root密码

#修改文件权限为600
chmod 600 /etc/rsyncd.secrets

四、配置客户端【传送资料端】

客户端只需配置秘钥即可,也无需开启rsync,直接使用rsync推送即可

vim /etc/rsyncd.secrets
test1          #直接配置密码,与目标端密码一致。

#修改文件权限为600
chmod 600 /etc/rsyncd.secrets

五、同步资料【传送端】执行命令即可

#命令参数详解
-a  使用归档传输
-z  传输过程中使用压缩/解压模式
--password-file  指定秘钥文件,上方已创建
--delete  删除接收服务器多余文件,与传输端文件一致,用于增量备份,并不会删传送端任何文件
--exclude 过滤掉不需要传输的文件,支持正则表达式(过滤掉log结尾的日志文件)
--exclude='atlassian/temp'  过滤掉整个文件夹,此路径为相对路径,不能使用绝对路径,该命令为推送/opt下所有文件, 所以会过滤掉/opt/atlassian/temp的文件夹

rsync -az --password-file=/etc/rsyncd.secrets --delete --exclude='atlassian/confluence/temp'  --delete  --exclude='*.log'  /opt/  root@x.x.x.x::test

六、rsync+sshpass 【备份服务器端去源文件服务器端拉取文件】

sshpass -p          #指定资源端服务器密码
rsync -az           #使用rsync
-e                  #指定ssh协议,-p 指定目标端ssh端口
root@X.X.X.X:/data  #资料端服务器 用户@IP:文件路径
/data/bak           #拉取存放至备份服务器存放路径

sshpass -p 'PASSWD' rsync -az -e 'ssh -p 22' --delete root@X.X.X.X:/data /data/bak

七、关于其他rsync的用法及参数 待写

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值