rsync+inotify同步备份MYSQL数据

xiaoxiao2021-02-28  88

备份源10.16.77.93 备份端10.16.77.95 原理:利用inotify监控mysql数据库数据目录:/usr/local/mysql/data 一.备份端服务的配置 1)确认rsync是否安装,大多数linux发行版默认安装rsync rpm -q rsync 2)手动创建rsync的配置文件 uid=root gid=root use chroot = no max connections = 10 strict modes = yes pid file = /var/run/rsyncd.pid lock file = /var/run/rsyncd.lock log file = /var/log/rsyncd.log [mysqldata] path = /data/mysqldata comment = mysql data ignore errors  read only = no write only = no hosts allow = 10.16.77.93 list = false auth users = rsync_user secrets file = /etc/rsync.password 3)建立rsync用户名和密码文件,并为/etc/rsync.password授权为600 echo "rsync_user:rsync_user_pwd" > /etc/rsync.password chmod -R 600 /etc/rsync.password 4)启动rsync服务 rsync --daemon 至此备份端服务配置完成 二.备份源配置 1)设置rsync客户端密码文件,将密码文件的权限设置成600 客户端只需要设置rsync同步密码即可,不用重设用户名 echo "rsync_user_pwd" > /etc/rsync.password chmod -R 600 /etc/rsync.password 2)安装inotify ./configure --prefix=/usr/local make && make install 3)编写运行监控脚本。为了保证/usr/local/mysql/data目录自动同步,安装完成inotify后,写一个inotify脚本。 #!/bin/bash ip=10.16.77.95 src=/data/mysqldata_src/ dst=mysqldata user=rsync_user /usr/local/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f' -e modify,delete,create,attrib ${src} \     | while read file do rsync -vzrtopg --delete --progress $src $user@$ip::$dst --password-file=/etc/rsync.password > /dev/null && echo "$src was rsyncd" done
转载请注明原文地址: https://www.6miu.com/read-75710.html

最新回复(0)