当前位置:网站首页>Besides, rsync+inotify realizes real-time backup of data
Besides, rsync+inotify realizes real-time backup of data
2022-07-04 13:02:00 【Brother Xing plays with the clouds】
rsync The advantages and disadvantages of
With the traditional cp、tar Compared with backup mode ,rsync It has high security 、 Fast backup 、 Support incremental backup and other advantages , adopt rsync It can solve the data backup requirements that do not require high real-time performance , For example, regularly backup files The server Data to remote end The server , Do data mirroring on local disk regularly .
With the continuous expansion of application system scale , Better requirements for data security and reliability ,rsync In the high-end business system has gradually exposed a lot of shortcomings , First ,rsync When synchronizing data , All documents need to be scanned and compared , Carry out differential transmission . If the number of files reaches millions or even tens of millions , Scanning all files will be very time consuming . And what's changing is often a small part of it , It's a very inefficient way . secondly ,rsync Can't monitor in real time 、 Synchronous data , Although it can pass through linux The way the daemons trigger synchronization , But there must be a time difference between the two triggers , This leads to inconsistency between the data of the server and the client , Unable to fully recover data in case of application failure . For the above reasons ,rsync+inotify The combination appears !
inotify Introduce
Inotify It's a powerful 、 Fine grained 、 Asynchronous file system event monitoring mechanism ,linux Kernel from 2.6.13 rise , Joined the Inotify Support , adopt Inotify Can monitor the file system to add 、 Delete , modify 、 All sorts of subtle events like movement , Using this kernel interface , Third party software can monitor the changes of files in the file system , and inotify-tools It's such a third-party software .
We talked about it earlier ,rsync Can achieve triggered file synchronization , But by crontab Trigger in the way of daemons , There will be differences between the synchronized data and the actual data , and inotify You can monitor changes in the file system , When there is any change in the file , It triggers rsync Sync , This just solves the real-time problem of synchronous data .
install inotify and inotify-tools Tools
because inotify Feature needs Linux Kernel support , In the installation inotify-tools Make sure that Linux Whether the system kernel has reached 2.6.13 above , If Linux The kernel is lower than 2.6.13 edition , You need to recompile the kernel and add inotify Support for , You can also judge , Does the kernel support inotify.
Check whether the system supports inotify
#Linux shell
uname -a
Linux localhost 3.2.0-4-amd64 #1 SMP Debian 3.2.57-3 x86_64 GNU/Linux # The kernel is larger than 2.6.13 Is to support the
ll /proc/sys/fs/inotify
Total usage 0
-rw-r--r-- 1 root root 0 5 month 19 20:02 max_queued_events
-rw-r--r-- 1 root root 0 5 month 19 20:02 max_user_instances
-rw-r--r-- 1 root root 0 5 month 19 20:02 max_user_watches
If you have the above three outputs , Indicates that the system has supported by default inotify, Then you can start installing inotify-tools 了 .
install inotify-tools
Debian System
apt-get install inotify-tools
CentOS System
yum install inotify-tools
Source mode
succeed in inviting sb. https://github.com/rvoicilas/inotify-tools/ Download source code, compile and install .
ll /usr/bin/inotifywa*
inotify-tools After installation , Will generate inotifywait and inotifywatch Two instructions , among ,inotifywait Used to wait for a specific event on a file or set of files , It can monitor any file and directory settings , And you can monitor the entire tree recursively .
inotifywatch Used to collect monitored file system statistics , Including each inotify How many times has the event happened .
inotify Parameter Introduction
inotify The following interface parameters are defined , Can be used to limit inotify Consume kernel memory Size . Because these parameters are memory parameters , therefore , According to the application requirements , Adjust its size in real time .
cat /proc/sys/fs/inotify/max_queued_evnets
Represents a call to inotify_init Time division rationing inotify instance In the queue event The maximum number of , Events that exceed this value are discarded , But it will trigger IN_Q_OVERFLOW event .
cat /proc/sys/fs/inotify/max_user_instances
For each one real user ID Can be created inotify instatnces The maximum number of .
cat /proc/sys/fs/inotify/max_user_watches
Represent each inotify instatnces The maximum number of directories that can be monitored . If the number of files monitored is huge , According to the situation , Increase the value appropriately , for example :
echo 30000000 > /proc/sys/fs/inotify/max_user_watches
inotifywait Related parameters
Inotifywait It's a monitoring wait event , Can cooperate with shell Scripts use it , Here are some common parameters :
•-m, namely –monitor, Indicates that the event listening state is always maintained .
•-r, namely –recursive, Represents a recursive query directory .
•-q, namely –quiet, Indicates that the monitoring event is printed out .
•-e, namely –event, This parameter allows you to specify the event to be monitored , Common events are modify、delete、create、attrib etc. .
Please refer to the manual for more detailed parameters .
man inotifywait # Check out the manual
边栏推荐
- [data clustering] section 3 of Chapter 4: DBSCAN performance analysis, advantages and disadvantages, and parameter selection methods
- Golang sets the small details of goproxy proxy proxy, which is applicable to go module download timeout and Alibaba cloud image go module download timeout
- 使用 NSProxy 实现消息转发
- 16. Memory usage and segmentation
- 面向个性化需求的在线云数据库混合调优系统 | SIGMOD 2022入选论文解读
- ArcGIS uses grid processing tools for image clipping
- eclipse链接数据库中测试SQL语句删除出现SQL语句语法错误
- 强化学习-学习笔记1 | 基础概念
- 爬虫练习题(一)
- Show recent errors only command /bin/sh failed with exit code 1
猜你喜欢
高效!用虚拟用户搭建FTP工作环境
VIM, another program may be editing the same file If this is the solution of the case
Concepts and theories related to distributed transactions
面试官:Redis 过期删除策略和内存淘汰策略有什么区别?
golang 设置goproxy代理的小细节,适用于go module下载超时,阿里云镜像go module下载超时
实战:fabric 用户证书吊销操作流程
ArcGIS uses grid processing tools for image clipping
Master the use of auto analyze in data warehouse
Paper notes ACL 2020 improving event detection via open domain trigger knowledge
Transformer principle and code elaboration (pytorch)
随机推荐
PostgreSQL 9.1 飞升之路
CANN算子:利用迭代器高效实现Tensor数据切割分块处理
mm_ Cognition of struct structure
Is the main thread the same as the UI thread- Is main thread the same as UI thread?
用fail2ban阻止密码尝试攻
C语言函数
使用 NSProxy 实现消息转发
AbstractDispatcherServletInitializer 的实现类为什么可以在初始化Web容器的时候被调用
Comprehensive evaluation of modular note taking software: craft, notation, flowus
C语言数组
Show recent errors only command /bin/sh failed with exit code 1
[Android kotlin] lambda return statement and anonymous function
Error: Failed to download metadata for repo ‘AppStream‘: Cannot download repomd. XML solution
Sort merge sort
Practice of retro SOAP Protocol
七、软件包管理
IIS error, unable to start debugging on the webserver
一文掌握数仓中auto analyze的使用
Full arrangement (medium difficulty)
6 分钟看完 BGP 协议。