Automatic Incremental Backup Using rsync in linux

Source: Internet
Author: User
Tags rsync

Rsync is a data image backup tool in unix-like systems. It can be used not only in linux systems, but also in windows systems and cross-platform data backup. Now many webmasters use it.

Requirement: content on a server is backed up to a remote disaster recovery server on a regular basis every day. To save space and improve transmission efficiency, Incremental backup is used.
Expansion requirement: the two servers synchronize all data in a directory in one-way and two-way in real time.

Environment: cent OS 5 (5.4 5.5 5.6 tested), with rsync included in the system.
1. Install rsync (ignored if rsync is already installed)

The Code is as follows: Copy code

Wget http://rsync.samba.org/ftp/rsync/src/rsync-3.0.7.tar.gz
Tar xvfz rsync-3.0.7.tar.gz
Cd rsync-3.0.7
./Configure -- prefix =/usr/local/rsync
Make & make install

2. Configure rsync to create an rsyncd. conf file.

Vim/etc/rsyncd. conf

Enter the following content:

The Code is as follows: Copy code

Uid = nobody
Gid = nobody
Max connections = 36000
Use chroot = no
Log file =/var/log/rsyncd. log
Pid file =/var/run/rsyncd. pid
Lock file =/var/run/rsyncd. lock
[Htdocs]
Comment = backup htdocs
Path =/opt/htdocs/view
Ignore errors
Read only = yes
Host allow = *
Host deny = *
Secrets file =/etc/rsyncd. passwd
Auth users = bakccad

Modify:

The Code is as follows: Copy code

Vim/etc/rsyncd. passwd

Input:

The Code is as follows: Copy code
Username: 13577531

Run:

The Code is as follows: Copy code

Chmod 600/etc/rsyncd. conf
Chmod 600/etc/rsyncd. passwd

3. Start rsync on the server:

The Code is as follows: Copy code

/Usr/local/rsync/bin/rsync -- daemon

Client:
The client does not need to be installed. You only need to edit the password file and enter the password:

The Code is as follows: Copy code

Vim/etc/rsyncd. passwd

Input:
13577531
Run:

The Code is as follows: Copy code

Chmod 600/etc/rsyncd. passwd

The client can execute the following command to synchronize data from the server to the local machine:

The Code is as follows: Copy code

Rsync-azP -- delete bakccad@1.2.3.4: htdocs/opt/bakroot/rsyncwww/view -- password-file =/etc/rsync. passwd

In the command, htdocs is the name configured on the server. The following path is the saved path. The password file is followed by the password file. The password file only requires a password (if the client uses the user: passwd format, an error will occur ).

Attachment. If you only back up your data, you can use the shell command to back up the data.

Set in cron and execute at every Monday (full backup every Monday, Incremental backup for the rest of the time)

The Code is as follows: Copy code

# Vi backup. sh


Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/--> #! /Bin/bash

# Define
Dayofweek = 'date "+ % u "'
Today = 'date "+ % Y % m % d "'
Source =/data/
Backup =/backup/

# Action
Cd $ backup

If [$ dayofweek-eq 1]; then
If [! -F "full1_today.tar.gz"]; then
Rm-rf snapshot
Tar-g snapshot-zcf "full1_today.tar.gz" $ source -- exclude $ sourceserver. log
Fi
Else
If [! -F "inc$today.tar.gz"]; then
Tar-g snapshot-zcf "inc0000today.tar.gz" $ source -- exclude $ sourceserver. log
Fi
Fi

Back up the data in the directory you specified.

Related Article

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.