阿里雲RDS XtraBackup備份與binlog增量恢復

本文檔是針對阿里雲RDS的全量備份爲基礎的。阿里雲RDS的物理全量備份是基於備庫的,因此咱們在恢復的時候,須要根據備庫的全量數據加上主庫的binlog來恢復數據。mysql

方案前期準備工做:sql

  1. 本地xtrabackup安裝數據庫

  2. RDS主庫binlog備份(RDS自己也有備份,可是時間間隔長,數據差別可能大一些)app

  3. RDS開啓物理備份socket

方案整體步驟以下:ide

  1. 下載RDS備庫物理備份數據ui

  2. 肯定須要同步的binlog文件阿里雲

  3. 恢復RDS物理備份數據spa

  4. 恢復主庫增量的binlog數據rest

阿里雲的備份命令:

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

開始對方案進行操做

1、備份,使用阿里的備份就能夠

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、恢復到一個新數據庫

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

相關文章
相關標籤/搜索