rsync+crontab实现定时备份

环境搭建

  • CentOS Linux release 7.5.1804 (Core)
    关闭防火墙和selinux
    192.168.153.179 master
    192.168.153.178 backup

开始部署

  • master backup安装rsync服务
yum -y install rsync
  • master操作
vim /etc/rsyncd.conf
uid = root
gid = root
use chroot = yes
address = 192.168.153.179
port 873
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
hosts allow = 192.168.153.0/24
[git]
path = /opt/git
comment = Document Root of www.51xit.top
read only =no
dont comperss = *.gz *.bz2 *.tgz *.zip *.rar *.z
auth users =root
secrets file = /etc/secrets.pass

在这里插入图片描述
创建源目录

mkdir /opt/git

任意添加文件,之后测试时用

[root@localhost git]# pwd
/opt/git
[root@localhost git]# touch a
[root@localhost git]# ls
a

授权的账号和密码

vim /etc/secrets.pass

在这里插入图片描述
授权

chmod 600 /etc/secrets.pass

启动rsync服务并查看

rsync --daemon
ss -nltp|grep 873
LISTEN     0      5      192.168.153.179:873                      *:*     
  • backup操作

创建目录,此目录以存放服务器备份过来的数据目录

mkdir /opt/backgit

免密登录

vim /etc/secrets.backpass

在这里插入图片描述
授权

chmod 600 /etc/secrets.backpass

测试备份服务端数据

rsync -az --password-file=/etc/secrets.backpass [email protected]::git /opt/backgit

成功备份,加入crontab 定时任务

ls /opt/backgit/
a

定时任务每分钟 1 次,抓紧时间进行操作

[root@backup ~]# crontab -l
* * * * * rsync -az --password-file=/etc/secrets.backpass [email protected]::git /opt/backgit
  • server端
    删除文件 a 创建文件 xinzeng
pwd
/opt/git
rm -rf a
touch xinzeng
[root@server git]# ls
xinzeng
  • backup端
    1分钟后…

可以使用 ll 命令查看时间,这个自行选择~ _ ~
大功告成!!!

[root@backup backgit]# ls
a
[root@backup backgit]# ls
a  xinzeng
[root@backup backgit]# ll
总用量 0
-rw-r--r--. 1 root root 0 10月 29 13:47 a
-rw-r--r--. 1 root root 0 10月 29 14:13 xinzeng

完毕~ _ ~!!!

猜你喜欢

转载自blog.csdn.net/qq_49296785/article/details/109357530