Linux under Rsync to implement automatic incremental backup

Source: Internet
Author: User
Tags chmod rsync

Requirements: Content on a server, scheduled daily backup to remote disaster-tolerant server. To save space and improve transmission efficiency, use incremental backups.
Expansion requirements: Two servers in real time one-way, bidirectional synchronization of all data in a directory.

Environment: Cent OS 5 (5.4 5.5 5.6 test pass), system with rsync.
1. Install rsync (already installed can be ignored)

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 a 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

Perform:

The code is as follows Copy Code

chmod 600/etc/rsyncd.conf
chmod 600/etc/rsyncd.passwd

3. Start rsync in server-side mode:

The code is as follows Copy Code

/usr/local/rsync/bin/rsync--daemon

Client:
Client does not need to install, just edit password file Enter password:

The code is as follows Copy Code

vim/etc/rsyncd.passwd

Input:
13577531
Perform:

The code is as follows Copy Code

chmod 600/etc/rsyncd.passwd

The client completes server-side to local synchronization by executing the following command:

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

This command htdocs the name of the server-side configuration. The following path is the path saved to. Behind the password file, the password file can only have a password (client if the use of user:passwd in the form of the error will occur).

Attached, if you just backed up the backup we can use the shell command directly for backup

Set in Cron, perform every Monday 2 o'clock in the morning (full backup every Monday, incremental backup for the rest of 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 "full$today.tar.gz"]; Then
RM-RF Snapshot
Tar-g snapshot-zcf "full$today.tar.gz" $source--exclude $sourceserver. Log
Fi
Else
if [!-F "inc$today.tar.gz"]; Then
Tar-g snapshot-zcf "inc$today.tar.gz" $source--exclude $sourceserver. Log
Fi
Fi

It's going to have to back up the good data in your designated directory

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.