MySQL Point-in-Time Recovery like a Rockstar

Similar documents
MySQL Multi-Source Replication

Backup and Recovery Strategy

MySQL Replication. Rick Golba and Stephane Combaudon April 15, 2015

MySQL 5.6 New Replication Features

Replication features of 2011

How Facebook Got Consistency with MySQL in the Cloud Sam Dunster

Introduction to MySQL InnoDB Cluster

MySQL Group Replication in a nutshell

MySQL Group Replication in a nutshell

MySQL InnoDB Cluster & Group Replication in a Nutshell: Hands-On Tutorial

Consistent Reads Using ProxySQL and GTID. Santa Clara, California April 23th 25th, 2018

Oracle Exam 1z0-883 MySQL 5.6 Database Administrator Version: 8.0 [ Total Questions: 100 ]

Operational DBA In a Nutshell - HandsOn Reference Guide

1 Copyright 2011, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8

MySQL Group Replication. Bogdan Kecman MySQL Principal Technical Engineer

What's new in MySQL 5.5 and 5.6 replication

The Exciting MySQL 5.7 Replication Enhancements

Mix n Match Async and Group Replication for Advanced Replication Setups. Pedro Gomes Software Engineer

1Z Oracle. MySQL 5 Database Administrator Certified Professional Part I

Backup & Restore. Maximiliano Bubenick Sr Remote DBA

MySQL GTID Implementation, Maintenance, and Best Practices. Brian Cain (Dropbox) Gillian Gunson (GitHub) Mark Filipi (SurveyMonkey)

Setting up Multi-Source Replication in MariaDB 10.0

Using the MySQL Binary Log as a Change Stream

MySQL InnoDB Cluster. MySQL HA Made Easy! Miguel Araújo Senior Software Developer MySQL Middleware and Clients. FOSDEM 18 - February 04, 2018

Everything You Need to Know About MySQL Group Replication

MySQL Replication Update

Support for replication is built into MySQL. There are no special add-ins or applications to install.

MySQL HA Solutions Selecting the best approach to protect access to your data

3 / 120. MySQL 8.0. Frédéric Descamps - MySQL Community Manager - Oracle

Diagnosing Failures in MySQL Replication

MySQL Replication: Latest Developments

replic8 The Eighth Generation of MySQL Replication Sven Sandberg MySQL Replication Core Team Lead

mysql Sun Certified MySQL 5.0 Database(R) Administrator Part 1

Welcome to Virtual Developer Day MySQL!

MySQL Document Store. How to replace a NoSQL database by MySQL without effort but with a lot of gains?

MySQL Architecture Design Patterns for Performance, Scalability, and Availability

Setting Up Master-Master Replication With MySQL 5 On Debian Etch

MySQL Backup Best Practices and Case Study:.IE Continuous Restore Process

Quest NetVault Backup Plug-in for MySQL

Creating a Best-in-Class Backup and Recovery System for Your MySQL Environment. Akshay Suryawanshi DBA Team Manager,

MySQL Replication, the Community Sceptic Roundup. Giuseppe Maxia Quality Assurance Architect at

MySQL High Availability Solutions. Alex Poritskiy Percona

ProxySQL - GTID Consistent Reads. Adaptive query routing based on GTID tracking

What's new in MySQL 5.5? Performance/Scale Unleashed

MySQL Utilities, part 1. Sheeri Cabral. Senior DB Admin/Architect,

Riding the Binlog: an in Deep Dissection of the Replication Stream. Jean-François Gagné jeanfrancois DOT gagne AT booking.com

How to make MySQL work with Raft. Diancheng Wang & Guangchao Bai Staff Database Alibaba Cloud

How to get MySQL to fail

MySQL InnoDB Cluster & Group Replication in a Nutshell: Hands-On Tutorial

Backup Strategies with MySQL Enterprise Backup

MySQL 8.0: Atomic DDLs Implementation and Impact

2) One of the most common question clients asks is HOW the Replication works?

