Top Banner
Creating a Best-in-Class Backup and Recovery System for Your MySQL Environment Akshay Suryawanshi DBA Team Manager, 2015-07-15
45

Creating a Best-in-Class Backup and Recovery …...2015/07/15  · Logical Backups Mydumper Faster logical backups as is multithread Almost no locking with innodb tables Compress on

Jul 18, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Creating a Best-in-Class Backup and Recovery …...2015/07/15  · Logical Backups Mydumper Faster logical backups as is multithread Almost no locking with innodb tables Compress on

Creating a Best-in-Class Backup and Recovery System for Your MySQL Environment

Akshay Suryawanshi DBA Team Manager,

2015-07-15

Page 2: Creating a Best-in-Class Backup and Recovery …...2015/07/15  · Logical Backups Mydumper Faster logical backups as is multithread Almost no locking with innodb tables Compress on

www.percona.com

Agenda

● Why backups?

● Backup Types

● Binary or Raw Backups

● Logical Backups

● Binlog mirroring

● Backups Locks

● Examples

● Tips

Page 3: Creating a Best-in-Class Backup and Recovery …...2015/07/15  · Logical Backups Mydumper Faster logical backups as is multithread Almost no locking with innodb tables Compress on

Why Backups?

Page 4: Creating a Best-in-Class Backup and Recovery …...2015/07/15  · Logical Backups Mydumper Faster logical backups as is multithread Almost no locking with innodb tables Compress on

www.percona.com

Why Backups?

● At some point anything can and will fail● Hardware issues● Application bugs● Operational mistakes● Attacks

Page 5: Creating a Best-in-Class Backup and Recovery …...2015/07/15  · Logical Backups Mydumper Faster logical backups as is multithread Almost no locking with innodb tables Compress on

www.percona.com

Why Backups?

● Depending on the fail you will need to:

● Restore a complete server

● Restore a complete DB

● A complete table

● A few rows

Page 6: Creating a Best-in-Class Backup and Recovery …...2015/07/15  · Logical Backups Mydumper Faster logical backups as is multithread Almost no locking with innodb tables Compress on

Backup types

Page 7: Creating a Best-in-Class Backup and Recovery …...2015/07/15  · Logical Backups Mydumper Faster logical backups as is multithread Almost no locking with innodb tables Compress on

www.percona.com

Different Backup types

● Logical

● Plain text files

● Can be Remote

● Slower on large datasets

● Sometimes the only option

Page 8: Creating a Best-in-Class Backup and Recovery …...2015/07/15  · Logical Backups Mydumper Faster logical backups as is multithread Almost no locking with innodb tables Compress on

www.percona.com

Different Backup types

● Binary or Raw

● Filesystem level access

● Local

● Faster on large datasets

● Storage engine dependent

● Can be useless on filesystem corruption

Page 9: Creating a Best-in-Class Backup and Recovery …...2015/07/15  · Logical Backups Mydumper Faster logical backups as is multithread Almost no locking with innodb tables Compress on

www.percona.com

Different Backup types

● Binlog

● For point in time recovery

● PITR even for a single schema

Page 10: Creating a Best-in-Class Backup and Recovery …...2015/07/15  · Logical Backups Mydumper Faster logical backups as is multithread Almost no locking with innodb tables Compress on

Binary Backups

Page 11: Creating a Best-in-Class Backup and Recovery …...2015/07/15  · Logical Backups Mydumper Faster logical backups as is multithread Almost no locking with innodb tables Compress on

www.percona.com

Binary Backups

● Tools

● Percona XtraBackup

● mylvmsnapshot

● MySQL Enterprise Backup

Page 12: Creating a Best-in-Class Backup and Recovery …...2015/07/15  · Logical Backups Mydumper Faster logical backups as is multithread Almost no locking with innodb tables Compress on

www.percona.com

Binary Backups

● Percona XtraBackup

● Fast, limited by IO

● Almost no locks (--rsync)

● Compress on the fly (--compress)

● Best option for full server restore or setting up newslaves

Page 13: Creating a Best-in-Class Backup and Recovery …...2015/07/15  · Logical Backups Mydumper Faster logical backups as is multithread Almost no locking with innodb tables Compress on

Logical Backups

Page 14: Creating a Best-in-Class Backup and Recovery …...2015/07/15  · Logical Backups Mydumper Faster logical backups as is multithread Almost no locking with innodb tables Compress on

www.percona.com

Logical Backups

