Inotify+rsync实现实时数据同步
使用rsync可以实现数据同步,但是即使使用crontab定时任务最小执行间隔为1分钟,在数据实时性要求比较高场合需使用inotify+rsync实现实时同步
下载inotify
wget https://github.s3.amazonaws.com/downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar.gz
安装
tar -xf inotify-tools-3.14.tar.gz
yum -y install gcc-c++
./configure --prefix=/usr/local/inotify-tools-3.14
make && make install
ln -s /usr/local/inotify-tools-3.14/ /usr/local/inotify
显示帮助
/usr/local/inotify/bin/inotifywait --help
inotifywait 3.14
Wait for a particular event on a file or set of files.
Usage: inotifywait [ options ] file1 [ file2 ] [ file3 ] [ ... ]
Options:
-h|--help Show this help text.
@<file> Exclude the specified file from being watched.
--exclude <pattern>
Exclude all events on files matching the
extended regular expression <pattern>.
--excludei <pattern>
Like --exclude but case insensitive.
-m|--monitor Keep listening for events forever. Without
this option, inotifywait will exit after one
event is received.
-d|--daemon Same as --monitor, except run in the background
logging events to a file specified by --outfile.
Implies --syslog.
-r|--recursive Watch directories recursively.
--fromfile <file>
Read files to watch from <file> or `-' for stdin.
-o|--outfile <file>
Print events to <file> rather than stdout.
-s|--syslog Send errors to syslog rather than stderr.
-q|--quiet Print less (only print events).
-qq Print nothing (not even events).
--format <fmt> Print using a specified printf-like format
string; read the man page for more details.
--timefmt <fmt> strftime-compatible format string for use with
%T in --format string.
-c|--csv Print events in CSV format.
-t|--timeout <seconds>
When listening for a single event, time out after
waiting for an event for <seconds> seconds.
If <seconds> is 0, inotifywait will never time out.
-e|--event <event1> [ -e|--event <event2> ... ]
Listen for specific event(s). If omitted, all events are
listened for. Exit status:
0 - An event you asked to watch for was received.
1 - An event you did not ask to watch for was received
(usually delete_self or unmount), or some error occurred.
2 - The --timeout option was given and no events occurred
in the specified interval of time. Events:
access file or directory contents were read
modify file or directory contents were written
attrib file or directory attributes changed
close_write file or directory closed, after being opened in
writeable mode
close_nowrite file or directory closed, after being opened in
read-only mode
close file or directory closed, regardless of read/write mode
open file or directory opened
moved_to file or directory moved to watched directory
moved_from file or directory moved from watched directory
move file or directory moved to or from watched directory
create file or directory created within watched directory
delete file or directory deleted within watched directory
delete_self file or directory was deleted
unmount file system containing file or directory unmounted
监控一个文件夹,开启另外一个窗口创建修改删除文件
/usr/local/inotify/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f ' -e create,delete,close_write,modify /data/
创建删除打开修改或者重定向都会有输出
touch test
vim test
显示如下
写一个脚本配合rsync实现数据同步
#!/bin/bash
inotify=/usr/local/inotify/bin/inotifywait
$inotify -mrq --format '%w%f' -e create,close_write,delete,motify /data \
|while read file
do
cd / &&
rsync -az ./data --delete rsync_backup@192.168.1.4::backup/ \
--password-file=/etc/rsync.password
done
rsync安装配置参考文档 https://www.cnblogs.com/minseo/p/8080426.html
把该脚本设置在后台及开机启动运行即可实现实时的数据同步
Inotify+rsync实现实时数据同步的更多相关文章
- Linux学习系列之Inotify+Rsync实现实时数据同步
Inotify简介 inotify介绍 inotify是一种强大的.异步的文件系统监控机制,linux内核从2.6.13起,加入了inotify的支持,通过inotify可以监控文件系统中添加.删除. ...
- centos7部署inotify与rsync实现实时数据同步
实验环境:CentOS Linux release 7.6.1810 node1:192.168.216.130 客户端(向服务端发起数据同步) node2:192.168.216.132 服务端(接 ...
- Linux系统实时数据同步inotify+rsync
一.inotify简介 inotify是Linux内核的一个功能,它能监控文件系统的变化,比如删除.读.写和卸载等操作.它监控到这些事件的发生后会默认往标准输出打印事件信息.要使用inotify,Li ...
- inotify+rsync实现实时同步
第1章 数据实时同步介绍 1.1 什么是实时同步:如何实现实时同步 A. 要利用监控服务(inotify),监控同步数据服务器目录中信息的变化 B. 发现目录中数据产生变化,就利用rsync服务推送到 ...
- 【转】inotify+rsync实现实时同步
[转]inotify+rsync实现实时同步 1.1 什么是实时同步:如何实现实时同步 要利用监控服务(inotify),监控同步数据服务器目录中信息的变化 发现目录中数据产生变化,就利用rsync服 ...
- rsync+inotify实时数据同步多目录实战
rsync+inotify实时数据同步多目录实战 inotify配置是建立在rsync服务基础上的配置过程 操作系统 主机名 网卡eth0 默认网关 用途 root@58server1 1 ...
- rsync+inotify实时数据同步单目录实战
rsync+inotify实时数据同步单目录实战 rsync+inotify实时数据同步单目录实战 inotify是一个强大的.细粒度的.异步的文件系统事件监控机制,linux内核从2.6.13起 ...
- 【linux运维】rsync+inotify与sersync+rsync实时数据同步笔记
Rsync(remote sync)远程同步工具,通过rsync可以实现对远程服务器数据的增量备份通过,但rsync自身也有缺陷,同步数据时,rsync采用核心算法对远程服务器的目标文件进行对比,只进 ...
- inotify+rsync实现实时同步(附解决crontab中无法执行python脚本的问题)
1.准备环境 # 系统支持的话,下面的目录就会存在 ls /proc/sys/fs/inotify/ rpm -qa inotify-tools yum -y install inotify-tool ...
随机推荐
- 阿里巴巴MySQL DBA面试题答案[转]
无意中看到阿里巴巴的面试题,,借此回首DBMS时刻趁热打铁巩固一下基础 拿到题目大概浏览了一遍难度大概在中上游水平,自己跪了接近35%的题目 自己答题如下,欢迎大家讨论分析题 1 2 3 4 5 6 ...
- 安装nginx和添加ssl证书
一. 准备: 1. 需要有一台centos的服务器 2. 域名解析到服务器 3. 域名的nginx证书 二. 安装Nginx(输入下面的指令后:可访问实验机器外网 HTTP 服务http://118. ...
- JavaScript中的namespace
<head> <title> New Document </title> <script> var global = window.global||{} ...
- 那天有个小孩教我WCF[一][2/3]
接着上次的继续讲吧 我们开始吧 9.创建数据库 use master go --创建库 if exists(select * from sysdatabases where name='NewsDB' ...
- 【转】Java异常总结和Spring事务处理异常机制浅析
异常的概念和Java异常体系结构 异常是程序运行过程中出现的错误.本文主要讲授的是Java语言的异常处理.Java语言的异常处理框架,是Java语言健壮性的一个重要体现. Thorwable类所有异常 ...
- 6.翻译系列:EF 6 Code-First中数据库初始化策略(EF 6 Code-First系列)
原文链接:http://www.entityframeworktutorial.net/code-first/database-initialization-strategy-in-code-firs ...
- 【R作图】蜜蜂群图beeswarm和jitter的使用
最近经常要画好看的盒形图,还要在上面加入散点,所以总结了两个方法. 第一种方法是,利用beeswarm函数: library(beeswarm) beeswarm 蜜蜂群图 http://rgm3.l ...
- android 加载远程Jar、APK
参考链接: .http://blog.csdn.net/bboyfeiyu/article/details/117104972\ http://www.cnblogs.com/LittleRedPoi ...
- Tomcat配置多个域名绑定到不同项目
<Host name="www.dn-serve.com" appBase="webapps" unpackWARs="true" a ...
- GPT(保护分区)解决办法
教你在硬盘被GPT保护分区后怎么格式化 GUID 分区表 (GPT) 作为可扩展固件接口 (EFI) 计划的一部分而引入.与 PC 以前通用的旧的主引导记录 (MBR) 分区方案相比,GPT 为磁盘 ...