Effective Testing for Live Applications. March, 29, 2018 Sveta Smirnova

MySQL Test Framework for Troubleshooting. February, 04, 2018 Sveta Smirnova

Upgrading to MySQL 8.0+: a More Automated Upgrade Experience. Dmitry Lenev, Software Developer Oracle/MySQL, November 2018

How to set up and verify automated MySQL backups in 15 minutes

Copyright 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12

Dell NetVault Backup Plug-in for MySQL 4.4. User s Guide

Move Amazon RDS MySQL Databases to Amazon VPC using Amazon EC2 ClassicLink and Read Replicas

Manage MySQL like a devops sysadmin. Frédéric Descamps

Oracle 1Z MySQL 5.6 Database Administrator. Download Full Version :

Testing and Verifying your MySQL Backup Strategy

How To Repair MySQL Replication

What s New in MySQL 5.7 Geir Høydalsvik, Sr. Director, MySQL Engineering. Copyright 2015, Oracle and/or its affiliates. All rights reserved.

Percona Xtrabackup: Hot Backup Solution for MySQL

1z0-888.exam.43q.

How to recover a lost administrator password?

Oracle Multitenant What s new in Oracle Database 12c Release ?

mysql Certified MySQL 5.0 DBA Part I

The New Replication Features in MySQL 8. Luís Soares Principal Software Engineer, MySQL Replication Lead

MySQL Replication: What's New In MySQL 5.7 and MySQL 8. Luís Soares Software Development Director MySQL Replication

MySQL Replication Tips and Tricks

Python MySQL Replication Documentation

MyRocks in MariaDB. Sergei Petrunia MariaDB Tampere Meetup June 2018

Load Testing Tools. for Troubleshooting MySQL Concurrency Issues. May, 23, 2018 Sveta Smirnova

MySQL Replication : advanced features in all flavours. Giuseppe Maxia Quality Assurance Architect at

MySQL Enterprise Backup User's Guide (Version 4.1.2)

BERLIN. 2015, Amazon Web Services, Inc. or its affiliates. All rights reserved

Optimizing BOINC project databases

State of MySQL Group Replication

Bitnami MySQL for Huawei Enterprise Cloud

MySQL Enterprise Backup User's Guide (Version )

MySQL Enterprise Backup User's Guide (Version )

Sun Microsystems. MySQL Backup and Security Best practices on how to run MySQL on Linux in a secure way. Lenz Grimmer

Introduction To MySQL Replication. Kenny Gryp Percona Live Washington DC /

MySQL Enterprise Backup User's Guide (Version )

MySQL Enterprise Backup User's Guide (Version 4.1.0)

MySQL Enterprise Backup User's Guide (Version 4.1.1)

MySQL Cluster Web Scalability, % Availability. Andrew

Building Highly Available and Scalable Real- Time Services with MySQL Cluster

ZDLRA High Availability for Backup and Recovery

Bitnami MariaDB for Huawei Enterprise Cloud

State of the Dolphin Developing new Apps in MySQL 8

Copyright Heraflux Technologies. Do not redistribute or copy as your own. 1

Consolidate and Prepare for Cloud Efficiencies Oracle Database 12c Oracle Multitenant Option

SQL Server Administration on Linux 2017

MySQL Enterprise Backup User's Guide (Version )

Files

MySQL Enterprise Backup User's Guide (Version )

MySQL usage of web applications from 1 user to 100 million. Peter Boros RAMP conference 2013

Transcription:

1 / 51

2 / 51

3 / 51 MySQL Point-in-Time Recovery like a Rockstar Accelerate MySQL point-in-time recovery for large workloads FOSDEM, February 2018 Frédéric Descamps - MySQL Community Manager - Oracle

4 / 51 Safe Harbor Statement The following is intended to outline our general product direction. It is intended for information purpose only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied up in making purchasing decisions. The development, release and timing of any features or functionality described for Oracle s product remains at the sole discretion of Oracle.

5 / 51 about.me/lefred Who am I?

