这里为了显示,打印了出来。
可以发现,基于时间点的还原,找到的文件是预期的:
1个完整备份,2个增量备份,2个binlog日志中的一部分数据,
其中binlog日志还原的start-position成功地衔接到最后一个增量备份的position,同时最后一个binlog日志的还原停留在指定的时间点。
自动生成的shell还原代码
################uncompress backup file###################
innobackupex --apply-log --redo-only /temp/restoretmp/20190801184134_full
innobackupex --apply-log --redo-only /temp/restoretmp/20190801184134_full --incremental-dir=/temp/restoretmp/20190801184335_inc
innobackupex --apply-log --redo-only /temp/restoretmp/20190801184134_full --incremental-dir=/temp/restoretmp/20190801184518_inc
innobackupex --apply-log /temp/restoretmp/20190801184134_full
################stop mysql service###################
systemctl stop mysqld_7000
####################backup current database file###########################
mv /usr/local/mysql57_data/mysql7000/data /usr/local/mysql57_data/mysql7000/data_20190801185855
mkdir /usr/local/mysql57_data/mysql7000/data
chown -R mysql.mysql /usr/local/mysql57_data/mysql7000/data
################restore backup data###################
innobackupex --defaults-file=/usr/local/mysql57_data/mysql7000/etc/my.cnf --copy-back --rsync /temp/restoretmp/20190801184134_full
chown -R mysql.mysql /usr/local/mysql57_data/mysql7000/data
################stop mysql service###################
systemctl start mysqld_7000
################restore data from binlog###################
cd /usr/local/mysql57_data/mysql7000/log/bin_log
mysqlbinlog mysql_bin_1300.000001 --skip-gtids=true --start-position=982 | mysql mysql -h127.0.0.1 -uroot -proot -P7000
mysqlbinlog mysql_bin_1300.000002 --skip-gtids=true --stop-datetime="2019-08-01 18:50:59" | mysql -h127.0.0.1 -uroot -proot -P7000
日志信息
实现
# -*- coding: utf-8 -*-
import os
import time
import datetime
import sys
import socket
import logging
logging.basicConfig(level=logging.INFO
#handlers={logging.FileHandler(filename='restore_log_info.log', mode='a', encoding='utf-8')}
)
host = "127.0.0.1"
port = "7000"
user = "root"
password = "root"
instance_name = "mysqld_7000"
stop_at = "2019-08-01 18:50:59"
cnf_file = "/usr/local/mysql57_data/mysql7000/etc/my.cnf"
backup_dir = "/usr/local/backupdata/"
dest_dir = "/temp/restoretmp/"
xtrabackuplog_name = "backuplog.log"
backupfilelist = os.path.join(backup_dir,"backupfilelist.log")
#根据key值,获取MySQL配置文件中的value
def get_config_value(key):
value = None
if not key:
return value
if os.path.exists(cnf_file):
with open(cnf_file, 'r') as f:
for line in f:
if (line.split("=")[0]):
if(line[0:1]!="#" and line[0:1]!="["):
if (key==line.split("=")[0].strip()):
&n