inotify.sh脚本范例
[[email protected] ~]# cat /server/scripts/inotify.sh
#!/bin/bash
#para
host01=192.168.1.111
src=/dingjian
dst=dingjian
user=rsync_backup
rsync_passfile=/etc/rsync.password
inotify_home=/usr/local/inotify-tools-3.14/
#judge
if [ ! -e "$src" ] \
|| [ ! -e "${rsync_passfile}" ] \
|| [ ! -e "${inotify_home}/bin/inotifywait" ] \
|| [ ! -e "/usr/bin/rsync" ];
then
echo "Check File and Folder"
exit 9
fi
${inotify_home}/bin/inotifywait -mrq --timefmt ‘%d/%m/%y %H:%M‘ --format ‘%T %w%f‘ -e close_write,delete,create,attrib $src \
| while read file
do
# rsync -avzP --delete --timeout=100 --password-file=${rsync_passfile} $src [email protected]$host01::$dst >/dev/null 2>&1
cd $src && rsync -aruz -R --delete ./ --timeout=100 [email protected]$host01::$dst --password-file=${rsync_passfile} >/dev/null 2>&1
done
exit 0