Release the overtime of the programmer, rsync+crontab completes regular synchronization, good night and a good night’s sleep

Environmental preparation

Two centos7, turn off the firewall and selinux

[Client]——192.168.112.153
[Server]——192.168.112.172

  • During execution, the server and the client can copy files to each other, which can be understood as a backup between the two servers. Here the configuration file of the server is modified, and the backup is the server, and there are new changed directories/files.

[Server] 1. Install the server

yum -y install rsync

2. Modify the configuration file

vim /etc/rsyncd.conf
uid = root
gid = root
use chroot = yes
address = 192.168.112.172
port 873
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
hosts allow = 192.168.112.0/24
[git]
path = /var/opt/gitlab/backups
comment = Document Root of www.51xit.top
read only =no
dont comperss = *.gz *.bz2 *.tgz *.zip *.rar *.z
auth users =root
secrets file = /etc/rsync.cc
  • ParsingInsert picture description here

The path of the path can be set by yourself, if it is a new path, remember to create a directory! ! !

3. Create user and password files and assign permissions

echo 'root:123456' > /etc/rsync.cc
chmod 600 /etc/rsync.cc

4. Start in the background and verify the port

rsync --daemon
netstat -nlpt |grep 873

Insert picture description here

[Client] 5. Install the server

yum -y install rsync

6. Write a password file

echo '123456' > /etc/rsync.cc
  • Same permission
chmod 600 /etc/rsync.cc

7. Verify that it is synchronized

1) Create a directory

mkdir  /home/data

2) Switch to the server to simulate directory/file changes

Insert picture description here

3) Switch to the client and test synchronization

rsync -az --password-file=/etc/rsync.cc root@192.168.112.172::git /home/data/
  • If you need to maintain consistency with the server file, you can add the -delete parameter
  • -Delete means that if the server deletes this file, then the client deletes the file accordingly, keeping the real consistency

Verification diagram

Insert picture description here

8. Join the scheduled task

crontab -e
  • Write the inspection command in 7.3 into the supervision book and add scheduled tasks
    Insert picture description here
    Insert picture description here

Basic crontab format:

* * * * * command
time-sharing day month week command

  • The first column indicates the minutes 1~59 each minute with * or */1
  • The second column indicates hours 1 to 23 (0 means 0 o'clock)
  • The third column indicates dates 1~31
  • The fourth column represents the month 1-12
  • The fifth column identification number week 0~6 (0 means Sunday)
  • Command to be run in column 6

Error-prone point induction

Insert picture description here

  • Error 1649 occurred
  1. Check whether the user name and password file of the server is correct
  2. Password file forgot to give permission
  3. Check whether the server side and the client side are consistent
  • Other errors reported may be configuration file errors, carefully check the path and ip
  1. With ps -ef|grep rsyncthe investigation process ID
  2. Kill service
kill -9 进程号
  1. Background start
rsync --daemon

Finally, I wish every programmer work less overtime and have a good dream~-~
Insert picture description here

Guess you like

Origin blog.csdn.net/qing1912/article/details/109363417