title: 使用rsync备份远程备份binlog date: 2017-08-30 20:54:18 tags:
- crontab
- rsync
- binlog categories: Linux
背景
目前由于生产系统上空间有限,因此考虑将binlog以及相关备份全部copy到公司机房。
步骤
- 假设源机器ip为192.168.1.1(机器1) 镜像服务器ip为192.168.1.2(机器2)
- 分别在两边安装rsync
yum -y install rsync inotify-tools 复制代码
- 在机器1上配置如下 /etc/rsyncd.conf
对应新建文件/etc/binlog.pasuid = root gid = root use chroot = no max connections=0 pid file = /var/run/rsyncde.pid lock file = /var/run/rsync.lock log file = /var/log/rsyncd.log [backup] path = *** read only = no list = on auth users = rsyncuser secrets file = /etc/binlog.pas hosts allow=172.16.0.0/255.255.0.0 192.168.1.0/255.255.255.0 10.0.1.0/255.255.255.0 hosts deny=* [binlog] path = *** read only = no list = on auth users = rsyncuser secrets file = /etc/binlog.pas hosts allow=172.16.0.0/255.255.0.0 192.168.1.0/255.255.255.0 10.0.1.0/255.255.255.0 hosts deny=* 复制代码
可以看到如上就是对应的配置两个不同的实例。 此时我们需要运行服务器 需要注意的是binlog.pas 文件需要设置权限rsyncuser:*** 复制代码
chmod 600 /etc/binlog.pas 复制代码
- 运行服务器有两种
- 直接使用rsync 那么
rsync –daemon 复制代码
- 使用xinetd
/etc/rc.d/init.d/xinetd reload 复制代码
- 当服务端运行了之后 需要在客户端进行同步服务端资源(我们不需要删除服务端被删的文件)因此在机器2上运行命令如下
在服务端查看日志如下#!/bin/bash ################### . /etc/profile . ~/.bash_profile ################## rsync -vrztopg --progress --include-from '/home/shell/binlog_include.txt' --exclude-from '/home/shell/binlog_exclude.txt' rsyncuser@139.196.213.146::binlog /home/backup/binlog --password-file=/etc/binlog.pas 复制代码
将对应脚本加入crontab中即可2017/08/30 18:35:02 [13306] rsync on binlog/ from rsyncuser@UNKNOWN (***) 2017/08/30 18:35:02 [13306] building file list 2017/08/30 18:35:39 [13306] sent *** bytes received *** bytes total size *** 2017/08/30 20:35:01 [23013] Badly formed boolean in configuration file: "on". 2017/08/30 20:35:01 [23013] Badly formed boolean in configuration file: "on". 2017/08/30 20:35:01 [23013] name lookup failed for ***: Name or service not known 2017/08/30 20:35:01 [23013] connect from UNKNOWN (***) 2017/08/30 20:35:01 [23013] rsync on binlog/ from rsyncuser@UNKNOWN (***) 2017/08/30 20:35:01 [23013] building file list 2017/08/30 20:35:44 [23013] sent *** bytes received *** bytes total size *** 复制代码