rsync+crontab
- Environmental preparation
-
- [Server] 1. Install the server
- 2. Modify the configuration file
- 3. Create user and password files and assign permissions
- 4. Start in the background and verify the port
- [Client] 5. Install the server
- 6. Write a password file
- 7. Verify that it is synchronized
- 8. Join the scheduled task
- Error-prone point induction
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
- Parsing
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
[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
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
8. Join the scheduled task
crontab -e
- Write the inspection command in 7.3 into the supervision book and add scheduled tasks
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
- Error 1649 occurred
- Check whether the user name and password file of the server is correct
- Password file forgot to give permission
- 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
- With
ps -ef|grep rsync
the investigation process ID - Kill service
kill -9 进程号
- Background start
rsync --daemon
Finally, I wish every programmer work less overtime and have a good dream~-~