Perform the following operations in the server. In your environment, some dependent packages may be missing. Install them by using: dnf -y install autoconf automake libtool
[root@Rocky~]# wget -c https://github.com/inotify-tools/inotify-tools/archive/refs/tags/3.21.9.6.tar.gz[root@Rocky~]# tar -zvxf 3.21.9.6.tar.gz -C /usr/local/src/[root@Rocky~]# cd /usr/local/src/inotify-tools-3.21.9.6/[root@Rocky/usr/local/src/inotify-tools-3.21.9.6]# ./autogen.sh && \
./configure--prefix=/usr/local/inotify-tools&&\
make&&\
makeinstall
...
[root@Rocky~]# ls /usr/local/inotify-tools/bin/
inotifywaitinotifywatch
Append the environment variable PATH, write it to the configuration file and let it take effect permanently.
[root@Rocky~]# vim /etc/profile
...
PATH=$PATH:/usr/local/inotify-tools/bin/
[root@Rocky~]# . /etc/profile
Why not use the inotify-tools RPM package of the EPEL repository? And the way to use source code to compile and install?
The author personally believes that remote data transmission is a matter of efficiency, especially in a production environment, where there are a large number of files to be synchronized and a single file is particularly large. In addition, the new version will have some bug fixes and function expansions, and perhaps the transmission efficiency of the new version will be higher, so I recommend installing inotify-tools by source code. Of course, this is the author's personal suggestion, not every user must follow.
The inotify-tools tool has two commands, namely:
* inotifywait: for continuous monitoring, real-time output results. It is generally used with the rsync incremental backup tool. Because it is a file system monitoring, it can be used with a script. We will introduce the specific script writing later.
* inotifywatch: for short-term monitoring, output results after the task is completed.
inotifywait mainly has the following options:
-m means continuous monitoring
-r Recursive monitoring
-q Simplify output information
-e specifies the event type of monitoring data, multiple event types are separated by commas in English status
The event types are as follows:
Event Type
Description
access
Access to the contents of a file or directory
modify
The contents of the file or directory are written
attrib
The attributes of the file or directory are modified
close_write
File or directory is opened in writable mode and then closed
close_nowrite
File or directory is closed after being opened in read-only mode
close
Regardless of the read/write mode, the file or directory is closed
open
File or directory is opened
moved_to
A file or directory is moved to the monitored directory
moved_from
A file or directory is moved from the monitored directory
move
There are files or directories that are moved to or removed from the monitoring directory
move_self
The monitored file or directory has been moved
create
There are files or directories created in the monitored directory
delete
A file or directory in the monitored directory is deleted
delete_self
The file or directory has been deleted
unmount
File system containing unmounted files or directories
We are operating in Rocky Linux 8 server, using SSH protocol for demonstration.
For the password-free authentication login of the SSH protocol, please refer to rsync password-free authentication login, which is not described here. An example of the content of a bash script is as follows. You can add different options after the command according to your needs to meet your needs. For example, you can also add --delete after the rsync command.
When using the SSH protocol for data synchronization transmission, if the SSH service port of the target machine is not 22, you can use a method similar to this——
b="/usr/bin/rsync -avz -e 'ssh -p [port-number]' /rsync/* testfedora@192.168.100.5:/home/testfedora/"
tip
If you want to start this script at boot
[root@Rocky ~]# echo "bash /root/rsync_inotify.sh &" >> /etc/rc.local[root@Rocky ~]# chmod +x /etc/rc.local