● Tools

● mysqldump

● Mydumper

Page 15: Creating a Best-in-Class Backup and Recovery …...2015/07/15  · Logical Backups Mydumper Faster logical backups as is multithread Almost no locking with innodb tables Compress on

www.percona.com

Logical Backups

● mysqldump

● General use

● Simple to use

● By default lock tables

● One big output file

● Can be piped to mysql client

Page 16: Creating a Best-in-Class Backup and Recovery …...2015/07/15  · Logical Backups Mydumper Faster logical backups as is multithread Almost no locking with innodb tables Compress on

www.percona.com

Logical Backups

● mysqldump

● --opt = --add-drop-table --add-locks --create-options--quick --extended-insert --lock-tables --set-charset–disable-keys (default)

● --single-transaction (innodb)

● --master-data (FTWRL) for binlog coordinates

● --dump-slave

● --innodb-optimize-keys (PS only feature)

● --triggers (ON) --routines (OFF)

Page 17: Creating a Best-in-Class Backup and Recovery …...2015/07/15  · Logical Backups Mydumper Faster logical backups as is multithread Almost no locking with innodb tables Compress on

www.percona.com

Logical Backups

● Mydumper

● Faster logical backups as is multithread

● Almost no locking with innodb tables

● Compress on the fly

● Doesn't handle Views, Triggers and Procedures

● Separate files per table, one row per line

Page 18: Creating a Best-in-Class Backup and Recovery …...2015/07/15  · Logical Backups Mydumper Faster logical backups as is multithread Almost no locking with innodb tables Compress on

www.percona.com

Logical Backups

● Mydumper

● --threads

● --outputdir

● --rows, --chunk-filesize

● --compress

● --less-locking

● --kill-long-queries

● --use-savepoints

Page 19: Creating a Best-in-Class Backup and Recovery …...2015/07/15  · Logical Backups Mydumper Faster logical backups as is multithread Almost no locking with innodb tables Compress on

www.percona.com

Logical Backups

● Without chunks

Thread 1 Thread 2 Thread 3 Thread 4

0

10

20

30

40

50

60

Table D

Table C

Table B

Table A

Tim

e

Page 20: Creating a Best-in-Class Backup and Recovery …...2015/07/15  · Logical Backups Mydumper Faster logical backups as is multithread Almost no locking with innodb tables Compress on

www.percona.com

Logical Backups

● With chunks (--rows)

Thread 1 Thread 2 Thread 3 Thread 4

0

5

10

15

20

25

Table D

Table C

Table B

Table A

Tim

e

Page 21: Creating a Best-in-Class Backup and Recovery …...2015/07/15  · Logical Backups Mydumper Faster logical backups as is multithread Almost no locking with innodb tables Compress on

www.percona.com

Logical Backups

● Less-locking, without it Mydumper needs tokeep FTWRL until all non-Innodb tables aredumped

Thread 1 Thread 2 Thread 3 Thread 4

0

2

4

6

8

10

12

14

Innodb

non-InnoDBTim

e

Page 22: Creating a Best-in-Class Backup and Recovery …...2015/07/15  · Logical Backups Mydumper Faster logical backups as is multithread Almost no locking with innodb tables Compress on

www.percona.com

Logical Backups

● Mydumper output files

● metadataStarted dump at: 2014-04-18 22:01:30

SHOW MASTER STATUS:

Log: mysql-bin.017436

Pos: 890402821

SHOW SLAVE STATUS:

Host: 192.168.56.101

Log: mysql-bin.017057

Pos: 968001054

Finished dump at: 2014-04-19 03:10:05

Page 23: Creating a Best-in-Class Backup and Recovery …...2015/07/15  · Logical Backups Mydumper Faster logical backups as is multithread Almost no locking with innodb tables Compress on

www.percona.com

Logical Backups

● Mydumper output files

● database.table.sql/*!40101 SET NAMES binary*/;

/*!40014 SET FOREIGN_KEY_CHECKS=0*/;

/*!40103 SET TIME_ZONE='+00:00' */;

INSERT INTO `t1` VALUES

(1,"abc"),

(2,"def"),

(4,"abc"),

(5,"abc"),

(6,"abc"),

(7,"abc"),

(8,"abc");

Page 24: Creating a Best-in-Class Backup and Recovery …...2015/07/15  · Logical Backups Mydumper Faster logical backups as is multithread Almost no locking with innodb tables Compress on

Binlog Mirroring

