Remote incremental backup via rsync (differential backup)

Source: Internet
Author: User
Tags chmod mkdir root directory rsync
Backup is an essential part of writing code, traditional backup, usually copy all the data to a place, and then labeled to indicate when the backup, this backup is called "Overall backup."
If you make a general backup, the disk space requirements are very large, especially when you back up large volumes of data, sometimes, for example, one weeks, only a small part of the content has been modified, but still need to back up all the time, it is clear that a waste of disk space, this time the incremental backup comes in handy, An incremental backup, also called a differential backup, is a name that backs up only the modified parts.
OK, nonsense said, to see how the actual operation, we use the software is the famous rsync, a lot of web site image is to use it to complete.

==================================
Environment Introduction:
==================================

Backup server: 192.168.10.3
Directories that need to be backed up:/var/www
Verify user name and password when backing up: Backup/secret
Backup client (Backup data repository): 192.168.10.4

Both client and server need to install Rsync package

===================================
Server-side configuration:
===================================
1. Installation

Using the system's own rsync tool, insert the system boot CD and install the Rsync tool via RPM.

If using the source package installation, is the classic compilation of three steps

2. Create a master configuration file

# vi/etc/rsyncd.conf
# # File Of/etc/rsyncd.conf
MOTD file=/var/rsync/welcome.msg
PID file =/var/rsync/rsyncd.pid
Lock file =/var/rsync/rsync.lock
Log file =/var/rsync/rsyncd.log


# # # need to back up the module
[WWW]
# The module name will be used after the
Comment = BBS
Path =/var/www/
Use chroot = no
Max connections = 4
Read Only = yes
List = False
UID = nobody
GID = Nobody
Secrets file =/etc/rsyncd.secrets
Hosts allow = 192.168.10.4
Hosts Deny = 0.0.0.0/0
Ignore errors = yes
Transfer logging = yes
Log format = "%a%f%l"
Auth users = Backup


The above defines 1 backup points, allowing only 192.168.10.4 connections and requiring authenticated user name backup
Then create the password file, each line format is: User name: Password, is clear text


# vi/etc/rsyncd.secrets
backup:123456
# chmod 600/etc/rsyncd.secrets

Create a log or run a directory
# Mkdir/var/rsync

3. Start the service
# rsync--daemon

4. Edit/etc/xinetd.d/rsync (Optional Step)

Rsync service monitoring is distributed uniformly by xinet

Service rsync

{
Disable = no #将此项改为no
Socket_type = Stream
wait = no
user = root
Server =/usr/bin/rsync
Server_args =--daemon
Log_on_failure + = USERID
}


Restart the xinetd to start the rsync service


# Service XINETD Restart


5. Check when Rsync starts
# Ps-ef | grep rsync

6. Stop the Service
# Kill ' Cat/var/rsync/rsyncd.pid '

====================
Configuration of the Client
====================
(1) Primary server backup to backup server
# RSYNC-VZRTOPG--delete--progress Backup@192.168.10.3::www/back


(2) Recovery of Backup server (primary server Read Only = no)
# RSYNC-VZRTOPG--delete--progress/back backup@192.168.10.3::www

(3) Incremental backup (mainly with this)

Backup requirements: All the data is unified into one root directory, the primary backup is named after each backup point, the incremental backup directory is increment, the incremental backup data for each backup point is placed under this directory, the directory is the current date, the format is 2007-08-11_11-22
The file directory tree is as follows:
/var/backup/Backup root directory
|---The home directory of the www/backup point 1, the data in this directory is the latest after the backup is completed
|---increment/incremental backup root directory
|---www/the difference between backup points 1/modify backup Data
|---2009-12-04_10-22 from the start of the backup to August 11 10:22, the modified data
|---2009-12-05_11-22 from 10:22 to 11:22, the modified data

Preparatory work:
Create backup root: Mkdir/var/backup, other directories are automatically created when they are backed up

Use the system's own rsync tool to insert the system boot CD and install the Rsync tool via rpm

# echo "Secret" >/etc/rsyncd.conf

Note that this is different from the server side, where you can write only the password

# chmod 600/etc/rsyncd.conf

The client basically does not have to configure what files. A script is OK.
# vi/etc/rc.d/init.d/rsync.sh

#!/bin/bash
unset verb Progress
For i in $*; Do
["$i" = "verb"] && verb=v
["$i" = "Progress"] && progress= "--progress"
Done
rsync_server=192.168.10.3 #rsync SERVER IP
Auth_user=backup
bakroot=/var/backup/
Inc_dir=increment
now= ' Date +%y-%m-%d_%h:%m '


[!-e $BAKROOT] && mkdir-p $BAKROOT
Passwd_file=/etc/rsyncd.conf
Passwd_perm= ' ls-l $PASSWD _file|awk ' {print '} '
If ["$PASSWD _perm"! = "-RW-------"]; Then
Echo-e "\nwarning:permission of passwd file changed to 0600 \ n";
chmod 0600 $PASSWD _file
Fi
Logfile=/var/log/rsync/rsyncbak.log
Excludes=/var/log/rsync/exclude_file
[!-e $EXCLUDES] && touch $EXCLUDES
backup_modules= "www" #如需备份多个目录, add the server-side module name inside "", separated by a space
options= "--force--ignore-errors--delete--delete-excluded \
--exclude-from= $EXCLUDES $progress \
--password-file= $PASSWD _file--backup "
Rm-f/var/log/rsync/log.*
Log_id=0 <

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.