使用rsync备份远程备份binlog


title: 使用rsync备份远程备份binlog date: 2017-08-30 20:54:18 tags:

  • crontab
  • rsync
  • binlog categories: Linux

背景

目前由于生产系统上空间有限,因此考虑将binlog以及相关备份全部copy到公司机房。

步骤

  1. 假设源机器ip为192.168.1.1(机器1) 镜像服务器ip为192.168.1.2(机器2)
  2. 分别在两边安装rsync
    yum -y install rsync inotify-tools
    复制代码
  3. 在机器1上配置如下 /etc/rsyncd.conf
    uid = 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=*
    复制代码
    对应新建文件/etc/binlog.pas
    rsyncuser:***
    复制代码
    可以看到如上就是对应的配置两个不同的实例。 此时我们需要运行服务器 需要注意的是binlog.pas 文件需要设置权限
    chmod 600 /etc/binlog.pas
    复制代码
  4. 运行服务器有两种
    1. 直接使用rsync 那么
    rsync –daemon
    复制代码
    1. 使用xinetd
    /etc/rc.d/init.d/xinetd reload
    复制代码
  5. 当服务端运行了之后 需要在客户端进行同步服务端资源(我们不需要删除服务端被删的文件)因此在机器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
    复制代码
    在服务端查看日志如下
    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 ***
    复制代码
    将对应脚本加入crontab中即可
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值