当前位置:网站首页>Centos7 Rsync + crontab scheduled backup

Centos7 Rsync + crontab scheduled backup

2020-11-10 10:41:00 osc_8grrbqh4

rsync Remote backup function

rsync Common options :

-v: Details output
-z: Compress during transmission --compress-level=NUM Can be compressed by level
-a: Archive mode transfers and preserves file properties equivalent to -rtopgDL
-r : Recursive mode
-t : Keep time attribute of file
-o: Keep the file primary
-p: Keep the file permission attribute
-g: Keep file group attribute
-D: Keep device file information
-l : Keep file soft links
-e: Using the specified protocol
–include=PATTERN: Specifies to exclude files that do not need to be transferred
–exclude-from=file: Read the exclusion from the file
-bwlimit=KBPS: Speed limit I / O bandwidth ; Per second KBytes
–delete: Delete files that do not exist in the source directory to make the target directory consistent with the source directory , Use with caution













crontab Cycle planning tasks

*   *    *    *    *
 branch    when     Japan     month     Zhou 

Prepare two virtual machine tests

192.168.27.137 Backup source
192.168.27.138 Backup side
 Insert picture description here

Turn off the firewall setenforce

[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0

Backup source operation

 install rsync
[root@localhost ~]# yum -y install rsync
 Modify the configuration file 
[root@localhost ~]# vim /etc/rsyncd.conf 
uid = nobody
gid = nobody
use chroot = yes
port 873
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
hosts allow = 192.168.27.0/24
[wwwroot]
path = /opt/aaa
comment = Document Root of www.51xit.top
read only =no
dont comperss = *.gz *.bz2 *.tgz *.zip *.rar *.z
auth users =tom
secrets file = /etc/rsyncd_users.db

[root@localhost ~]# mkdir /opt/aaa
 Set up an account   password 
[root@localhost ~]# vim /etc/rsyncd_users.db
tom:123

 Add authority 
[root@localhost ~]# chmod 600 /etc/rsyncd_users.db 
 start-up rsync  Check the port 
root@localhost ~]# rsync --daemon
[root@localhost ~]# netstat -nlput |grep 873
tcp        0      0 0.0.0.0:873             0.0.0.0:*               LISTEN      13360/rsync         
tcp6       0      0 :::873                  :::*                    LISTEN      13360/rsync         

Backup side operation

 install rsync
[root@localhost ~]# yum -y install rsync
 The backup only needs to set the user password 
[root@localhost ~]# vim /etc/server.pass
123

 Add authority 
[root@localhost ~]# chmod 600 /etc/server.pass 

 Set timing task   Execute every minute 
[root@localhost ~]# crontab -e
* * * * * rsync -az --password-file=/etc/server.pass tom@192.168.27.137::wwwroot /root/

[root@localhost ~]# crontab -l
* * * * * rsync -az --password-file=/etc/server.pass tom@192.168.27.137::wwwroot /root/

test

 Create a test on the backup side 
[root@localhost aaa]# cd /opt/aaa/
[root@localhost aaa]# touch a

 In the backup source, etc 1 Minutes to check   Is it synchronized 
[root@localhost ~]# ls
a

版权声明
本文为[osc_8grrbqh4]所创,转载请带上原文链接,感谢