inotify

Linux服务器间文件实时同步的实现

孤街醉人 提交于 2019-12-01 11:44:11
使用场景 现有服务器A和服务器B,如果服务器A的指定目录(例如 /home/paul/rsync/ )中的内容发生变更(增删改和属性变更),实时将这些变更同步到服务器B的目标目录中(例如 /home/paul/rsync/ )。 数据镜像备份工具Rsync Rsync是一个非常快速和灵活的文件复制工具。它支持本机或者是和远程服务器间的文件复制。Rsync使用了delta-transfer算法,它只需要传送源端和目标端的文件差异部分,大大减少了网络带宽的消耗和复制耗费的时间。Rsync多用于数据备份和镜像。 Rsync使用了快速检查算法,通过比较文件大小或最后修改时间的变化来判断文件是否需要同步。 Rsync连接远程主机有两种方式:使用ssh或rsync daemon。这里使用Rsync方式来实现远程文件备份。 Rsync的安装与操作 安装Rsync 分别在服务器A和服务器B的terminal执行: sudo yum install rsync 安装完毕后,会发现rsync的配置文件位于 etc/rsyncd.conf 。该文件使用daemon方式同步时需要使用,此处暂不介绍。 配置服务器A和B之间的免密登录 服务器A执行: ssh-keygen ssh-copy-id 服务器B的IP地址 创建源端目录和目标端目录 在服务器A中: mkdir /home/paul/rsync

干货 | 如何将主机文件自动同步至对象存储

笑着哭i 提交于 2019-12-01 10:01:37
注:最好利用京东云对象存储来存储一些静态文件,不建议用其直接存储数据库之类的数据文件,而且也会受到速度的影响,当然我们可以利用其存储备份文件。 今天我们来利用s3fs工具将京东云对象存储挂载到京东云云主机,把对象存储Bucket(空间)当成一个文件夹挂载到Linux系统内部,当成一个系统文件夹来使用,之后我们会利用inotify+rsync工具来实现主机文件自动同步到对象存储的挂载目录,以此来实现主机文件自动同步至京东云对象存储。 演示示意图: 一、挂载对象存储到云主机 1. 创建CentOS 7.4云主机 首先我们需要打开京东云官网:http://www.jdcloud.com,点击右上角控制台登陆后开始创建一台京东云云主机,方法详见:https://docs.jdcloud.com/cn/virtual-machines/create-linux-instance 云主机创建完成后如下: 2. 安装依赖包 yum install automake fuse fuse-devel gcc-c++ git libcurl-devel libxml2-devel make openssl-devel -y 3. 安装s3fs yum install epel-release s3fs-fuse -y 4. 创建密码文件 echo Access_Key_ID:Access_Key

How to use inotifywait to watch files within folder instead of folder

蹲街弑〆低调 提交于 2019-12-01 09:05:35
I want to use inotifyway to monitor newly created or moved file within a folder But only the files. Let's say my folder is name "watched_folder_test" and I have a file name "toto.txt". If I use the mv command to move the file to the watched_folder_test I got notify that I want Let's say inside the watched_folder_test I have a folder named foo and I create a file name 'bar.txt". I got the notification that I want. But here is my issue. If I have a folder name foo outside of watched_folder_test and I have a file name bar.txt inside it ( foo/bar.txt ) and I move that entire folder inside watched

How to use inotifywait to watch files within folder instead of folder

梦想的初衷 提交于 2019-12-01 07:06:02
问题 I want to use inotifyway to monitor newly created or moved file within a folder But only the files. Let's say my folder is name "watched_folder_test" and I have a file name "toto.txt". If I use the mv command to move the file to the watched_folder_test I got notify that I want Let's say inside the watched_folder_test I have a folder named foo and I create a file name 'bar.txt". I got the notification that I want. But here is my issue. If I have a folder name foo outside of watched_folder_test

Getting File Create Notifications for CIFS Mount in Linux

我的梦境 提交于 2019-12-01 02:48:10
I have a windows share mounted via CIFS on an ubuntu server. I need to a way to know when a new file has been added to the Windows share. I tried this inotify program: http://www.thegeekstuff.com/2010/04/inotify-c-program-example/ Which works fine with standard directories, but is unable to catch any CIFS changes. I don't neccessarily need to use inotify, although I would like to, but any suggestions on how to accomplish getting file create notifications would be great. I have also been working on this and ran into the same issue - it seems (after a little trawling on google) that,

Getting File Create Notifications for CIFS Mount in Linux

