rsync配置两台服务器之间的文件备份(同步)

世上唯一不能复制的是时间,唯一不能重演的是人生,唯一不劳而获的是年龄。该怎么走,过什么样的生活,全凭自己的选择和努力。人生很贵,请别浪费!与智者为伍,与良善者同行。rsync配置两台服务器之间的文件备份(同步),希望对大家有帮助,欢迎收藏,转发!站点地址:www.bmabk.com,来源:原文

rsync配置两台服务器之间的文件备份(同步)

前情提要

环境:

  • 192.168.1.2 主服务器 centos 7.7
  • 192.168.1.3 备份服务器 centos 7.7

rsync 安装(两台linux都需要安装)

在linux环境下,以centos为例,安装非常简单:

[root@qinshengfei ~]# yum install rsync

rsync的配置文件(服务端配置)

rsync 服务端安装完成之后是没有生成rsync.conf文件的,需要手动创建rsyncd.conf

[root@qinshengfei ~]# vim /etc/rsyncd.conf
#先定义整体变量
secrets file = /etc/rsyncd.secrets          #配置同步用户名和密码
motd file = /etc/rsyncd.motd
read only = yes
list = yes
#uid = nobody
#gid = nobody
uid = root
gid = root
hosts allow = *    #哪些电脑可以访问rsync服务
hosts deny = 0.0.0.0/32    #哪些电脑不可以访问rsync服务
max connections = 2
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
  
#再定义要rsync的目录
[backup]
path = /data/app/files
list=yes
ignore errors
auth users = root
comment = welcome
exclude = file1/  file2/ 
  • 配置同步的用户名和密码
[root@qinshengfei ~]# vim /etc/rsyncd.secrets
  • 在rsyncd.secrets文件里配置一行即可
root:123456

rsync 备份测试(客户端执行)

 [root@qinshengfei ~]# rsync -arzvtopg --delete feng@192.168.1.2::bakup /opt/app/bakdir --password-file=/etc/rsyncd.secrets

rsync 定时备份(客户端配置)

在linux环境下,可以使用crontab和rsync结合起来做备份机制,找到/etc/crontab文件,在文件里追加这样一行

[root@qinshengfei ~]# vim /etc/crontab
40 19 * * * root rsync -aqzrtopg  --progress root@192.168.1.2::backup /opt/app/bakdir --password-file=/etc/rsyncd.secrets --log-file=/var/log/rsync.log 

释义:前面两个参数配置是:每天19:40定时同步

总结

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/240512.html

(0)
小半的头像小半

相关推荐

极客之音——专业性很强的中文编程技术网站,欢迎收藏到浏览器,订阅我们!