备份方法scp rsync,inotifywait
备份方法scp rsync,inotifywait
博客分类: linux
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
概要 - 为什么需要监控文件系统?
在日常工作中,人们往往需要知道在某些文件(夹)上都有那些变化,比如:- 通知配置文件的改变
- 跟踪某些关键的系统文件的变化
- 监控某个分区磁盘的整体使用情况
- 系统崩溃时进行自动清理
- 自动触发备份进程
- 向服务器上传文件结束时发出通知
Inotify到底是什么?
% grep INOTIFY_USER /boot/config-$(uname -r)
CONFIG_INOTIFY_USER=y
简单的文件变化通知样例:
% inotifywait -rme modify,attrib,move,close_write,create,delete,delete_self /srv/test
Setting up watches. Beware: since -r was given, this may take a while!
Watches established.
% mkdir /srv/test/infoq
% echo TODO > /srv/test/infoq/article.txt
% rm /srv/test/infoq/article.txt
/srv/test/ CREATE,ISDIR infoq
/srv/test/infoq/ CREATE article.txt
/srv/test/infoq/ MODIFY article.txt
/srv/test/infoq/ CLOSE_WRITE,CLOSE article.txt
/srv/test/infoq/ DELETE article.txt
% inotifywait --exclude '^/srv/test/(large|ignore)/' -rme modify,attrib,move,close_write,create,delete,delete_self /srv/test
Setting up watches. Beware: since -r was given, this may take a while!
Watches established.
% echo test > /srv/test/action.txt
% echo test > /srv/test/large/no_action.txt
% echo test > /srv/test/ignore/no_action.txt
% echo test > /srv/test/large-name-but-action.txt
/srv/test/ CREATE action.txt
/srv/test/ MODIFY action.txt
/srv/test/ CLOSE_WRITE,CLOSE action.txt
/srv/test/ CREATE large-name-but-action.txt
/srv/test/ MODIFY large-name-but-action.txt
/srv/test/ CLOSE_WRITE,CLOSE large-name-but-action.txt
Inotifywatch - 使用inotify来统计文件系统访问信息
% inotifywatch -v -e access -e modify -t 120 -r ~/InfoQ
Establishing watches...
Setting up watch(es) on /home/mika/InfoQ
OK, /home/mika/InfoQ is now being watched.
Total of 58 watches.
Finished establishing watches, now collecting statistics.
Will listen for events for 120 seconds.
total modify filename
2 2 /home/mika/InfoQ/inotify/
Inotify的配置选项
% inotifywait -r /
Setting up watches. Beware: since -r was given, this may take a while!
Failed to watch /; upper limit on inotify watches reached!
Please increase the amount of inotify watches allowed per user via `/proc/sys/fs/inotify/max_user_watches'.
# cat /proc/sys/fs/inotify/max_user_watches
8192
# echo 16000 > /proc/sys/fs/inotify/max_user_watches
# cat /proc/sys/fs/inotify/max_user_watches
16000
使用Inotify的一些工具
# echo username > /etc/incron.allow
/srv/test/ IN_CLOSE_WRITE mail -s "$@/$#\n" root
# strace -e inotify_init,inotify_add_watch tail -f ~log/syslog
[...]
inotify_init() = 4
inotify_add_watch(4, "/var/log/syslog", IN_MODIFY|IN_ATTRIB|IN_DELETE_SELF|IN_MOVE_SELF) = 1
在脚本中使用Inotify
总结
综上所述,Inotify为Linux提供了一套高效监控和跟踪文件变化的机制,它可以实时地处理、调试以及监控文件变化,而轮询是一种延迟机制。 对于系统管理员,关于实现事件驱动的服务如系统备份,构建服务以及基于文件操作的程序调试等,Inotify无疑提供了强大的支持
转载于:https://blog.51cto.com/dadloveu/845730
备份方法scp rsync,inotifywait相关推荐
- centos linux 系统日常管理4 scp,rsync,md5sum,sha1sum,strace ,find Rsync 常见错误及解决方法 第十七节课...
centos linux 系统日常管理4 scp,rsync,md5sum,sha1sum,strace ,find Rsync 常见错误及解决方法 第十七节课 rsync可以增量同步,scp不行 ...
- linux 文件夹同步备份软件下载,rsync从linux到linux的文件同步备份方法_rsync在linux下同步备份教程_飞翔教程...
一.环境 须要备份文件的服务器(服务器端):192.168.1.201 (RHEL 5) 接收备份文件的服务器(客户端):192.168.1.202 (CENTOS 5) 二.安装配置 1.服务器端的 ...
- linux下不同服务器间数据传输(rcp,scp,rsync,ftp,sftp,lftp,wget,curl)
因为工作原因,需要经常在不同的服务器见进行文件传输,特别是大文件的传输,因此对linux下不同服务器间数据传输命令和工具进行了研究和总结.主要是rcp,scp,rsync,ftp,sftp,lftp, ...
- 如何备份mysql_史上最全的MYSQL备份方法
本人曾经 用过的备份方式有:mysqldump.mysqlhotcopy.BACKUP TABLE .SELECT INTO OUTFILE,又或者备份二进制日志(binlog),还可以是直接拷贝数据 ...
- 【MongoDB】MongoDB备份方法
2019独角兽企业重金招聘Python工程师标准>>> MongoDB备份方法 On this page Back Up with MongoDB Cloud Manager or ...
- linux 上传网页文件大小,Linux:上传未完成的文件 – 文件大小检查(scp / rsync)
我通常最终会遇到以下情况:例如,我有一个来自相机的650 MB MPEG-2 .avi视频文件.然后,我使用ffmpeg2theora将其转换为Theora .ogv视频文件,比如说大小为150 MB ...
- 云计算学习历程之-备份服务(rsync)上
rsync介绍 rsync是linux系统下的数据镜像备份工具.使用快速增量备份工具Remote Sync可以远程同步,支持本地复制,或者与其他SSH.rsync主机同步, 支持增量传输(只同步变化的 ...
- oracle数据库备份方法主要有哪几种,Oracle数据库备份方法有哪三种?
Oracle数据库的备份方法很多,无论使用那种备份方法,备份的目的都是为了在出现故障后能够以尽可能小的时间和代价恢复系统.比如使用export实用程序导出数据库对象.使用Oracle备份数据库.使用O ...
- 基于PLSQL的数据库备份方法及如何解决导出clob和blob类型数据报错的问题
基于PLSQL的数据库备份方法及如何解决导出clob和blob类型数据报错的问题 参考文章: (1)基于PLSQL的数据库备份方法及如何解决导出clob和blob类型数据报错的问题 (2)https: ...
最新文章
- OpenCV(项目)车牌识别2 -- 车牌字符分割(直方图)
- 手机应用:非功能需求 Check List
- 已解决Cause: java.sql.SQLException: Incorrect string value: ‘\\xF0\\x9F\\x8C\\xB8 \\xE5...‘报错
- WPF wpf scrollviewer 触屏滚动 窗体弹跳
- 如何用c 语言编写阶乘程序,求10000的阶乘(c语言代码实现)
- Android:简易单词本(三)
- java 命名管道_Java中命名管道的并发读/写(在Windows上)
- atitit.Oracle 9 10 11 12新特性attilax总结
- jvmti_JVMTI标记如何影响GC暂停
- imagick php 缩放,php使用imagick模块实现图片缩放、裁剪、压缩示例
- 【消息果留言板 v1.2】支持回复邮件提醒+页面pc端宽度调整+时间友好显示
- 【详细说明】nginx反向代理wss websocket
- 北京涛思数据获得 Pre A 轮融资,专注时序空间大数据领域
- rpcbind 、nfs无法启动问题
- 单片机74LS164C语言例子,74ls164单片机编程汇总(跑马灯/驱动数码管)
- MIL自动化单元测试
- Mysql安装步骤:
- Numpy 用 npy/npz 文件保存与载入数据
- 计算机报名上传图片需要flash,公务员报名上传照片时需要的flash控件是什么
- 渗透测试抓包工具-wireshark