Rsync is a data image backup tool in Linux and UNIX systems. Its features are as follows:
1. images can be used to save the entire directory tree and file system.
2. It is easy to maintain the permissions, time, and soft links of the original file.
3. installation without special permissions.
4. optimized process, high file transmission efficiency.
5. You can use rcp, ssh, and other methods to transmit files. Of course, you can also use a direct socket connection.
6. Anonymous transmission is supported.
Today, we will use rsync + crontab to implement regular Incremental Backup between Linux servers.
Environment Description:
Work server A: IP address 192.168.1.86, operating system CentOS 5.5, user tom has been set up
Backup Server B: IP address 192.168.1.87, operating system CentOS 5.5, created user jack (uid 503, gid 503)
Purpose:
At every morning, the user directory/home on server A is automatically backed up to/home/jack/backup-A on server B, and Incremental backup is performed, no user interaction is required.
Configuration steps:
1. Configure Backup Server B
1) [root @ Server-B ~] # Rpm-qa | grep rsync # Check whether an rsync package exists
Rsync-2.6.8-3.1
The above output indicates that rsync has been installed to ensure that the following lines exist in/etc/services.
2) The rpm package of rsync does not contain the rsyncd configuration file. You need to manually create it (/etc/rsyncd. conf)
[Root @ Server-B ~] # Vi/etc/rsyncd. conf
3) Modify/etc/xinetd. d/rsync to enable the rsync service.
[Root @ Server-B ~] # Vi/etc/xinetd. d/rsync
4) Enable the rsyncd service and set the rsync service to load when the system starts.
[Root @ Server-B ~] #/Usr/bin/rsync -- daemon
5) check whether the rsync service is successfully started
The following content indicates that the instance has been started successfully.
6) Configure non-interactive login for ssh
Idea: server A generates A pair of RSA keys, keeps the private key on its own, attaches the private key to authorized_keys of login server B, A logs on to server B, and perform rsync from A to B without entering the password interactively.
> Generate A key pair on server A (executed as root)
> Remotely log on to backup server B and create a. ssh directory.
[Root @ Server-A ~] # Sshjack@192.168.1.87
...
[Jack @ Server-B ~] $ Mkdir. ssh; chmod 0700. ssh
> Run the following command on machine A to remotely copy the public key to machine B:
[Root @ Server-A ~] # Scp. ssh/id-rsa.pubroot@192.168.1.87:/home/jack/. ssh/authorized_keys
In this way, no interactive ssh Login is complete. Note that the. ssh directory permission of server B is preferably 700. If you grant it excessive permissions, no interactive logon may not take effect!
7) Prepare the backup script
Write A backup script on server A and place it in/home/tom/public_scripts named backup. sh.
#! /Bin/sh
TARGET_DIR = backup-
For SOURCE_DIR in "/home"
Do
Echo "Backing up $ SOURCE_DIR ..."
Rsync-au-delete $ SOURCE_DIRjack@192.168.1.87:/home/jack/$ TARGET_DIR
Done
[Root @ Server-A public_scripts] # chmod 755 backup. sh
The script permission is set to 755 so that other users can access it.
8) modify a scheduled task
Run the following command as root on server:
[Root @ Server-A ~] # Crontab-e
3 ***/home/tom/public_scripts/backup. sh