6 / 51 Frédéric Descamps @lefred MySQL Evangelist Hacking MySQL since 3.23 devops believer living in Belgium http://lefred.be

7 / 51 what is PITR? point-in-time recovery

8 / 51 PITR: Definition from Wikipedia (thank you Jaime) Point-in-time recovery (PITR) in the context of computers involves systems whereby an administrator can restore or recover a set of data or a particular setting from a time in the past. Once PITR logging starts for a PITR-capable database, a database administrator can restore that database from backups to the state that it had at any time since.

9 / 51 PITR: Definition from Wikipedia (thank you Jaime) Point-in-time recovery (PITR) in the context of computers involves systems whereby an administrator can restore or recover a set of data or a particular setting from a time in the past. Once PITR logging starts for a PITR-capable database, a database administrator can restore that database from backups to the state that it had at any time since. Please donate to wikimedia : https://goo.gl/zyvfhf

10 / 51 MySQL PITR requirements

11 / 51 Requirements To be able to perform point-in-time recovery with MySQL, you need to have:

12 / 51 Requirements To be able to perform point-in-time recovery with MySQL, you need to have: decent backups

13 / 51 Requirements To be able to perform point-in-time recovery with MySQL, you need to have: decent backups binary logs enabled

14 / 51 Requirements To be able to perform point-in-time recovery with MySQL, you need to have: decent backups binary logs enabled keeping your binlogs at least since the last successful backup

15 / 51 MySQL PITR Procedure

16 / 51 Procedure The procedure to perform a PITR with MySQL is the following:

17 / 51 Procedure The procedure to perform a PITR with MySQL is the following: find the binary log file and the position of the event you want restore up to

18 / 51 Procedure The procedure to perform a PITR with MySQL is the following: find the binary log file and the position of the event you want restore up to restore the last backup

19 / 51 Procedure The procedure to perform a PITR with MySQL is the following: find the binary log file and the position of the event you want restore up to restore the last backup find the binlog position of the last restored event

20 / 51 Procedure The procedure to perform a PITR with MySQL is the following: find the binary log file and the position of the event you want restore up to restore the last backup find the binlog position of the last restored event replay all events present in the binary logs since the backup up to the position of the transaction we want to skip

21 / 51 Procedure The procedure to perform a PITR with MySQL is the following: find the binary log file and the position of the event you want restore up to restore the last backup find the binlog position of the last restored event replay all events present in the binary logs since the backup up to the position of the transaction we want to skip see the manual: https://dev.mysql.com/doc/refman/5.7/en/point-in-time-recovery.html

22 / 51 MySQL PITR Example

23 / 51 Example We have one database with 16 tables sysbench /usr/share/sysbench/oltp_insert.lua --db-driver=mysql --mysql-user=root --mysql-host=localhost --table-size=100000 --tables=16 prepare

24 / 51 Example We have one database with 16 tables sysbench /usr/share/sysbench/oltp_insert.lua --db-driver=mysql --mysql-user=root --mysql-host=localhost --table-size=100000 --tables=16 prepare We have one physical backup /opt/mysql/meb-4.1/bin/mysqlbackup --host=127.0.0.1 --backup-dir=mysqlbackup backup /opt/mysql/meb-4.1/bin/mysqlbackup --host=127.0.0.1 --backup-dir=mysqlbackup apply-log

25 / 51 Example We have one database with 16 tables sysbench /usr/share/sysbench/oltp_insert.lua --db-driver=mysql --mysql-user=root --mysql-host=localhost --table-size=100000 --tables=16 prepare We have one physical backup /opt/mysql/meb-4.1/bin/mysqlbackup --host=127.0.0.1 --backup-dir=mysqlbackup backup /opt/mysql/meb-4.1/bin/mysqlbackup --host=127.0.0.1 --backup-dir=mysqlbackup apply-log Any other backup solution can be used

26 / 51 Example (2) We write data using 8 threads for 1h: sysbench /usr/share/sysbench/oltp_insert.lua --db-driver=mysql --mysql-user=root --mysql-host=localhost --table-size=100000 --tables=16 --threads=8 --report-interval=10 --time=3600 run

27 / 51 Example (2) We write data using 8 threads for 1h: sysbench /usr/share/sysbench/oltp_insert.lua --db-driver=mysql --mysql-user=root --mysql-host=localhost --table-size=100000 --tables=16 --threads=8 --report-interval=10 --time=3600 run And let's modify a record with something we can track ;-) mysql> update sbtest3 set pad='fred' where id = 126551; Query OK, 1 row affected (0.02 sec) Rows matched: 1 Changed: 1 Warnings: 0

28 / 51 Suddenly...

29 / 51 Suddenly...

30 / 51 Suddenly... mysql> update sbtest4 set pad="oups"; Query OK, 1066269 rows affected (8.52 sec) Rows matched: 1066269 Changed: 1066269 Warnings: 0

31 / 51 UPDATE without WHERE clause!?!

32 / 51 Find what we need to avoid after restore mysql> show master status; +------------------+-----------+...+------------------------------------------------+ File Position Executed_Gtid_Set +------------------+-----------+...+------------------------------------------------+ imac2-bin.000005 622915384 25d97ef9-005b-11e8-bf1b-685b359e77d5:1-1072032 +------------------+-----------+...+------------------------------------------------+ 1 row in set (0.00 sec)

33 / 51 Let's verify... mysql> pager grep -A 1 -B 2 'sbtest.sbtest4' grep -B 4 Update mysql> show binlog events in 'imac2-bin.000005'; -- imac2-bin.000005 277145452 Gtid... SET @@SESSION.GTID_NEXT= '25d97ef9-005b-11e8-bf1b-685b359e77d5:1072032' imac2-bin.000005 277145513 Query... BEGIN imac2-bin.000005 277145583 Table_map... table_id: 154 (sbtest.sbtest4) imac2-bin.000005 277145638 Update_rows... table_id: 154 mysql> pager sed -n -e '/25d97ef9-005b-11e8-bf1b-685b359e77d5:1072032/,/COMMIT/ p' grep COMMIT mysql> show binlog events in 'imac2-bin.000005'; imac2-bin.000005 622915357 Xid... 622915384 COMMIT /* xid=1072253 */ This is good, let's then keep the position 277145452

34 / 51 Stop MySQL and save the binlogs [root@imac2 ~]# systemctl stop mysqld [root@imac2 ~]# mkdir /mnt/mysql/binlogs [root@imac2 ~]# cd /var/lib/mysql [root@imac2 mysql]# cp imac2-bin.* /mnt/mysql/binlogs/

35 / 51 Stop MySQL and save the binlogs [root@imac2 ~]# systemctl stop mysqld [root@imac2 ~]# mkdir /mnt/mysql/binlogs [root@imac2 ~]# cd /var/lib/mysql [root@imac2 mysql]# cp imac2-bin.* /mnt/mysql/binlogs/ Restore the backup [root@imac2 mysql]# rm -rf * [root@imac2 mysql]# /opt/mysql/meb-4.1/bin/mysqlbackup --backup-dir=/tmp/mysqlbackup copy-back... mysqlbackup completed OK! with 3 warnings [root@imac2 mysql]# chown -R mysql. *

36 / 51 Point-in-Time Recovery Now we can start MySQL and replay the binlogs from the backup position, until the "EVENT" (277145452) # grep binlog_position backup_variables.txt binlog_position=imac2-bin.000004:888830919 [root@imac2 binlogs]# time mysqlbinlog -j 888830919 --stop-position 277145452 imac2-bin.00000[4-5] mysql real 305m18.867s I only needed to replay events from imac2-bin.00000[4-5] in fact, but it could be way more than that