核能气质少年 提交于 2019-11-30 23:29:29
问题 I have a windows share mounted via CIFS on an ubuntu server. I need to a way to know when a new file has been added to the Windows share. I tried this inotify program: http://www.thegeekstuff.com/2010/04/inotify-c-program-example/ Which works fine with standard directories, but is unable to catch any CIFS changes. I don't neccessarily need to use inotify, although I would like to, but any suggestions on how to accomplish getting file create notifications would be great. 回答1: I have also been

使用inotify和git pull 实现网站自动部署(附wordpress插件)

[亡魂溺海] 提交于 2019-11-30 22:54:13
本文转载自我的个人网站的博客文章,原文: 使用inotify和git-pull-实现网站自动部署附wordpress插件 --------------------- 我的个人网站项目托管在osc的git仓库里,以前的更新方法是从把代码从本地push到git仓库后,远程登陆服务器,执行一次git pull,把代码更新到服务器。久而久之,渐渐觉得这样的方式太过麻烦。 我们知道,git仓库一般都提供web hooks, 就是每次push代码后,都会给远程HTTP URL发送一个POST请求,比如这是oschina的web hook: http://git.oschina.net/oschina/git-osc/wikis/WebHook-%E4%BD%BF%E7%94%A8%E7%AE%80%E4%BB%8B 。 所以一个可行的办法是服务器收到这个web hook 的post请求之后在网站目录自动执行一次git pull, 这样就把代码更新到服务器了。 但是有一个问题,服务器使用的是php,它获取这个请求之后,由于运行php-fpm的用户为daemon,因为安全因素,网站目录对这个用户并不全部可写,所以执行git pull需要root权限,而且,使用 system (),exec(),passthru()这类调用外部程序的函数有一定的危险,我也不喜欢。 然后找到了一个神器:

Is there a way to watch a mysql database for changes using perl?

倖福魔咒の 提交于 2019-11-30 20:17:35
I'm looking for a solution similar to the inotify method of watching files for changes. I'm aware that I could watch the binlog file of the mysql database and run queries to pick out the new results but that seems very inefficient and inelegant; as does simply doing masses of queries in a loop waiting for new results. If you add a TRIGGER to the table(s) you're interested in, you can use that to alert the watching application. You could do that in a number of ways: Create an audit table in the database, and have the trigger write the relevant info there; and have your watching application poll

inotifywait - exclude regex pattern formatting

╄→尐↘猪︶ㄣ 提交于 2019-11-30 08:51:18
I am trying to use inotifywait to watch all .js files under my ~/js directory; how do I format my regex inside the following command? $ inotifywait -m -r --exclude [REGEX HERE] ~/js The regex - according to the man page, should be of POSIX extended regular expression - needs to match "all files except those that ends in .js ", so these files can in turn be excluded by the --exclude option. I've tried the (?!) lookaround thing, but it doesn't seem to work in this case. Any ideas or workarounds? Would much appreciate your help on this issue. I've tried the (?!) thing This thing is called

rsync+inotify实现服务器之间文件实时同步

纵饮孤独 提交于 2019-11-30 06:38:43
之前做了“ssh信任与scp自动传输脚本”的技术文档,此方案是作为公司里备份的方法,但在实际的运行中,由于主服务器在给备份服务器传输的时候,我们的主服务器需要备份的文件是实时、不停的产生的,造成不知道主服务器给备份服务器传输了多少文件,磁盘空间就那么大,做备份的原因:一个是为了保持文件,另外一个是解决主服务器的磁盘饱满问题,但由于不知道备份服务器到底接收了多少文件,所以主服务器里的文件不敢删除(如果没有备份的情况下删除,问题就严重了,我这个是政府的项目,服务器里的文件都是重要的,删错了就走人~~~~(>_<)~~~~ ),所以我就采用了rsync+inotify的方式来实时同时服务器之间的文件,而且传输的过程是加密的,比scp安全多了(即使scp采用ssh信任,用密钥,也不是万无一失的)。 以下是我给公司运维做的备份技术文档,分享给大家,希望对大家有帮助。 先介绍一下rsync与inotify,都在在网上找的资料。先声明下面的rsync与inotify介绍不是我自己写的。 1、rsync 与传统的cp、tar备份方式相比,rsync具有安全性高、备份迅速、支持增量备份等优点,通过rsync可以解决对实时性要求不高的数据备份需求,例如定期的备份文件服务器数据到远端服务器,对本地磁盘定期做数据镜像等。 随着应用系统规模的不断扩大,对数据的安全性和可靠性也提出的更好的要求