I. experimental requirements
1. The backup machine needs to synchronize all files under the / app/java_project directory of the MIS server at 1:03 a.m. every day.
2. It is required to record the synchronization log to facilitate the analysis of synchronization failure.
II. Task analysis
1. Use crontab to write scheduled tasks
2. Use rsync for remote synchronization
3. Because it is a scheduled task, rsync is based on ssh service, so two servers are required to set up ssh password free login.
III. experimental topology
IV. introduction to the experimental environment
The server with IP 128 is the MIS server, and the directory where the code is stored is / app/java_project, which needs to be backed up.
The server with IP 129 is the code backup server, and the code on 128 server needs to be backed up to / backup / APP / Java project.
V. specific steps of the experiment
1. Two servers are configured with ssh password free login
129 server is required to be able to log on to 128 without password.
[root@back ~]# ssh-keygen //Generate key pair Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): Created directory '/root/.ssh'. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /root/.ssh/id_rsa. Your public key has been saved in /root/.ssh/id_rsa.pub. The key fingerprint is: 0d:8c:ee:fe:38:88:44:f9:1c:a3:8f:18:23:01:06:83 root@back The key's randomart image is: +--[ RSA 2048]----+ |= | |Eo o | |o . . o | |. o o. o | | o + o. S . | |+ o o. | |.= + .. | |. o o... | | oo. | +-----------------+ [root@back .ssh]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.189.128 //Copy public key to 128 host remotely The authenticity of host '192.168.189.128 (192.168.189.128)' can't be established. RSA key fingerprint is df:28:9d:09:a3:bf:52:a6:e5:ce:f2:a4:04:0d:b8:cc. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '192.168.189.128' (RSA) to the list of known hosts. root@192.168.189.128's password: Now try logging into the machine, with "ssh 'root@192.168.189.128'", and check in: .ssh/authorized_keys to make sure we haven't added extra keys that you weren't expecting.
[root@back .ssh]# ssh root@192.168.189.128 Last login: Sun Jul 21 22:45:44 2019 from 192.168.189.1 //test ssh Password free login completed
2. Enable rsync service (on MIS server)
Relevant documents are available https://www.cnblogs.com/feng0919/p/11223473.html
[root@MIS .ssh]# yum install rsync //Installed: rsync.x86_64 0:3.0.6-12.el6 //Complete! [root@MIS .ssh]# vim /etc/rsyncd.conf [java] path = /app/java_project/ log file = /tmp/rsync.log [root@MIS .ssh]# rsync --daemon
3. Script planned tasks
[root@back ~]# vim rstnc.sh #!/bin/bash rsync -a 192.168.189.128::java /backup/app/java_project/ [root@back ~]# chmod +x rstnc.sh [root@back ~]# crontab -e no crontab for root - using an empty one 03 01 * * * /root/rsync.sh &>/dev/null