inotify和rsync实现实时同步-wx5c84e6f0bb26f的博客

Windows Windows 2个月前 (08-15) 4次浏览 未收录 0个评论 扫描二维码

inotify和rsync实现实时同步首先先用两台主机实现rsyncc同步服务端:[root@centos7 data 14:20:35]#echo “rsyncuser:123” > /etc/rsync.pass 生成验证文件[root@centos7 data 14:21:13]#chmod 600 /etc/rsync.pass [root@centos7 data 14:21:19]#mkdir /backup 准备目录[root@centos7 data 15:18:52]#vim /etc/rsyncd.conf 配置/etc/rsyncd.confuid = rootgid = rootuse chroot = nomax connections = 0 ignore errorsexclude = lost+found/log file = /var/log/rsyncd.logpid file = /var/run/rsyncd.pidlock file = /var/run/rsyncd.lockreverse lookup = nohosts allow = 192.168.0.0/24[backup]path = /backup/comment = backupread only = noauth users = rsyncusersecrets file = /etc/rsync.pass comment = ftp export area [root@centos7 ~ 14:45:22]#systemctl start rsyncd 开启服务,监听873端口

客户端:[root@centos6 ~ 12:02:50]#echo “123” > /etc/rsync.pass 生成密码文件[root@centos6 ~ 15:45:39]#chmod 600 /etc/rsync.pass[root@centos6 ~ 15:45:47]#rsync -avz –password-file=/etc/rsync.pass /data/ rsyncuser@192.168.0.17::backup 同步数据sending incremental file list./ERROR: daemon refused to receive directory “lost+found”*** Skipping any contents from this failed directory ***data/

sent 72 bytes received 16 bytes 176.00 bytes/sectotal size is 0 speedup is 0.00rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1039) [sender=3.0.6]

结合inotify+rsync实现同步:[root@centos6 ~ 16:08:40]#yum -y install epel-release[root@centos6 ~ 16:08:57]#yum -y install inotify-tools[root@centos6 ~ 16:11:33]#vim inotify_rsync.sh#!/bin/bashSRC=’/data/’DEST=’rsyncuser@192.168.0.17::backup’br/>#!/bin/bashSRC=’/data/’DEST=’rsyncuser@192.168.0.17::backup’FILEPATH=${DIR}${FILE}rsync -az –delete –password-file=/etc/rsync.pass $SRC $DEST && echo “At ${TIME} on ${DATE}, file $FILEPATH was backuped up via rsync” >> /var/log/changelist.log#注意:因为ext系统文件系统有lost+found文件夹,所有rsync会同步成功,但命令的执行结果是失败的,所有不会写日志至/var/log/changelist.log中,要想成功,在ext系统文件系统中把&&换成||即可done [root@centos6 ~ 16:13:53]#./inotify_rsync.shinotify和rsync实现实时同步-wx5c84e6f0bb26f的博客在客户端创建文件inotify和rsync实现实时同步-wx5c84e6f0bb26f的博客服务端几乎瞬间就能够同步inotify和rsync实现实时同步-wx5c84e6f0bb26f的博客

喜欢 (0)
[]
分享 (0)
关于作者:
发表我的评论
取消评论
表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址