Rsync+inotify for real-time file synchronization

Source: Internet
Author: User
Tags inotify rsync

Rsync + inotify (relatively real-time)


System environment
Cat/etc/issue
CentOS Release 6.6 (Final)

Uname-sr
Linux 2.6.32-504.el6.x86_64

Server Planning
Rsync Server: 192.168.10.241
rsync + inotify-tools Server: 192.168.10.231


Configuring the Rsync server configuration can refer to the relevant configuration of rsync in the blog RSYNC+LSYNCD

1. Configure rsync client and Inotify-tools to implement file real-time synchronization

Edit the Rsync client, provide the add password file, and modify the permissions to 600
echo "123456" >/etc/backserver.pas
chmod 600/etc/backserver.pas
Ll/etc/backserver.pas
-RW-------1 root root 7 Jul 15:34/etc/backserver.pas
Yum Install Inotify-tools-y

Writing synchronization Scripts

1. Local synchronization
Vim lsyncd_local.sh
--------------------------------------------------------------------------------------------------------------- ---------------
#!/bin/bash

Lsync_local () {
Log_path=/home/web
srcpath=/opt/
/usr/bin/inotifywait-mrq--timefmt '%F%T '--format '%e%w%f%T '-e create,delete,modify,move,attrib $SrcPath |whi Le read line
Do
RSYNC-VZRTOPG--progress--delete $SrcPath/tmp/back/
Echo-n "$line" >> ${log_path}/inotify_local_$ (date "+%f"). LOG
Done
}
Lsync_local

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

2. Remote synchronization
# Vim Lsync_remote.sh
--------------------------------------------------------------------------------------------------------------- ---------------
#!/bin/bash

Lsync_remote () {
Log_path=/home/web
srcpath=/opt/
/usr/bin/inotifywait-mrq--timefmt '%F%T '--format '%e%w%f%T '-e create,delete,modify,move,attrib $SrcPath |whi Le read line
Do
RSYNC-VZRTOPG--progress--delete $SrcPath [email protected]::home--password-file=/etc/backserver.pas
Echo-n "$line" >> ${log_path}/inotify_remote_$ (date "+%f"). LOG
Done
}
Lsync_remote

--------------------------------------------------------------------------------------------------------------- ---------------
2. Record the synchronization time log
Tailf Inotify_local_2015-07-28.log
modify/opt/test.sh 2015-07-28 16:14:33
Create/opt/test.bak 2015-07-28 16:15:33
Modify/opt/test.bak 2015-07-28 16:15:33
Modify/opt/test.bak 2015-07-28 16:17:34
modify/opt/test.sh 2015-07-28 16:18:04
Delete/opt/test.bak 2015-07-28 16:18:09
modify/opt/test.sh 2015-07-28 16:24:35
modify/opt/test.sh 2015-07-28 16:25:29


This article is from the Linux tours blog, so be sure to keep this source http://openlinuxfly.blog.51cto.com/7120723/1679287

Rsync+inotify for real-time file synchronization

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.