功能:
监控指定服务器的某个目录,自动同步至其它服务器
- #!/bin/bash
- # author: honway.liu
- # date: 2012-07-04
- R1=61.147.88.114
- R2=61.147.88.115
- R3=222.186.32.15
- DESTHOSTDIR=/data/mp3
- SRCDIR=/data/music/mp3/song11
- LOG=/var/tmp/mp3sync.log
- inotifywait -mr --timefmt '%d/%m/%y %H:%M' --format '%T %w %f' -e close_write,modify,delete,create,attrib $SRCDIR | while read DATE TIME DIR FILE; do
- FILECHANGE=${DIR}${FILE}
- rsync -avz --password-file=/etc/rsyncd/rsyncd.pass $FILECHANGE darling@${R1}::root${DESTHOSTDIR} &>/dev/null && \
- echo "At ${TIME} on ${DATE}, file $FILECHANGE was backed up via rsync" >> $LOG
- rsync -avz --password-file=/etc/rsyncd/rsyncd.pass $FILECHANGE darling@${R2}::root${DESTHOSTDIR} &>/dev/null && \
- echo "At ${TIME} on ${DATE}, file $FILECHANGE was backed up via rsync" >> $LOG
- rsync -avz --password-file=/etc/rsyncd/rsyncd.pass $FILECHANGE darling@${R3}::root${DESTHOSTDIR} &>/dev/null && \
- echo "At ${TIME} on ${DATE}, file $FILECHANGE was backed up via rsync" >> $LOG
- done
本文转自 gm100861 51CTO博客,原文链接:http://blog.51cto.com/gm100861/935176