Inotify + rsync implements real-time file backup 1. inotify inotify is a powerful fine-grained and asynchronous file system event monitoring mechanism. The Linux kernel has been added to Inotify since 2.6.13, inotify can be used to monitor various events in the file system, such as adding, deleting, modifying, and moving. However, inotify only provides the C language interface, which is inconvenient to call. Therefore, inotify-tools must be installed first. installation Method: yum install inotify-tools; apt-get install inotify-tools II. the Rsync www.2cto.com backup tool works the same as tar, cpio, and other tools, but can be backed up to other machines without compression before transmission. Configure rsync on the target server to create/etc/rsyncd. confShell code uid = user gid = usergroup use chroot = no timeout = 600 pid file =/var/run/rsyncd. pid lock file =/var/run/rsyncd. lock log file =/var/log/rsyncd. log [web1] path =/photo/system/ignore errors read only = no list = no auth users = user secrets file =/etc/user. pwd user. pwd records the user name and password of the user, in the format of user: password www.2cto.com source server shell file
Shell code #! /Bin/bash SRC =/web/system/DST = user@192.168.0.162: web1/usr/bin/inotifywait-mrq-e close_write, create, attrib $ {SRC} | while read d e f do/usr/bin/rsync-vzrtopg -- progress $ SRC $ DST -- password-file =/etc/picback. pwd done picback. pwd records the password of the user on the target server