实时同步 && 全网备份

一. 实时同步:
1. 实时同步服务概述:
原因:实时同步是一种只要当前目录发生变化则会触发一个事件,事件触发后会将变化的目录同步至远程服务器。
意义:保证数据的连续性 ,减少人力维护成本
如何实现数据实时同步:
	1)发现数据产生变化:inotify(监控软件)
	   inotifywait   参数   事件   监控目录
	2)进行数据传输备份:rsync
2 实时同步实现方式(命令方式):
    存储服务器部署
    第一个历程:按照监控数据变化软件
	条件:确认epel源可以正常使用
	yum install -y inotify-tools
	
	第二个历程:监控命令使用
	/usr/bin/inotifywait    --- 监控数据变化命令
    /usr/bin/inotifywatch   --- 统计数据变化次数  添加 删除 修改
	
	语法结构:inotifywait  --help
	inotifywait  参数  事件  监控目录
	· 永久监控目录中数据变化:  inotifywait -m  目录
      -m|--monitor  	Keep listening for events forever. 
                        保持永久监控
      -d|--daemon   	Same as --monitor
	                    类似-m参数
						
    · 实现目录中数据递归监控:  inotifywait -rm  目录
	  -r|--recursive	Watch directories recursively.
	                    监控目录中子目录数据变化
						
	
    · 实时目录中数据排除监控功能:	
	  --exclude <pattern>   Exclude all events on files matching the extended regular expression <pattern>
	                        排除指定数据信息不要进行监控 (区分大小写识别信息)
      --excludei <pattern>  Like --exclude but case insensitive.
	                        排除指定数据信息不要进行监控 (忽略大小写识别信息)  
					
    · 将无用的信息进制输出
      -q|--quiet    	    Print less (only print events).	
	                        输出少量信息(只输出事件信息)
	
	· 知识输出信息格式
	  --format <fmt>	Print using a specified printf-like format string; read the man page for more details.
	                    指定输出信息格式
						%e  显示触发事件信息 
						%w  显示监控目录信息
						%f  触发事件数据信息
	  --timefmt <fmt>	strftime-compatible format string for use with %T in --format string.
                        定义显示的时间格式信息(时间格式的定义和 date命令类似)
	  -c|--csv      	Print events in CSV format.   (MySQL)
	  -e|--event <event1> [ -e|--event <event2> ... ]         Listen for specific event(s)
	                                                          指定监视事件信息
															  
	  														  
	  事件信息:inotify软件采用触发机制进行监控
      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
	                文件系统中包含文件或目录被卸载

3. 实时同步实现方式(脚本实现):
    编写脚本思路:
	1)发现变化数据信息    inotifywait
       inotifywait -mrq --format "%w%f" /data -e "close_write,move,create,delete"
       数据信息  

	2)将变化数据进行传输  rsync
	   rsync -az  数据信息  rsync_backup@172.16.1.41::backup  --password-file=/etc/rsync.password 
	
    3) 监控操作和同步操作建立联系
       shell脚本循环语句:
	   · for    循环语句     --- 有限循环
	   · while  循环语句     --- 无限循环
	     条件为真就会一直循环
	   · until  循环语句     --- 无限循环 
	     条件为假就会一直循环
	   
	   脚本解释过程:
	   inotifywait -mrq --format "%w%f" /data -e "close_write,move,create,delete"|while read data_info
	       信息   
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值