Page 25: Creating a Best-in-Class Backup and Recovery …...2015/07/15  · Logical Backups Mydumper Faster logical backups as is multithread Almost no locking with innodb tables Compress on

www.percona.com

Binlog Mirroring

● Mysqlbinlog (5.6)

● Works with 5.1 and 5.5 master also

● Mirror binlogs on the master on a second server

● mysqlbinlog --read-from-remote-server --raw --stop-never

Page 26: Creating a Best-in-Class Backup and Recovery …...2015/07/15  · Logical Backups Mydumper Faster logical backups as is multithread Almost no locking with innodb tables Compress on

Backup Locks

Page 27: Creating a Best-in-Class Backup and Recovery …...2015/07/15  · Logical Backups Mydumper Faster logical backups as is multithread Almost no locking with innodb tables Compress on

www.percona.com

Backup Locks

● LOCK TABLE ... READ LOCAL● Other sessions can read the table but can't write

● LOCAL allows non conflicting INSERTs to MyISAM

● FLUSH TABLES WITH READ LOCK● Global read lock

● Big issue on busy servers and long running selects

● Requires tables be reopened which can be another bottleneck on busyservers

● metadata locking since 5.5● No DDLs to tables used in a transaction

Page 28: Creating a Best-in-Class Backup and Recovery …...2015/07/15  · Logical Backups Mydumper Faster logical backups as is multithread Almost no locking with innodb tables Compress on

www.percona.com

Backup Locks

● mysqldump

● --lock-tables (default)

– LOCK TABLES READ LOCAL

● --lock-all-tables –master-data and –dump-slave

– FLUSH TABLES WITH READ LOCK

● --single-transaction (innodb only)

– START TRANSACTION /*!40100 WITH CONSISTENTSNAPSHOT */

● --skip-lock-tables

– No locks

Page 29: Creating a Best-in-Class Backup and Recovery …...2015/07/15  · Logical Backups Mydumper Faster logical backups as is multithread Almost no locking with innodb tables Compress on

www.percona.com

Backup Locks

● Mydumper

● Always needs FTWRL to coordinate threads but fora small time if all tables are innodb

● --less-locking

– LOCK TABLES READ LOCAL for non-innodb

– CONSISTENT SNAPSHOT for innodb

● --use-savepoints

– Reduce metadata locking issues

● --no-locks

– Not ensure a consistent backup

Page 30: Creating a Best-in-Class Backup and Recovery …...2015/07/15  · Logical Backups Mydumper Faster logical backups as is multithread Almost no locking with innodb tables Compress on

www.percona.com

Backup Locks

● Percona XtraBackup

● FTWRL at the end to copy non transactional filesand get binlog coordinates.

● --rsync

– Use rsync twice instead of cp each file, FTWRL for onlythe second rsync, didn't work with stream

● --no-locks

– Not ensure a consistent backup

Page 31: Creating a Best-in-Class Backup and Recovery …...2015/07/15  · Logical Backups Mydumper Faster logical backups as is multithread Almost no locking with innodb tables Compress on

www.percona.com

Backup Locks

● Percona Server 5.6 new locks for backups

● LOCK TABLES FOR BACKUP

● Block updates to non-transactional tables

● Block DDL to all tables

● LOCK BINLOG FOR BACKUP

● blocks all updates to binary log

● UNLOCK BINLOG

Page 32: Creating a Best-in-Class Backup and Recovery …...2015/07/15  · Logical Backups Mydumper Faster logical backups as is multithread Almost no locking with innodb tables Compress on

www.percona.com

Backup Locks

● Percona Server 5.6 new locks for backups

● Percona XtraBackup 2.2

● Mysqldump --lock-for-backup –single-transaction

● Mydumper 0.6.2

Page 33: Creating a Best-in-Class Backup and Recovery …...2015/07/15  · Logical Backups Mydumper Faster logical backups as is multithread Almost no locking with innodb tables Compress on

Examples

Page 34: Creating a Best-in-Class Backup and Recovery …...2015/07/15  · Logical Backups Mydumper Faster logical backups as is multithread Almost no locking with innodb tables Compress on

www.percona.com

Using Percona XtraBackup

● Simple Backup:

innobackupex --rsync --slave-info /backups/

● Prepare

innobackupex --apply-log --use-memory=2G --defaults-file=/etc/my.cnf /backups/latest/

● Restore

innobackupex --copy-back /backups/latest/

