备份方法scp rsync,inotifywait

编程技术  /  houtizong 发布于 3年前   142
参考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/ [email protected]::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/ [email protected]::rsynctest >>/tmp/rsync.log                rsync --include='${file}' --exclude='*' -av  ${path}  [email protected]:${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 eventdocase "$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        ;;esacdone

定时删除无用文件比如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 eventdocase "$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        ;;esacdone[@tc_157_49 share]# 

请勿发布不友善或者负能量的内容。与人为善,比聪明更重要!

留言需要登陆哦

技术博客集 - 网站简介:
前后端技术:
后端基于Hyperf2.1框架开发,前端使用Bootstrap可视化布局系统生成

网站主要作用:
1.编程技术分享及讨论交流,内置聊天系统;
2.测试交流框架问题,比如:Hyperf、Laravel、TP、beego;
3.本站数据是基于大数据采集等爬虫技术为基础助力分享知识,如有侵权请发邮件到站长邮箱,站长会尽快处理;
4.站长邮箱:[email protected];

      订阅博客周刊 去订阅

文章归档

文章标签

友情链接

Auther ·HouTiZong
侯体宗的博客
© 2020 zongscan.com
版权所有ICP证 : 粤ICP备20027696号
PHP交流群 也可以扫右边的二维码
侯体宗的博客