准备:安装qpress,
安装percona-xtrabackup-24
# yum localinstall percona-xtrabackup-24-2.4.4-1.el7.x86_64.rpm
# tar -xvf qpress-11-linux-x64.tar
全备恢复的步骤
0)提取数据
xbstream -x < /app/mysql/backup/4771/mysql-6jdr5q_2020_04_20_01_00_00/2020_04_20_01_00_00 -C /app/mysql/tmp/4771
1)解压备份:
innobackupex --decompress --parallel=4 --slave-info --throttle=300 --use-memory=200MB --tmpdir=/tmp --lock-wait-timeout=120 --lock-wait-threshold=120 --kill-long-queries-timeout=60 --kill-long-query-type=all --lock-wait-query-type=all --no-version-check /app/mysql/tmp/4771
#删除*.qp 文件
find /app/mysql/tmp/4771/full -name *.qp |xargs rm -f
2)全备应用日志:
innobackupex --defaults-file=/etc/my.cnf --apply-log --slave-info --throttle=300 --use-memory=200MB --tmpdir=/tmp --lock-wait-timeout=120 --lock-wait-threshold=120 --kill-long-queries-timeout=60 --kill-long-query-type=all --lock-wait-query-type=all --no-version-check /app/mysql/tmp/4771/full
3)恢复备份到数据库目录:
innobackupex --defaults-file=/etc/my.cnf --move-back --slave-info --tmpdir=/tmp --no-version-check /app/mysql/tmp/4771/full
rm -rf /app/mysql/data/4771/* && rm -rf /app/mysql/log/redolog/4771/* && rm -rf /app/mysql/log/binlog/4771/* && rm -rf /app/mysql/log/relaylog/4771/*
rm -rf /app/mysql/tmp/4771/full/* && rm -rf /app/mysql/tmp/4771/inc1/* && rm -rf /app/mysql/tmp/4771/inc2/* && rm -rf /app/mysql/tmp/4771/inc3/*
增量备份恢复的步骤(恢复到某一时间点)
mkdir -p /app/mysql/tmp/4771/{full,inc1,inc2,inc3}
0)提取数据
xbstream -x < /app/mysql/backup/4771/mysql-6jdr5q_2020_04_20_01_00_00/2020_04_20_01_00_00 -C /app/mysql/tmp/4771/full
xbstream -x < /app/mysql/backup/4771/mysql-6jdr5q_2020_04_20_01_00_00/2020_04_21_01_00_00 -C /app/mysql/tmp/4771/inc1
xbstream -x < /app/mysql/backup/4771/mysql-6jdr5q_2020_04_20_01_00_00/2020_04_22_01_00_00 -C /app/mysql/tmp/4771/inc2
xbstream -x < /app/mysql/backup/4771/mysql-6jdr5q_2020_04_20_01_00_00/2020_04_23_01_00_00 -C /app/mysql/tmp/4771/inc3
1)解压备份:
innobackupex --decompress --parallel=4 --slave-info --throttle=300 --use-memory=200MB --tmpdir=/tmp --lock-wait-timeout=120 --lock-wait-threshold=120 --kill-long-queries-timeout=60 --kill-long-query-type=all --lock-wait-query-type=all --no-version-check /app/mysql/tmp/4771/full
innobackupex --decompress --parallel=4 --slave-info --throttle=300 --use-memory=200MB --tmpdir=/tmp --lock-wait-timeout=120 --lock-wait-threshold=120 --kill-long-queries-timeout=60 --kill-long-query-type=all --lock-wait-query-type=all --no-version-check /app/mysql/tmp/4771/inc1
innobackupex --decompress --parallel=4 --slave-info --throttle=300 --use-memory=200MB --tmpdir=/tmp --lock-wait-timeout=120 --lock-wait-threshold=120 --kill-long-queries-timeout=60 --kill-long-query-type=all --lock-wait-query-type=all --no-version-check /app/mysql/tmp/4771/inc2
innobackupex --decompress --parallel=4 --slave-info --throttle=300 --use-memory=200MB --tmpdir=/tmp --lock-wait-timeout=120 --lock-wait-threshold=120 --kill-long-queries-timeout=60 --kill-long-query-type=all --lock-wait-query-type=all --no-version-check /app/mysql/tmp/4771/inc3
#删除*.qp 文件
cd /app/mysql/tmp/4771
find /app/mysql/tmp/4771/full -name *.qp |xargs rm -f && find /app/mysql/tmp/4771/inc1 -name *.qp |xargs rm -f && find /app/mysql/tmp/4771/inc2 -name *.qp |xargs rm -f && find /app/mysql/tmp/4771/inc3 -name *.qp |xargs rm -f
2)增量应用日志:
innobackupex --defaults-file=/etc/my.cnf --apply-log --redo-only --use-memory=200MB --slave-info --tmpdir=/tmp /app/mysql/tmp/4771/full
2020-4-28下午18:00做到此处
innobackupex --defaults-file=/etc/my.cnf --apply-log --redo-only --use-memory=200MB --slave-info --tmpdir=/tmp /app/mysql/tmp/4771/full --incremental-dir=/app/mysql/tmp/4771/inc1
innobackupex --defaults-file=/etc/my.cnf --apply-log --redo-only --use-memory=200MB --slave-info --tmpdir=/tmp /app/mysql/tmp/4771/full --incremental-dir=/app/mysql/tmp/4771/inc2
innobackupex --defaults-file=/etc/my.cnf --apply-log --slave-info --tmpdir=/tmp /app/mysql/tmp/4771/full --incremental-dir=/app/mysql/tmp/4771/inc3
innobackupex --defaults-file=/etc/my.cnf --apply-log --slave-info --tmpdir=/tmp /app/mysql/tmp/4771/full
3)恢复备份到数据库目录:
innobackupex --defaults-file=/etc/my.cnf --move-back --slave-info --tmpdir=/tmp --no-version-check /app/mysql/tmp/4771/full
4)修改目录权限
chown -R mysql:mysql /app/mysql
5)启动mysqld
/app/mysql/base/bin/mysqld_safe --defaults-file=/etc/my.cnf --datadir=/app/mysql/data/4771 --user=mysql &
6)验证是否恢复到预期时间
/app/mysql/base/bin/mysql -S /app/mysql/data/4771/mysqld.sock -uroot -pXXXXXXXX -e "select * from universe.u_delay"
7)计划恢复到2020-04-23 06:10:00
cat /app/mysql/tmp/4771/full/xtrabackup_binlog_info
/app/mysql/base/bin/mysqlbinlog /app/mysql/backup/4771/mysql-6jdr5q_binlog/mysql-bin.001830 --start-position=103429731 -vv >> /tmp/load.sql
/app/mysql/base/bin/mysqlbinlog /app/mysql/backup/4771/mysql-6jdr5q_binlog/mysql-bin.001831 --stop-datetime="2020-04-23 06:10:00" -vv >> /tmp/load.sql
nohup /app/mysql/base/bin/mysql -S /app/mysql/data/4771/mysqld.sock -uroot -pXXXXXXXX -e "source /tmp/load.sql" &
8)验证时间点
/app/mysql/base/bin/mysql -S /app/mysql/data/4771/mysqld.sock -uroot -pXXXXXXXX -e "select * from universe.u_delay"
mysql: [Warning] Using a password on the command line interface can be insecure.
+--------+---------------------+-----------------+
| source | real_timestamp | logic_timestamp |
+--------+---------------------+-----------------+
| ustats | 2020-04-23 06:09:59 | 73720322 |
+--------+---------------------+-----------------+
网友评论