Page 35: Creating a Best-in-Class Backup and Recovery …...2015/07/15  · Logical Backups Mydumper Faster logical backups as is multithread Almost no locking with innodb tables Compress on

www.percona.com

Using Percona XtraBackup

● Stream Backup:

innobackupex –stream=tar ./ | gzip - > xb.tar

● Unpack

tar xvif xb.tar.gz

● Can be piped to remote host:

● On destination:

cd /destination/dirnc -l 873 | tar xvif -

● On source:

innobackupex –stream=tar ./ | gzip - | nc <dest_ip> 873

Page 36: Creating a Best-in-Class Backup and Recovery …...2015/07/15  · Logical Backups Mydumper Faster logical backups as is multithread Almost no locking with innodb tables Compress on

www.percona.com

Using Percona XtraBackup

● Stream Backup:

innobackupex --stream=xbstream --compress --parallel=4 ./ > xb.xbs

● Unpack

xbstream -x < xb.xbs -C /destination/dir

● Can be piped to remote host:

● On destination:

nc -l 873 | xbstream -x -C /destination/dir

● On source:

innobackupex --stream=xbstream ./ | nc <dest_ip> 873

Page 37: Creating a Best-in-Class Backup and Recovery …...2015/07/15  · Logical Backups Mydumper Faster logical backups as is multithread Almost no locking with innodb tables Compress on

www.percona.com

Using Mydumper

● Full Backup:

mydumper -h x.x.x.x -–less-locking –-compress -o /backup/dir

● Full Restore:

myloader -h x.x.x.x -d /backup/dir -o

Page 38: Creating a Best-in-Class Backup and Recovery …...2015/07/15  · Logical Backups Mydumper Faster logical backups as is multithread Almost no locking with innodb tables Compress on

www.percona.com

Using Mydumper

● Partial Restore:

cd /backup/dir

mkdir restore

cp -l db.* ./restore/

cp -l metadata ./restore/

myloader -h x.x.x.x -d /backup/dir/restore/ -o

Page 39: Creating a Best-in-Class Backup and Recovery …...2015/07/15  · Logical Backups Mydumper Faster logical backups as is multithread Almost no locking with innodb tables Compress on

www.percona.com

Using mysqlbinlog

● Copy binlogs:

mysqlbinlog --stop-never --raw --read-from-remote-server --host=127.0.0.1 mysql-bin.000001

Page 40: Creating a Best-in-Class Backup and Recovery …...2015/07/15  · Logical Backups Mydumper Faster logical backups as is multithread Almost no locking with innodb tables Compress on

Tips

Page 41: Creating a Best-in-Class Backup and Recovery …...2015/07/15  · Logical Backups Mydumper Faster logical backups as is multithread Almost no locking with innodb tables Compress on

www.percona.com

Tips

● Use the three types of backups

● Binary for full restores, new slaves

● Logical for partial restores

● Binlog for point in time recovery

● Store on more than one server and off-site

● Test your backups!!!!

● Document restore procedures, script them andtest them!!!

Page 42: Creating a Best-in-Class Backup and Recovery …...2015/07/15  · Logical Backups Mydumper Faster logical backups as is multithread Almost no locking with innodb tables Compress on

www.percona.com

Tips (cont)

● If taking from a slave run pt-table-checksum

● Configuration files, scripts

● Do you need to backup everything all days?

● Hardlinking backups can save lot of disk spacein some circumstances

● Monitor your Backups

Page 43: Creating a Best-in-Class Backup and Recovery …...2015/07/15  · Logical Backups Mydumper Faster logical backups as is multithread Almost no locking with innodb tables Compress on

Percona Backup Service

Page 44: Creating a Best-in-Class Backup and Recovery …...2015/07/15  · Logical Backups Mydumper Faster logical backups as is multithread Almost no locking with innodb tables Compress on

www.percona.com

Percona Backup Service

● Managed MySQL backup and recovery combining our bestpractices and software tools with your backup servers

● Percona ensures your backups run smoothly and reliably

● Backup data sets are always available

● Percona manages production recovery

● Lower TCO than managing in-house

● Any combination of MySQL server and backup locations

● Flexible backup configurations per customer

● More information at www.percona.com

Page 45: Creating a Best-in-Class Backup and Recovery …...2015/07/15  · Logical Backups Mydumper Faster logical backups as is multithread Almost no locking with innodb tables Compress on

[email protected]

We're Hiring! www.percona.com/about-us/careers/

Thank you and Q&A