CentOS   发布时间:2022-04-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了CentOS6.6 rsync+inotify实现数据时时备份大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

rsync+inotify实现数据时时备份     注意:rsync的daemon模式已提前配置好了,只需要配置inotify即可。 基本环境   系统版本 主机名 IP地址 角色 备份/监控目录 CentOS  6.6 BACkup 10.0.0.10 rsync服务端 /BACkup CentOS  6.6 nfs-server 10.0.0.7 rsync客户端 /data   inotif

rsync+inotify@H_502_6@实现数据时时备份

注意:rsyncdaemon模式已提前配置好了,只需要配置inotify即可

  • 基本环境

系统版本

主机名

IP地址

角色

备份/监控目录

CentOS 6.6

BACkup

10.0.0.10

rsync服务端

/BACkup

CentOS 6.6

nfs-server

10.0.0.7

rsync客户端

/data

[root@nfs-server tools]# ls -l/proc/sys/fs/inotify/

@R_144_10586@l 0

-rw-r--r-- 1 root root 0 May 16 19:44max_queued_events

-rw-r--r-- 1 root root 0 May 16 19:44max_user_instances

-rw-r--r-- 1 root root 0 May 16 19:44max_user_watches

  1. 下载inotify工具包并解压安装

[root@nfs-server tools]# wget--no-check-certificate https://cloud.github.com/downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar.gz

[root@nfs-server tools]# tar-zxvf inotify-tools-3.14.tar.gz

[root@nfs-server tools]# cdinotify-tools-3.14

[root@nfs-serverinotify-tools-3.14]# ./configure --prefix=/usr/local/inotify-tools-3.14

[root@nfs-serverinotify-tools-3.14]# make && make install

[root@nfs-server inotify-tools-3.14]#ln -s /usr/local/inotify-tools-3.14/ /usr/local/inotify-tools

工具集介绍

[root@nfs-serverinotity-tools]# ls /usr/local/inotify-tools/bin

inotifywait inotifywatch

一共安装了2个工具(命令),即inotifywaitinotifywatch

inotifywait:在被监控的文件或目录上等待特定文件系统事件(openclosedelete等)发生,执行后处于阻塞状态,适合在sHell脚本中使用。

inotifywatch:收集被监视的文件系统使用度统计数据,指文件系统事件发生的次数统计

  1. 监控本地/data目录

[root@nfs-server /]#/usr/local/inotify-tools/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M'--format '%T %w%f' -e create,close_write,delete /data

create:监控创建文件

close_write:监控修改文件

delete:监控删除文件

  1. inotify监控nfs-server/data目录,然后调用rsync时时备份到BACkup主机的/BACkup目录,并写成脚本完成

#!/bin/bash

##############################BACkupscripts#######################

#author wangning

#qq 1198143315

#date 2017-6-9

#E-mail 1198143315@qq.com

inotify=/usr/local/inotify-tools/bin/inotifywait

$inotify -mrq --format '%w%f' -e create,delete/data \

|while read file

do

cd / &&

rsync -az ./data/ --deletersync_BACkup@10.0.0.10::BACkup/ \

--password-file=/etc/rsync.password

done

  • 关键参数说明

  • /proc/sys/fs/inotify/目录下有三个文件,对inotify机制有一定的限制

@H_163_180@max_user_watches:设置inotifywaitinotifywatch命令可以监视的文件数量(单进程)

@H_163_180@max_user_instances:设置每个用户可以运行的inotifywaitinotifywatch命令的进程数

@H_163_180@max_queued_events:设置inotify实例事件(event)队列可容纳的事件数量

  1. 工作中如果参数不够用,可以调大一些

[root@nfs-server scripts]# echo"50000000" >/proc/sys/fs/inotify/max_user_watches

[root@nfs-server scripts]# echo"50000000" >/proc/sys/fs/inotify/max_queued_events

大佬总结

以上是大佬教程为你收集整理的CentOS6.6 rsync+inotify实现数据时时备份全部内容,希望文章能够帮你解决CentOS6.6 rsync+inotify实现数据时时备份所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。