阿里云RDS XtraBackup备份与binlog增量恢复

本文档是针对阿里云RDS的全量备份为基础的。阿里云RDS的物理全量备份是基于备库的,所以我们在恢复的时候,需要根据备库的全量数据加上主库的binlog来恢复数据。

方案前期准备工作:

  1. 本地xtrabackup安装

  2. RDS主库binlog备份(RDS本身也有备份,但是时间间隔长,数据差异可能大一些)

  3. RDS开启物理备份

方案总体步骤如下:

  1. 下载RDS备库物理备份数据

  2. 确定需要同步的binlog文件

  3. 恢复RDS物理备份数据

  4. 恢复主库增量的binlog数据

阿里云的备份命令:

tool_name = innobackupex
tool_command = --defaults-file=/etc/my3016.cnf --password=... --user=aliyun_root --host=127.0.0.1 --port=3016 --tmpdir=/home/mysql/backup/3016 --rocksdb_checkpoint_path=/mysqldata/backup_tmp/11293269_5067582 --rds-xb-fd-limits=400000 --slave-info --stream=tar /home/mysql/backup/3016

开始对方案进行操作

一、备份,使用阿里的备份就可以

innobackupex --defaults-file=/export/server/mysql/slave/config/my.cnf --backup --socket=/export/server/mysql/slave/mysql.sock --password=123456 --user=root --host=127.0.0.1 --port=3900 --rds-xb-fd-limits=400000  --slave-info  /export/data/mysql/restore01

二、恢复到一个新数据库

2.1 准备全量备份

innobackupex --apply-log /export/data/mysql/restore01/2019-04-04_19-42-24/


2.2 恢复到一个新的数据目录

innobackupex  --defaults-file=/export/server/mysql/restore/config/my.cnf --copy-back --rsync /export/data/mysql/restore01/2019-04-04_19-42-24/

附上my.cnf配置

[client]
port = 4000
socket = /export/server/mysql/restore/mysql.sock
default-character-set=utf8

[mysql]
default-character-set=utf8

[mysqld]
server_id = 2
port = 4000
user = mysql
character-set-server = utf8mb4
default_storage_engine = innodb
log_timestamps = SYSTEM
socket = /export/server/mysql/restore/mysql.sock
basedir = /export/local/mysql
datadir = /export/data/mysql/restore
pid-file = /export/server/mysql/restore/mysql.pid
max_connections = 10000
max_connect_errors = 10000
table_open_cache = 1024
max_allowed_packet = 128M
open_files_limit = 65535
lower_case_table_names = 1
innodb_buffer_pool_size = 1024M
innodb_file_per_table = 1
innodb_write_io_threads = 4
innodb_read_io_threads = 4
innodb_purge_threads = 2
innodb_flush_log_at_trx_commit = 1
innodb_log_file_size = 512M
innodb_log_files_in_group = 2
innodb_log_buffer_size = 16M
innodb_max_dirty_pages_pct = 80
innodb_lock_wait_timeout = 30
innodb_data_file_path = ibdata1:10M:autoextend
slow_query_log = 1
long_query_time = 1
log_error = /export/server/mysql/restore/log/mysql_error.log
slow_query_log_file = /export/server/mysql/restore/log/mysql_slow.log
transaction-isolation=Read-Committed

log-bin = mysql-bin
innodb_flush_log_at_trx_commit = 1
binlog_ignore_db = mysql

lower_case_table_names=1
max_connect_errors=1000

这里需要手动创建mysql_slow.log、mysql_error.log文件,并赋予mysql:mysql属主权限:

chown  mysql:mysql  /export/server/mysql/restore

chown  mysql:mysql  /export/data/mysql/restore


2.3 启动数据库

nohup  /export/local/mysql/bin/mysqld_safe --defaults-file=/export/server/mysql/restore/config/my.cnf &


2.4 恢复增量binlog

可以根据/export/data/mysql/restore01/2019-04-04_19-42-24/目录下的xtrabackup_slave_info的文件内容,判断上次备份的路径

我这里是:

CHANGE MASTER TO MASTER_LOG_FILE='mysql-bin.000003', MASTER_LOG_POS=20561581;


2.5 恢复增量binlog数据

mysqlbinlog --start-position=20561581 /export/data/mysql/master/mysql-bin.000003 | /export/local/mysql/bin/mysql  -S /export/server/mysql/restore/mysql.sock  --port=3900 -uroot -p123456


上一篇:2018-12-23 从aliyun的rds全备恢复数据库到docker的mysql。


下一篇:云数据库RDS存储能力进化解析!