How to implement synchronous backups with Rsync+sersync

Source: Internet
Author: User
Tags inotify

3, Rsync+sersync faster and more resource-saving to achieve Web data synchronization
4, Unison+inotify realize bidirectional synchronization of Web data

One: Why synchronous backups are implemented

When there are some important files or data on the server, they can be backed up to another server so that the data or files are not lost.

Second: The construction of the environment

Server a:192.168.1.10 Source Server

Server b:192.168.1.20 Destination Server

All we have to do is to synchronize the files on the a server to the B server for backup. We mainly install the configuration rsync on the B server, install the configuration Sersync on the a server, push the file to the B server via Sersync

Three: Start building

Start with the B server:

1. Close SELinux, in/etc/sysconfig/selinux this file, set selinux=disable

2. Firewall open 873 Port-a input-m state--state new-m tcp-p TCP--dport 873-j ACCEPT
3. Start installing Rsync

Yum Install Rsync-y

4. Configure the Rsync,rsync configuration file to be/etc/rsyncd.conf, configured as follows:

Note below the figure: Secrets file This is the configuration of the synchronized password files. [Rsynctest] This is the name of the configuration synchronization module, path is the directory to configure synchronization, hosts allow is the host that allows synchronization, hosts deny: Host denied synchronization

5. Create a file that synchronizes the user with the password, that is, the file in the Config option in the secrets file. /ETC/RSYNC.PASSWD, enter the permission to set this file to 600

echo "User:password" >>/etc/rsync.passwd

chmod 600/etc/rsync.passwd

6. Create a synchronized directory: The directory in the path configuration option.

Mkdir/home/rsynctest

7. Start Rsync

Rsync--daemon--config=/etc/rsyncd.conf

Then restart the xinetd.

/etc/init.d/xinetd restart

8. Configure boot-up start echo "rsync--daemon--config=/etc/rsyncd.conf" >>/etc/rc.d/rc.local

To such a basic configuration of B server is completed.

Then configure a server:

1. Go to sersync website to download sersync:http://sersync.sourceforge.net/

wget http://sersync.googlecode.com/files/sersync2.1_64bit_binary.tar.gz

2. Installing Sersync

# Mkdir/usr/local/sersync

# mkdir/usr/local/sersync/conf

# Mkdir/usr/local/sersync/bin

# Mkdir/usr/local/sersync/log

# tar ZXVF sersync2.5_32bit_binary_stable_final.tar.gz

# CD gnu-linux-x86/

# CP Confxml.xml/usr/local/sersync/conf

# CP Sersync2/usr/local/sersync/bin

3. Create password file, same as B server, but this file just save a password on the line, without user name, permissions are 600

echo "Password" >>/etc/rsync.passwd

chmod 600/etc/rsync.passwd

4. Configure the Sersync, the configuration file is the second step in the copy of Confxml.xml this article, the path in/usr/local/sersync/conf

--------------------------------------------------------------------------------------------------------------- ------------

<?xml version= "1.0" encoding= "Iso-8859-1"?>

# set local IP and port

# Turn on Dubug mode

<debug start= "false"/>

# Open XFS File system

<filesystem xfs= "false"/>

# Ignore push files (regular expressions) when synchronizing, close by default

<filter start= "false" >

<exclude expression= "(. *) \.SVN" ></exclude>

<exclude expression= "(. *) \.gz" ></exclude>

<exclude expression= "^info/*" ></exclude>

<exclude expression= "^static/*" ></exclude>

</filter>

<inotify>

# set up the events to monitor

<delete start= "true"/>

<createfolder start= "true"/>

<createfile start= "true"/>

<closewrite start= "true"/>

<movefrom start= "true"/>

<moveto start= "true"/>

<attrib start= "true"/>

<modify start= "true"/>

</inotify>

<sersync>

# Local Synchronized directory path

<localpath watch= "/data" >

# Remote IP and rsync module name

<remote ip= "192.168.1.20" name= "Data"/>

<!--<remote ip= "192.168.8.39" name= "Tongbu"/>-->

<!--<remote ip= "192.168.8.40" name= "Tongbu"/>-->

</localpath>

<rsync>

# rsync Command Parameters

<commonparams params= "-auvzp"/>

# rsync Sync Authentication

<auth start= "true" users= "user" passwordfile= "/etc/rsync.passwd"/>

# Set the Rsync remote service port, the remote non-default port will need to open the custom

<userdefinedport start= "false" port= "874"/><!--port=874--

# Set Timeout time

<timeout start= "true" Time= "/><!--timeout=100--

# set RSYNC+SSH encryption transfer mode, default off, turn on the need to set up SSH encryption certificate

<ssh start= "false"/>

</rsync>

# Sersync Transmission failed Log script path, every 60 will re-execute the script, the execution will be automatically emptied.

<faillog path= "/usr/local/sersync/log/rsync_fail_log.sh" timetoexecute= "/><!--default every 60mins Execute once-->

# set Rsync+crontab timed transfer, default off

<crontab start= "false" schedule= "><!--600mins-->

<crontabfilter start= "false" >

<exclude expression= "*.php" ></exclude>

<exclude expression= "info/*" ></exclude>

</crontabfilter>

</crontab>

# set Sersync transfer after calling name specified plug-in script, default off

<plugin start= "false" name= "command"/>

</sersync>

# Plugin Script Example

<plugin name= "command" >

<param prefix= "/bin/sh" suffix= "" ignoreerror= "true"/> <!--prefix/opt/tongbu/mmm.sh suffix-->

<filter start= "false" >

<include expression= "(. *) \.php"/>

<include expression= "(. *) \.sh"/>

</filter>

</plugin>

# Plugin Script Example

<plugin name= "Socket" >

<localpath watch= "/opt/tongbu" >

<deshost ip= "192.168.138.20" port= "8009"/>

</localpath>

</plugin>

<plugin name= "Refreshcdn" >

<localpath watch= "/data0/htdocs/cms.xoyo.com/site/" >

<cdninfo domainname= "ccms.chinacache.com" port= "" "Username=" xxxx "passwd=" xxxx "/>

<sendurl base= "Http://pic.xoyo.com/cms"/>

<regexurl regex= "false" Match= "Cms.xoyo.com/site ([/a-za-z0-9]*). Xoyo.com/images"/>

</localpath>

</plugin>

--------------------------------------------------------------------------------------------------------------- ---

5. Create a sync directory: mkdir/home/rsynctest

6. Set Environment variables:

# echo "Export path= $PATH:/usr/local/sersync/bin/" >>/etc/profile

# Source/etc/profile

7. Start Sersync

Sersync2-r-d-o/usr/local/sersync/conf/confxml.xml

Note: The restart operation is as follows:

# killall Sersync2 && sersync2-r-d-o/usr/local/sersync/conf/confxml.xml

8. Set Boot up

# echo "Sersync2-r-d-o/usr/local/sersync/conf/confxml.xml" >>/etc/rc.local

OK, the configuration of both machines has been completed, now you in a server/home/rsynctest this directory to create files, to see if B server also generated this file, if so, congratulations, you succeeded!

How to implement synchronous backups with Rsync+sersync

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.