rsync+crontab realizes regular backup

Environment setup

  • CentOS Linux release 7.5.1804 (Core)
    close the firewall and selinux
    192.168.153.179 master
    192.168.153.178 backup

Start deployment

  • master backup install rsync service
yum -y install rsync
  • master operation
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

Insert picture description here
Create source directory

mkdir /opt/git

Add files arbitrarily, and use it later when testing

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

Authorized account and password

vim /etc/secrets.pass

Insert picture description here
Authorization

chmod 600 /etc/secrets.pass

Start the rsync service and view

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

Create a directory to store the data directory backed up by the server

mkdir /opt/backgit

Password-free login

vim /etc/secrets.backpass

Insert picture description here
Authorization

chmod 600 /etc/secrets.backpass

Test backup server data

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

Successful backup, add crontab timing task

ls /opt/backgit/
a

Scheduled tasks once every minute, hurry up and operate

[root@backup ~]# crontab -l
* * * * * rsync -az --password-file=/etc/secrets.backpass [email protected]::git /opt/backgit
  • server
    delete file a create file xinzeng
pwd
/opt/git
rm -rf a
touch xinzeng
[root@server git]# ls
xinzeng

  • One minute later on the backup side ...

You can use the ll command to check the time, this is your own choice~ _ ~
You're done! ! !

[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

Finished~ _ ~ ! ! !

Guess you like

Origin blog.csdn.net/qq_49296785/article/details/109357530