0
2

More than 1 year has passed since last update.

inotify-tools + rsyncでディレクトリを同期する

Last updated at Posted at 2023-07-31

inotify-toolsをインストールする

[root@ip-10-0-0-4 ~]# yum list inotify-tools
Last metadata expiration check: 0:01:19 ago on Mon Jul 31 11:41:41 2023.
Available Packages
inotify-tools.x86_64                    3.22.1.0-4.amzn2023                    amazonlinux
[root@ip-10-0-0-4 ~]# yum install inotify-tools
・・・

Installed:
  inotify-tools-3.22.1.0-4.amzn2023.x86_64                                                

Complete!
[root@ip-10-0-0-4 ~]# 
[root@ip-10-0-0-4 ~]# mkdir src1
[root@ip-10-0-0-4 ~]# mkdir src2
[root@ip-10-0-0-4 ~]# ls -al
・・・
drwxr-xr-x.  2 root root   6 Jul 31 11:43 src1
drwxr-xr-x.  2 root root   6 Jul 31 11:43 src2
[root@ip-10-0-0-4 ~]# 

src1にアップされたファイルをsrc2にコピーする

[root@ip-10-0-0-4 ~]# inotifywait -m /root/src1 | xargs -I{} rsync -r /root/src1/ /root/src2/
Setting up watches.
Watches established.
・・・

試す

[root@ip-10-0-0-4 ~]# touch /root/src1/test01.txt
[root@ip-10-0-0-4 ~]# ls -al src1
total 0
drwxr-xr-x. 2 root root  24 Jul 31 11:46 .
dr-xr-x---. 5 root root 127 Jul 31 11:43 ..
-rw-r--r--. 1 root root   0 Jul 31 11:46 test01.txt

とすると、

[root@ip-10-0-0-4 ~]# ls -al src2
total 0
drwxr-xr-x. 2 root root  24 Jul 31 11:46 .
dr-xr-x---. 5 root root 127 Jul 31 11:43 ..
-rw-r--r--. 1 root root   0 Jul 31 11:46 test01.txt

参考URL

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2