`
haoningabc
  • 浏览: 1444285 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

备份方法scp rsync,inotifywait

阅读更多
参考http://blog.leezhong.com/project/2010/12/13/inotify-rsync.html
https://github.com/rvoicilas/inotify-tools/wiki/
远程执行脚本
ssh -l root 10.10.10.10 "/opt/test/stop.sh";
ssh -l root 10.10.10.10  "scp /opt/data/database.tcb 10.10.10.10:/opt/ttserver/test/test.tcb"

rsync+inotifywait
#!/bin/sh
/usr/local/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format  '%T %w%f %e' \
 -e modify,create,move  \
/opt/cms5/share/template/cms_page/template/ \
| while read date time file event
        do
                rsync -av --progress  --include=kk  --exclude='*' --password-file=/etc/rsyncd.secrets /opt/backuptest/ haha@10.1.224.171::test >>/opt/log/templatenotify.log
                #echo "${date} ${time} ${file} ${event}"
        done


#!/bin/sh
#/usr/local/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format  '%T %w %f %e' \
/usr/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format  '%T %w %f %e' \
 -e modify,create,move  \
/opt/backuptest/ \
| while read date time path file event
        do
#               rsync -av --password-file=/etc/rsyncd.secrets /opt/rsynctest/ test@10.10.10.10::rsynctest >>/tmp/rsync.log
                rsync --include='${file}' --exclude='*' -av  ${path}  root@10.1.224.171:${path}
                echo "${date} ${time} ${path} ${file} ${event}"
        done

--------templatenotify.sh----------
#!/bin/sh
#this is a test  not used for production ,please look 154 
logfile="/opt/log/templatenotify-`date +%Y%m%d`.log"
toip=10.11.10.10
/usr/local/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format  '%T %w%f %e' \
 -e CLOSE_WRITE,delete,create,move  \
/opt/template/ \
| while read date time  file event
do
case "$event" in
        DELETE)
        echo "delete ${file} but not rsync ----delete--- over" >>${logfile};
        ;;
        *)
        if [ "${file: -4}" != '4913' ]  && [ "${file: -1}" != '~' ]; then
                echo "rsync -av  $file  root@${toip}:`dirname $file`" >>${logfile}
                rsync -av  $file  root@${toip}:`dirname $file`  >>${logfile} 2>&1
                echo "${date}  ${time}  ${file} ${event} --------over" >>${logfile}
        fi
        ;;
esac
done

定时删除无用文件比如log
crontab -l
0 3 * * * (find /opt/modules/ -type f -mtime +2 -exec rm -f {} \;)

[@tc_157_49 share]# cat /usr/local/src/switch/templatenotify.sh
#!/bin/sh
#this is a test  not used for production ,please look 154 
logfile="/opt/log/templatenotify-`date +%Y%m%d`.log"
toip=10.11.157.53
/usr/local/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format  '%T %w%f %e' \
 -e CLOSE_WRITE,delete,create,move  \
/opt/cms5/share/template/cms_page/template/ \
| while read date time  file event
do
case "$event" in
        DELETE)
        echo "delete ${file} but not rsync ----delete--- over" >>${logfile};
        ;;
        *)
        if [ "${file: -4}" != '4913' ]  && [ "${file: -1}" != '~' ]; then
                echo "rsync -av  $file  root@${toip}:`dirname $file`" >>${logfile}
                rsync -av  $file  root@${toip}:`dirname $file`  >>${logfile} 2>&1
                echo "${date}  ${time}  ${file} ${event} --------over" >>${logfile}
        fi
        ;;
esac
done
[@tc_157_49 share]# 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics