42°

xtrabackup 笔记

环境

  • CentOS7
  • MySQL 5.27.22
  • XtraBackup 2.4

安装

  • 创建 repo 文件
    cat > /etc/yum.repos.d/percona.repo <<EOF
    [percona-release-x86_64]
    name = Percona Original release/x86_64 YUM repository
    #baseurl = http://repo.percona.com/percona/yum/release/$releasever/RPMS/x86_64
    baseurl = https://mirrors.cloud.tencent.com/percona/percona/yum/release/$releasever/RPMS/x86_64
    enabled = 1
    gpgcheck = 0
    gpgkey = file:///etc/pki/rpm-gpg/PERCONA-PACKAGING-KEY
    [percona-release-noarch]
    name = Percona Original release/noarch YUM repository
    #baseurl = http://repo.percona.com/percona/yum/release/$releasever/RPMS/noarch
    baseurl = https://mirrors.cloud.tencent.com/percona/percona/yum/release/$releasever/RPMS/noarch
    enabled = 1
    gpgcheck = 0
    gpgkey = file:///etc/pki/rpm-gpg/PERCONA-PACKAGING-KEY
    [percona-release-sources]
    name = Percona Original release/sources YUM repository
    #baseurl = http://repo.percona.com/percona/yum/release/$releasever/SRPMS
    baseurl = https://mirrors.cloud.tencent.com/percona/percona/yum/release/$releasever/SRPMS
    enabled = 0
    gpgcheck = 0
    gpgkey = file:///etc/pki/rpm-gpg/PERCONA-PACKAGING-KEY
    EOF
    
  • 安装
    yum clean all
    yum makecache fast
    yum install percona-xtrabackup-24
    

创建数据库备份用户

create user percona@localhost identified by '123456';
grant reload, lock tables, process, replication client on *.* to percona@localhost;
flush privileges;

全量备份

  • 按天创建全量备份目录
    xtrabackup --backup --user=percona --password=123456 --target-dir=/backup/$(date +mysql.%Y%m%d)
    # NFS 挂载时,需使用 sync 模式
    # 保留最近 3 天的全量备份
    ls -d mysql.* | head -n -3 | xargs rm -rf
    

恢复数据

  • 准备一个 xtrabackup 备份目录
    xtrabackup --prepare --target-dir=/backup/20190711
    
  • 停止 mysql 服务,移除数据目录
    systemctl stop mysqld
    cd /var/lib && [ -d mysql ] && mv mysql mysql_origin
    
  • 恢复 mysql 数据
    xtrabackup --copy-back --target-dir=/backup/20190711
    chown -R mysql.mysql /var/lib/mysql
    

本文由【俊赛潘安-才比管乐】发布于开源中国,原文链接:https://my.oschina.net/colben/blog/3072886

全部评论: 0

    我有话说: