SlideShare uma empresa Scribd logo
1 de 23
Baixar para ler offline
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
1
MySQL Enterprise Backup:
PITR Partial Online Recovery
Keith Hollman
MySQL Principal Sales Consultant EMEA
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
3
Agenda
 Objectives for today.
 Backup and what to do.
 Restore procedures.
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
4
Objectives
 Backup Policy:
– Full Backup of the environment.
– Complemental Incremental backups & online BinLogs.
 Restore:
– Logical Restore.
– Online, Zero impact.
– Partial, single database, group of tables.
Backup & Restore
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
5
Backup
 A working environment, with 4 databases, of which 2 will require
restoration.
 Full backup with MySQL Enterprise Backup:
mysqlbackup --user=root --socket=/tmp/mysql.sock 
--backup-dir=/home/mysql/unit4/backup/ --with-timestamp backup
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
6
Backup
 Create 4 different databases, where the structure & content is the
same.
create database u4_1; use u4_1; create table `unit4` (`ID` int(7) NOT NULL
AUTO_INCREMENT, `Name` char(20) NOT NULL DEFAULT '‘, PRIMARY KEY (`ID`) )
ENGINE=InnoDB;
create database u4_2; use u4_2; create table `unit4` (...) ;
create database u4_3; use u4_3; create table `unit4` (...) ;
create database u4_4; use u4_4; create table `unit4` (...) ;
 Insert some rows in each of the “unit4” tables,
within each database:
call Unit4Insert (1000);
Test preparation
delimiter //
DROP PROCEDURE IF EXISTS Unit4Insert//
CREATE PROCEDURE Unit4Insert (p1 INT)
BEGIN
SET @x = 0;
REPEAT
INSERT INTO unit4 SELECT NULL, '1thousand';
SET @x = @x + 1;
UNTIL @x > p1 END REPEAT;
END
//
delimiter ;
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
7
Backup
 Then execute an incremental backup to safeguard the newly created
databases & objects and inserted rows.
mysqlbackup --user=root --socket=/tmp/mysql.sock 
--incremental-backup-dir=/home/mysql/unit4/backup_inc --with-timestamp 
--incremental --incremental_base=history:last_backup backup
Incremental
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
8
Recovery
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
9
Recovery
 We can:
1. convert the existing backup-dir to a single file backup and then extract it, or
2. go via the collection of tablespaces, locking and discarding as we go.
 Restore method also depends on whether:
1. tables have had rows deleted or modified (here we can use transportable
tablespaces)
2. if the object has been deleted, then we need to recreate it, from a
mysqldump extracted from a restored environment.
 In another separate environment or using a specific my.cnf.
2 Options for Logical Recovery.
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
10
Recovery
 Bring the full backup up to date with all InnoDB data:
mysqlbackup --backup-dir=/home/mysql/unit4/backup/2013-07-25_01-44-43/ apply-log
 Update the Full backup with the Incremental backup:
mysqlbackup --backup-dir=/home/mysql/unit4/backup/2013-07-25_01-44-43/ 
--incremental-backup-dir=/home/mysql/unit4/backup_inc/2013-07-25_17-20-18 
apply-incremental-backup
 And then get a single consolidated image file to work from:
mysqlbackup --backup-image=/home/mysql/unit4/backup/full_backup.mbi 
--backup-dir=/home/mysql/unit4/backup/2013-07-25_01-44-43 backup-dir-to-image
Preparing backups
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
11
Recovery
 Now let’s insert some rows, to reflect changes in the binlogs:
use u4_2
call Unit4Insert (1000);
select count(*) from unit4;
 And generate something to have to recover from:
delete from unit4 where id < 10;
select count(*) from unit4;
The Test
+----------+
| count(*) |
+----------+
| 2002 |
+----------+
+----------+
| count(*) |
+----------+
| 1993 |
+----------+
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
12
Recovery
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
13
The Recovery Scenario
 Objective:
– Restore the whole table with the logs applied, before the error.
– Online, without having to stop or impede access to the other users.
 So when did the error happen then? Let’s view the General_log:
vi ol63uek01.log
/delete from unit4
....
130729 13:16:29 2 Query delete from unit4 where id < 10
..
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
14
The Recovery Scenario
 What’s the backup history:
use mysql
select backup_id, start_time, end_time, binlog_pos, binlog_file, backup_type, backup_format,
backup_destination, exit_state from backup_history;
 Position =1654141 binlog = mysql-bin.000008
Backup status
+-------------------+---------------------+---------------------+------------+------------------+-------------+---------------
+---------------------------------------------------+------------+
| backup_id | start_time | end_time | binlog_pos | binlog_file | backup_type | backup_format
| backup_destination | exit_state |
+-------------------+---------------------+---------------------+------------+------------------+-------------+---------------
+---------------------------------------------------+------------+
| 13747094837220932 | 2013-07-25 01:44:43 | 2013-07-25 01:45:26 | 829045 | mysql-bin.000008 | FULL | DIRECTORY
| /home/mysql/unit4/backup/2013-07-25_01-44-43 | SUCCESS |
| 13747656186636058 | 2013-07-25 17:20:18 | 2013-07-25 17:20:46 | 1654141 | mysql-bin.000008 | INCREMENTAL | DIRECTORY
| /home/mysql/unit4/backup_inc/2013-07-25_17-20-18 | SUCCESS |
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
15
The Recovery Scenario
 To list single-file image contents:
mysqlbackup --backup-image=/home/mysql/unit4/backup/full_backup.mbi list-image
 Now we know where the 2 databases are, u4_2 & u4_4, extract them:
mysqlbackup --backup-image=/home/mysql/unit4/backup/full_backup.mbi 
--src-entry=datadir/u4_2 --dst-entry=/home/mysql/unit4/reco/u4_2 extract
mysqlbackup --backup-image=/home/mysql/unit4/backup/full_backup.mbi 
--src-entry=datadir/u4_4 --dst-entry=/home/mysql/unit4/reco/u4_4 extract
List contents & Extract
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
16
The Recovery Scenario
 We also know which binlog to start reading from, and from what
position, in order to gather all changes after the Incremental backup
and just before the "delete" occurred.
 Also, as there is more than 1 binlog, we pass the list on a single line:
mysqlbinlog --start-position=1654141 --stop-datetime="2013-07-29 13:16:28"
/binlogs/mysql-bin.000008 /binlogs/mysql-bin.000009 --base64-output=decode-rows
--verbose --database=u4_2 > recover_1654141_20130729131628.sql
 with this file, recover_1654141_20130729131628.sql, we can see the sql
commands COMMENTED OUT, i.e. any execution of this file will not
restore anything.
Next steps
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
17
The Recovery Scenario
 Now discard the original tables, and replace with the recovered ones
from the Full+INC image result set:
 Generate the ‘lock’ and ‘discard’ sql syntax:
select 'use u4_2' db, concat_ws(' ','lock tables',table_name,'write;') 'lock',
concat_ws(' ','alter table',table_name,'discard tablespace;') 'discard' from
tables where table_schema = 'u4_2';
select 'use u4_4' db, concat_ws(' ','lock tables',table_name,'write;') 'lock',
concat_ws(' ','alter table',table_name,'discard tablespace;') 'discard' from
tables where table_schema = 'u4_4';
use u4_2; lock tables unit4 write; alter table unit4 discard tablespace;
use u4_4; lock tables unit4 write; alter table unit4 discard tablespace;
Transportable tablespaces.
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
18
The Recovery Scenario
 Copy the recovered .ibd files from the single file backup image:
cd /opt/mysql/mysql/data/u4_2
cp ~/unit4/reco/u4_2/*.ibd .
 Import the tablespaces:
select concat_ws(' ','alter table',table_name,'import tablespace;') 'import' from
tables where table_schema = 'u4_2';
alter table unit4 import tablespace;
 Unlock the tables (execute only once for all tables):
unlock tables;
Transportable tablespaces continued.
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
19
The Recovery Scenario
 Time to apply the data extracted from the binlogs, after the incremental
backup:
mysqlbinlog --start-position=1654141 --stop-datetime="2013-07-29 13:16:28" 
/binlogs/mysql-bin.000008 /binlogs/mysql-bin.000009 --verbose --database=u4_2 
| mysql –uroot
 Confirm that we have restored the table with all its rows:
mysql> select count(*) from u4_2.unit4;
Transportable tablespaces continued.
+----------+
| count(*) |
+----------+
| 2002 |
+----------+
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
20
Other details
 Just some further details of the procedure and impact of restoring, at a
space requirement level:
/opt/mysql/mysql/data 546996 Kb
/home/mysql/unit4 1461780 Kb
- 1 full backup (uncompressed) 538984 Kb
- 1 incremental backup 383412 Kb
- 1 Full+INC single file image 538450 Kb
- Recovered db's (u4_2+u4_4) 328 Kb
- recover sql w/ comments script 576 Kb
- meta & datadir dir's 8 Kb
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
21
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
22
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
23

Mais conteúdo relacionado

Mais procurados

MySQL enterprise backup overview
MySQL enterprise backup overviewMySQL enterprise backup overview
MySQL enterprise backup overview
郁萍 王
 
Less17 flashback tb3
Less17 flashback tb3Less17 flashback tb3
Less17 flashback tb3
Imran Ali
 
Yahoo Cloud Serving Benchmark
Yahoo Cloud Serving BenchmarkYahoo Cloud Serving Benchmark
Yahoo Cloud Serving Benchmark
kevin han
 

Mais procurados (20)

Percona Live 2022 - The Evolution of a MySQL Database System
Percona Live 2022 - The Evolution of a MySQL Database SystemPercona Live 2022 - The Evolution of a MySQL Database System
Percona Live 2022 - The Evolution of a MySQL Database System
 
Play with FILE Structure - Yet Another Binary Exploit Technique
Play with FILE Structure - Yet Another Binary Exploit TechniquePlay with FILE Structure - Yet Another Binary Exploit Technique
Play with FILE Structure - Yet Another Binary Exploit Technique
 
MySQL enterprise backup overview
MySQL enterprise backup overviewMySQL enterprise backup overview
MySQL enterprise backup overview
 
Dispersión y tablas hash
Dispersión y tablas hashDispersión y tablas hash
Dispersión y tablas hash
 
Percona xtrabackup - MySQL Meetup @ Mumbai
Percona xtrabackup - MySQL Meetup @ MumbaiPercona xtrabackup - MySQL Meetup @ Mumbai
Percona xtrabackup - MySQL Meetup @ Mumbai
 
Less17 flashback tb3
Less17 flashback tb3Less17 flashback tb3
Less17 flashback tb3
 
Oracle Drivers configuration for High Availability, is it a developer's job?
Oracle Drivers configuration for High Availability, is it a developer's job?Oracle Drivers configuration for High Availability, is it a developer's job?
Oracle Drivers configuration for High Availability, is it a developer's job?
 
HFile: A Block-Indexed File Format to Store Sorted Key-Value Pairs
HFile: A Block-Indexed File Format to Store Sorted Key-Value PairsHFile: A Block-Indexed File Format to Store Sorted Key-Value Pairs
HFile: A Block-Indexed File Format to Store Sorted Key-Value Pairs
 
Oracle data guard for beginners
Oracle data guard for beginnersOracle data guard for beginners
Oracle data guard for beginners
 
What to Expect From Oracle database 19c
What to Expect From Oracle database 19cWhat to Expect From Oracle database 19c
What to Expect From Oracle database 19c
 
Understanding SQL Server 2016 Always Encrypted
Understanding SQL Server 2016 Always EncryptedUnderstanding SQL Server 2016 Always Encrypted
Understanding SQL Server 2016 Always Encrypted
 
Redis on NVMe SSD - Zvika Guz, Samsung
 Redis on NVMe SSD - Zvika Guz, Samsung Redis on NVMe SSD - Zvika Guz, Samsung
Redis on NVMe SSD - Zvika Guz, Samsung
 
MySQL Security
MySQL SecurityMySQL Security
MySQL Security
 
Log Structured Merge Tree
Log Structured Merge TreeLog Structured Merge Tree
Log Structured Merge Tree
 
The e820 trap of Linux kernel hibernation
The e820 trap of Linux kernel hibernationThe e820 trap of Linux kernel hibernation
The e820 trap of Linux kernel hibernation
 
Percona Xtrabackup - Highly Efficient Backups
Percona Xtrabackup - Highly Efficient BackupsPercona Xtrabackup - Highly Efficient Backups
Percona Xtrabackup - Highly Efficient Backups
 
MySQL Enterprise Backup - BnR Scenarios
MySQL Enterprise Backup - BnR ScenariosMySQL Enterprise Backup - BnR Scenarios
MySQL Enterprise Backup - BnR Scenarios
 
Yahoo Cloud Serving Benchmark
Yahoo Cloud Serving BenchmarkYahoo Cloud Serving Benchmark
Yahoo Cloud Serving Benchmark
 
Introduction to Cassandra Basics
Introduction to Cassandra BasicsIntroduction to Cassandra Basics
Introduction to Cassandra Basics
 
Memory Mapping Implementation (mmap) in Linux Kernel
Memory Mapping Implementation (mmap) in Linux KernelMemory Mapping Implementation (mmap) in Linux Kernel
Memory Mapping Implementation (mmap) in Linux Kernel
 

Destaque

Anthony conner media
Anthony conner mediaAnthony conner media
Anthony conner media
shynedatruth1
 

Destaque (6)

Meb Backup & Recovery Performance
Meb Backup & Recovery PerformanceMeb Backup & Recovery Performance
Meb Backup & Recovery Performance
 
Anthony conner media
Anthony conner mediaAnthony conner media
Anthony conner media
 
Embracing Database Diversity: The New Oracle / MySQL DBA - UKOUG
Embracing Database Diversity: The New Oracle / MySQL DBA -   UKOUGEmbracing Database Diversity: The New Oracle / MySQL DBA -   UKOUG
Embracing Database Diversity: The New Oracle / MySQL DBA - UKOUG
 
MySQL Replication: Demo Réplica en Español
MySQL Replication: Demo Réplica en EspañolMySQL Replication: Demo Réplica en Español
MySQL Replication: Demo Réplica en Español
 
MySQL Enterprise Backup
MySQL Enterprise BackupMySQL Enterprise Backup
MySQL Enterprise Backup
 
MySQL Cluster: El ‘qué’ y el ‘cómo’.
MySQL Cluster: El ‘qué’ y el ‘cómo’.MySQL Cluster: El ‘qué’ y el ‘cómo’.
MySQL Cluster: El ‘qué’ y el ‘cómo’.
 

Semelhante a MySQL Enterprise Backup: PITR Partial Online Recovery

MySQL Enterprise Backup & Oracle Secure Backup
MySQL Enterprise Backup &  Oracle Secure BackupMySQL Enterprise Backup &  Oracle Secure Backup
MySQL Enterprise Backup & Oracle Secure Backup
Sanjay Manwani
 

Semelhante a MySQL Enterprise Backup: PITR Partial Online Recovery (20)

Making Backups in Extreme Situations
Making Backups in Extreme SituationsMaking Backups in Extreme Situations
Making Backups in Extreme Situations
 
Oracle backup
Oracle backupOracle backup
Oracle backup
 
Oracle Database Backup
Oracle Database BackupOracle Database Backup
Oracle Database Backup
 
Xpp c user_rec
Xpp c user_recXpp c user_rec
Xpp c user_rec
 
FOSDEM 2022 MySQL Devroom: MySQL 8.0 - Logical Backups, Snapshots and Point-...
FOSDEM 2022 MySQL Devroom:  MySQL 8.0 - Logical Backups, Snapshots and Point-...FOSDEM 2022 MySQL Devroom:  MySQL 8.0 - Logical Backups, Snapshots and Point-...
FOSDEM 2022 MySQL Devroom: MySQL 8.0 - Logical Backups, Snapshots and Point-...
 
Les 02 config
Les 02 configLes 02 config
Les 02 config
 
Les 07 rman_rec
Les 07 rman_recLes 07 rman_rec
Les 07 rman_rec
 
Les 05 create_bu
Les 05 create_buLes 05 create_bu
Les 05 create_bu
 
FOSDEM MySQL & Friends Devroom, February 2018 MySQL Point-in-Time Recovery l...
FOSDEM MySQL & Friends Devroom, February 2018  MySQL Point-in-Time Recovery l...FOSDEM MySQL & Friends Devroom, February 2018  MySQL Point-in-Time Recovery l...
FOSDEM MySQL & Friends Devroom, February 2018 MySQL Point-in-Time Recovery l...
 
Backup&recovery
Backup&recoveryBackup&recovery
Backup&recovery
 
Backups And Recovery
Backups And RecoveryBackups And Recovery
Backups And Recovery
 
MySQL Enterprise Backup & Oracle Secure Backup
MySQL Enterprise Backup &  Oracle Secure BackupMySQL Enterprise Backup &  Oracle Secure Backup
MySQL Enterprise Backup & Oracle Secure Backup
 
Power point oracle db 12c
Power point oracle db 12cPower point oracle db 12c
Power point oracle db 12c
 
MySQL Backup & Recovery
MySQL Backup & RecoveryMySQL Backup & Recovery
MySQL Backup & Recovery
 
MySQL Enterprise Backup (MEB)
MySQL Enterprise Backup (MEB)MySQL Enterprise Backup (MEB)
MySQL Enterprise Backup (MEB)
 
Training Slides: 203 - Backup & Recovery
Training Slides: 203 - Backup & RecoveryTraining Slides: 203 - Backup & Recovery
Training Slides: 203 - Backup & Recovery
 
Rman workshop short
Rman workshop shortRman workshop short
Rman workshop short
 
ODA Backup Restore Utility & ODA Rescue Live Disk
ODA Backup Restore Utility & ODA Rescue Live DiskODA Backup Restore Utility & ODA Rescue Live Disk
ODA Backup Restore Utility & ODA Rescue Live Disk
 
MySQL for Oracle DBAs
MySQL for Oracle DBAsMySQL for Oracle DBAs
MySQL for Oracle DBAs
 
Les 06 rec
Les 06 recLes 06 rec
Les 06 rec
 

Mais de Keith Hollman

Mais de Keith Hollman (9)

Moodle Moot Spain: Moodle Available and Scalable with MySQL HA - InnoDB Clust...
Moodle Moot Spain: Moodle Available and Scalable with MySQL HA - InnoDB Clust...Moodle Moot Spain: Moodle Available and Scalable with MySQL HA - InnoDB Clust...
Moodle Moot Spain: Moodle Available and Scalable with MySQL HA - InnoDB Clust...
 
MySQL InnoDB Cluster HA Overview & Demo
MySQL InnoDB Cluster HA Overview & DemoMySQL InnoDB Cluster HA Overview & Demo
MySQL InnoDB Cluster HA Overview & Demo
 
MySQL Technology Overview
MySQL Technology OverviewMySQL Technology Overview
MySQL Technology Overview
 
MySQL 8.0 Released Update
MySQL 8.0 Released UpdateMySQL 8.0 Released Update
MySQL 8.0 Released Update
 
MySQL Enterprise Edition - Complete Guide (2019)
MySQL Enterprise Edition - Complete Guide (2019)MySQL Enterprise Edition - Complete Guide (2019)
MySQL Enterprise Edition - Complete Guide (2019)
 
MySQL 8.0 InnoDB Cluster demo
MySQL 8.0 InnoDB Cluster demoMySQL 8.0 InnoDB Cluster demo
MySQL 8.0 InnoDB Cluster demo
 
MySQL NoSQL JSON JS Python "Document Store" demo
MySQL NoSQL JSON JS Python "Document Store" demoMySQL NoSQL JSON JS Python "Document Store" demo
MySQL NoSQL JSON JS Python "Document Store" demo
 
MySQL Una Introduccion Tecnica
MySQL Una Introduccion TecnicaMySQL Una Introduccion Tecnica
MySQL Una Introduccion Tecnica
 
A MySQL Odyssey - A Blackhole Crossover
A MySQL Odyssey - A Blackhole CrossoverA MySQL Odyssey - A Blackhole Crossover
A MySQL Odyssey - A Blackhole Crossover
 

Último

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Último (20)

Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 

MySQL Enterprise Backup: PITR Partial Online Recovery

  • 1. Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 1
  • 2. MySQL Enterprise Backup: PITR Partial Online Recovery Keith Hollman MySQL Principal Sales Consultant EMEA
  • 3. Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 3 Agenda  Objectives for today.  Backup and what to do.  Restore procedures.
  • 4. Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 4 Objectives  Backup Policy: – Full Backup of the environment. – Complemental Incremental backups & online BinLogs.  Restore: – Logical Restore. – Online, Zero impact. – Partial, single database, group of tables. Backup & Restore
  • 5. Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 5 Backup  A working environment, with 4 databases, of which 2 will require restoration.  Full backup with MySQL Enterprise Backup: mysqlbackup --user=root --socket=/tmp/mysql.sock --backup-dir=/home/mysql/unit4/backup/ --with-timestamp backup
  • 6. Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 6 Backup  Create 4 different databases, where the structure & content is the same. create database u4_1; use u4_1; create table `unit4` (`ID` int(7) NOT NULL AUTO_INCREMENT, `Name` char(20) NOT NULL DEFAULT '‘, PRIMARY KEY (`ID`) ) ENGINE=InnoDB; create database u4_2; use u4_2; create table `unit4` (...) ; create database u4_3; use u4_3; create table `unit4` (...) ; create database u4_4; use u4_4; create table `unit4` (...) ;  Insert some rows in each of the “unit4” tables, within each database: call Unit4Insert (1000); Test preparation delimiter // DROP PROCEDURE IF EXISTS Unit4Insert// CREATE PROCEDURE Unit4Insert (p1 INT) BEGIN SET @x = 0; REPEAT INSERT INTO unit4 SELECT NULL, '1thousand'; SET @x = @x + 1; UNTIL @x > p1 END REPEAT; END // delimiter ;
  • 7. Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 7 Backup  Then execute an incremental backup to safeguard the newly created databases & objects and inserted rows. mysqlbackup --user=root --socket=/tmp/mysql.sock --incremental-backup-dir=/home/mysql/unit4/backup_inc --with-timestamp --incremental --incremental_base=history:last_backup backup Incremental
  • 8. Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 8 Recovery
  • 9. Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 9 Recovery  We can: 1. convert the existing backup-dir to a single file backup and then extract it, or 2. go via the collection of tablespaces, locking and discarding as we go.  Restore method also depends on whether: 1. tables have had rows deleted or modified (here we can use transportable tablespaces) 2. if the object has been deleted, then we need to recreate it, from a mysqldump extracted from a restored environment.  In another separate environment or using a specific my.cnf. 2 Options for Logical Recovery.
  • 10. Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 10 Recovery  Bring the full backup up to date with all InnoDB data: mysqlbackup --backup-dir=/home/mysql/unit4/backup/2013-07-25_01-44-43/ apply-log  Update the Full backup with the Incremental backup: mysqlbackup --backup-dir=/home/mysql/unit4/backup/2013-07-25_01-44-43/ --incremental-backup-dir=/home/mysql/unit4/backup_inc/2013-07-25_17-20-18 apply-incremental-backup  And then get a single consolidated image file to work from: mysqlbackup --backup-image=/home/mysql/unit4/backup/full_backup.mbi --backup-dir=/home/mysql/unit4/backup/2013-07-25_01-44-43 backup-dir-to-image Preparing backups
  • 11. Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 11 Recovery  Now let’s insert some rows, to reflect changes in the binlogs: use u4_2 call Unit4Insert (1000); select count(*) from unit4;  And generate something to have to recover from: delete from unit4 where id < 10; select count(*) from unit4; The Test +----------+ | count(*) | +----------+ | 2002 | +----------+ +----------+ | count(*) | +----------+ | 1993 | +----------+
  • 12. Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 12 Recovery
  • 13. Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 13 The Recovery Scenario  Objective: – Restore the whole table with the logs applied, before the error. – Online, without having to stop or impede access to the other users.  So when did the error happen then? Let’s view the General_log: vi ol63uek01.log /delete from unit4 .... 130729 13:16:29 2 Query delete from unit4 where id < 10 ..
  • 14. Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 14 The Recovery Scenario  What’s the backup history: use mysql select backup_id, start_time, end_time, binlog_pos, binlog_file, backup_type, backup_format, backup_destination, exit_state from backup_history;  Position =1654141 binlog = mysql-bin.000008 Backup status +-------------------+---------------------+---------------------+------------+------------------+-------------+--------------- +---------------------------------------------------+------------+ | backup_id | start_time | end_time | binlog_pos | binlog_file | backup_type | backup_format | backup_destination | exit_state | +-------------------+---------------------+---------------------+------------+------------------+-------------+--------------- +---------------------------------------------------+------------+ | 13747094837220932 | 2013-07-25 01:44:43 | 2013-07-25 01:45:26 | 829045 | mysql-bin.000008 | FULL | DIRECTORY | /home/mysql/unit4/backup/2013-07-25_01-44-43 | SUCCESS | | 13747656186636058 | 2013-07-25 17:20:18 | 2013-07-25 17:20:46 | 1654141 | mysql-bin.000008 | INCREMENTAL | DIRECTORY | /home/mysql/unit4/backup_inc/2013-07-25_17-20-18 | SUCCESS |
  • 15. Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 15 The Recovery Scenario  To list single-file image contents: mysqlbackup --backup-image=/home/mysql/unit4/backup/full_backup.mbi list-image  Now we know where the 2 databases are, u4_2 & u4_4, extract them: mysqlbackup --backup-image=/home/mysql/unit4/backup/full_backup.mbi --src-entry=datadir/u4_2 --dst-entry=/home/mysql/unit4/reco/u4_2 extract mysqlbackup --backup-image=/home/mysql/unit4/backup/full_backup.mbi --src-entry=datadir/u4_4 --dst-entry=/home/mysql/unit4/reco/u4_4 extract List contents & Extract
  • 16. Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 16 The Recovery Scenario  We also know which binlog to start reading from, and from what position, in order to gather all changes after the Incremental backup and just before the "delete" occurred.  Also, as there is more than 1 binlog, we pass the list on a single line: mysqlbinlog --start-position=1654141 --stop-datetime="2013-07-29 13:16:28" /binlogs/mysql-bin.000008 /binlogs/mysql-bin.000009 --base64-output=decode-rows --verbose --database=u4_2 > recover_1654141_20130729131628.sql  with this file, recover_1654141_20130729131628.sql, we can see the sql commands COMMENTED OUT, i.e. any execution of this file will not restore anything. Next steps
  • 17. Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 17 The Recovery Scenario  Now discard the original tables, and replace with the recovered ones from the Full+INC image result set:  Generate the ‘lock’ and ‘discard’ sql syntax: select 'use u4_2' db, concat_ws(' ','lock tables',table_name,'write;') 'lock', concat_ws(' ','alter table',table_name,'discard tablespace;') 'discard' from tables where table_schema = 'u4_2'; select 'use u4_4' db, concat_ws(' ','lock tables',table_name,'write;') 'lock', concat_ws(' ','alter table',table_name,'discard tablespace;') 'discard' from tables where table_schema = 'u4_4'; use u4_2; lock tables unit4 write; alter table unit4 discard tablespace; use u4_4; lock tables unit4 write; alter table unit4 discard tablespace; Transportable tablespaces.
  • 18. Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 18 The Recovery Scenario  Copy the recovered .ibd files from the single file backup image: cd /opt/mysql/mysql/data/u4_2 cp ~/unit4/reco/u4_2/*.ibd .  Import the tablespaces: select concat_ws(' ','alter table',table_name,'import tablespace;') 'import' from tables where table_schema = 'u4_2'; alter table unit4 import tablespace;  Unlock the tables (execute only once for all tables): unlock tables; Transportable tablespaces continued.
  • 19. Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 19 The Recovery Scenario  Time to apply the data extracted from the binlogs, after the incremental backup: mysqlbinlog --start-position=1654141 --stop-datetime="2013-07-29 13:16:28" /binlogs/mysql-bin.000008 /binlogs/mysql-bin.000009 --verbose --database=u4_2 | mysql –uroot  Confirm that we have restored the table with all its rows: mysql> select count(*) from u4_2.unit4; Transportable tablespaces continued. +----------+ | count(*) | +----------+ | 2002 | +----------+
  • 20. Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 20 Other details  Just some further details of the procedure and impact of restoring, at a space requirement level: /opt/mysql/mysql/data 546996 Kb /home/mysql/unit4 1461780 Kb - 1 full backup (uncompressed) 538984 Kb - 1 incremental backup 383412 Kb - 1 Full+INC single file image 538450 Kb - Recovered db's (u4_2+u4_4) 328 Kb - recover sql w/ comments script 576 Kb - meta & datadir dir's 8 Kb
  • 21. Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 21
  • 22. Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 22
  • 23. Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 23