37 / 51 Point-in-Time Recovery Now we can start MySQL and replay the binlogs from the backup position, until the "EVENT" (277145452) # grep binlog_position backup_variables.txt binlog_position=imac2-bin.000004:888830919 [root@imac2 binlogs]# time mysqlbinlog -j 888830919 --stop-position 277145452 imac2-bin.00000[4-5] mysql real 305m18.867s I only needed to replay events from imac2-bin.00000[4-5] in fact, but it could be way more than that -rw-r----- 1 root root 1.1G Jan 23 21:27 imac2-bin.000004 -rw-r----- 1 root root 595M Jan 23 21:27 imac2-bin.000005

38 / 51 Was it really like a rockstar?

39 / 51 Was it really like a rockstar? NO!

40 / 51 Why not? If you have a large amount of large binary logs and your workload is not single threaded like mysqlbinlog... this process can take for eveeeeeeeeer!

41 / 51 Let's do it like a rockstar!

42 / 51 Find and Set the last executed GTID during backup [root@imac2 mysql]# cat backup_variables.txt grep gtid gtid_executed=25d97ef9-005b-11e8-bf1b-685b359e77d5:1-6001 The name of the file depends of your backup tool After restoring the backup, restart MySQL with this change in my.cnf: skip-slave-start Finally set the GTID AND ALSO the GTID of the transaction we want to avoid: mysql> reset master; mysql> SET @@GLOBAL.GTID_PURGED='25d97ef9-005b-11e8-bf1b-685b359e77d5:1-6001, 25d97ef9-005b-11e8-bf1b-685b359e77d5:1072032';

43 / 51 MySQL PITR Now the cool stuff!

44 / 51 We will copy all the saved binlogs and rename them as relaylogs! [root@imac2 mysql]# for i in $(ls /mnt/mysql/binlogs/*.0*) do ext=$(echo $i cut -d'.' -f2) cp $i imac2-relay-bin.$ext done

45 / 51 We will copy all the saved binlogs and rename them as relaylogs! [root@imac2 mysql]# for i in $(ls /mnt/mysql/binlogs/*.0*) do ext=$(echo $i cut -d'.' -f2) cp $i imac2-relay-bin.$ext done Don't forget to create the index file too: [root@imac2 mysql]# ls./imac2-relay-bin.0* >imac2-relay-bin.index [root@imac2 mysql]# chown mysql. *relay* [root@imac2 mysql]# cat imac2-relay-bin.index./imac2-relay-bin.000001./imac2-relay-bin.000002./imac2-relay-bin.000003./imac2-relay-bin.000004./imac2-relay-bin.000005

46 / 51 Get ready to do PITR like a rockstar!

47 / 51 Get ready to do PITR like a rockstar! mysql> SET GLOBAL server_id = 99; #replicate-same-server-id=1 won't work because of #89375 mysql> SET GLOBAL SLAVE_PARALLEL_TYPE='LOGICAL_CLOCK'; mysql> SET GLOBAL SLAVE_PARALLEL_WORKERS=8; mysql> CHANGE MASTER TO RELAY_LOG_FILE='imac2-relay-bin.000001', RELAY_LOG_POS=4, MASTER_HOST='dummy'; mysql> START SLAVE SQL_THREAD;

48 / 51 Get ready to do PITR like a rockstar! mysql> SET GLOBAL server_id = 99; #replicate-same-server-id=1 won't work because of #89375 mysql> SET GLOBAL SLAVE_PARALLEL_TYPE='LOGICAL_CLOCK'; mysql> SET GLOBAL SLAVE_PARALLEL_WORKERS=8; mysql> CHANGE MASTER TO RELAY_LOG_FILE='imac2-relay-bin.000001', RELAY_LOG_POS=4, MASTER_HOST='dummy'; mysql> START SLAVE SQL_THREAD; And you can even monitor it: mysql> select * from performance_schema.replication_applier_status_by_worker\g mysql> show global variables like 'gtid_executed';

49 / 51 it took less than 22 mins!

50 / 51 if you are brave and want to go at light speed Try https://github.com/lefred/myundelete

51 / 51 Thank you! Any Questions? http://lefred.be