当前位置:网站首页>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
边栏推荐
- WPF double slider control and forced capture of mouse event focus
- 一个数据人对领域模型理解与深入
- Transformer principle and code elaboration (pytorch)
- R language -- readr package reads and writes data
- WPF双滑块控件以及强制捕获鼠标事件焦点
- Transformer principle and code elaboration (tensorflow)
- mm_ Cognition of struct structure
- Definition of cognition
- Show recent errors only command /bin/sh failed with exit code 1
- DGraph: 大规模动态图数据集
猜你喜欢
高效!用虚拟用户搭建FTP工作环境
A taste of node JS (V), detailed explanation of express module
Will the concept of "being integrated" become a new inflection point of the information and innovation industry?
ArcGis利用栅格处理工具进行影像裁剪
DVWA range exercise 4
Transformer principle and code elaboration (pytorch)
CANN算子:利用迭代器高效实现Tensor数据切割分块处理
比量子化学方法快六个数量级,一种基于绝热状态的绝热人工神经网络方法,可加速对偶氮苯衍生物及此类分子的模拟
How real-time cloud interaction helps the development of education industry
runc hang 导致 Kubernetes 节点 NotReady
随机推荐
go-zero微服务实战系列(九、极致优化秒杀性能)
使用宝塔部署halo博客
Play Sanzi chess easily
ArcGis利用栅格处理工具进行影像裁剪
R language -- readr package reads and writes data
Implementation mode and technical principle of MT4 cross platform merchandising system (API merchandising, EA merchandising, nj4x Merchandising)
【云原生 | Kubernetes篇】深入了解Ingress(十二)
求解:在oracle中如何用一条语句用delete删除两个表中jack的信息
阿里云有奖体验:用PolarDB-X搭建一个高可用系统
Sort merge sort
Meituan Ali's Application Practice on multimodal recall
CVPR 2022 | TransFusion:用Transformer进行3D目标检测的激光雷达-相机融合
Fastlane one click package / release app - usage record and stepping on pit
Introduction to the button control elevatedbutton of the fleet tutorial (the tutorial includes the source code)
Deploy halo blog with pagoda
C語言:求100-999是7的倍數的回文數
ISO 27001 Information Security Management System Certification
【AI系统前沿动态第40期】Hinton:我的深度学习生涯与研究心法;Google辟谣放弃TensorFlow;封神框架正式开源
[Yu Yue education] 233 pre school children's language education reference questions in the spring of 2019 of the National Open University
Langue C: trouver le nombre de palindromes dont 100 - 999 est un multiple de 7