Zararfa SummerCamp 2012 - Performing fast backups in large scale environments using open source...

17
MySQL Backup solutions Liz van Dijk - @lizztheblizz Zarafa Summer Camp - June 2012

Transcript of Zararfa SummerCamp 2012 - Performing fast backups in large scale environments using open source...

Page 1: Zararfa SummerCamp 2012 - Performing fast backups in large scale environments using open source backup tools

MySQL Backup solutionsLiz van Dijk - @lizztheblizz

Zarafa Summer Camp - June 2012

Page 2: Zararfa SummerCamp 2012 - Performing fast backups in large scale environments using open source backup tools

Percona

MySQL/LAMP Consulting● MySQL Support● (co-)Developers of

○ Percona Server (XtraDB)○ Percona XtraBackup○ Percona Toolkit (Maatkit, Aspersa)○ Percona XtraDB Cluster

http://www.percona.comhttp://www.mysqlperformanceblog.com

Page 3: Zararfa SummerCamp 2012 - Performing fast backups in large scale environments using open source backup tools

Topics

● Why MySQL Backup is hard to get right● What's available on the market?● Percona's Solution: XtraBackup● Demo

Page 4: Zararfa SummerCamp 2012 - Performing fast backups in large scale environments using open source backup tools

MySQL Backup Challenges

● MySQL is multi-engine○ Different storage engines call for different strategies

■ Are we using filecopy or dumps?■ MyISAM tables handle filecopy quite well■ InnoDB files cannot simply be copied elsewhere

● MySQL can be quite busy○ Do we need to shut it down?○ If not, how much load is generated?○ How quickly can we restore?

● MySQL is more than the sum of its datafiles○ How about binary logging, replication?○ Does the tool impact MySQL in other ways?

Page 5: Zararfa SummerCamp 2012 - Performing fast backups in large scale environments using open source backup tools

Available backup solutions (InnoDB)

InnoDB Impact Warmth Backup Time

Restore Time

Cold Backup very high cold very fast fast

mysqldump medium hot medium slow

snapshotting high/medium hot/warm fast fast

MySQL EB (Enterprise Backup)

low hot fast fast

XtraBackup low hot fast fast

Page 6: Zararfa SummerCamp 2012 - Performing fast backups in large scale environments using open source backup tools

Available backup solutions (mixed)

InnoDB/MyISAM Impact Warmth Backup

TimeRestore

TimeCold Backup very high cold very fast fast

mysqldump high warm medium slow

snapshotting high/medium hot/warm fast fast

MySQL EB (Enterprise Backup)

low/medium warm fast fast

XtraBackup low/medium warm fast fast

Page 7: Zararfa SummerCamp 2012 - Performing fast backups in large scale environments using open source backup tools

XtraBackup Features

● Shared with MySQL Enterprise Backup○ Non-blocking○ Support for MyISAM○ Compression○ Partial Backups○ Throttling○ Incremental Backups

● Unique to XtraBackup○ Exporting/Importing individual tables○ Streaming (including incremental streaming since 2.0!)○ Parallel copying (with use of innodb_file_per_table)

http://www.percona.com/doc/percona-xtrabackup/intro.html

Page 8: Zararfa SummerCamp 2012 - Performing fast backups in large scale environments using open source backup tools

XtraBackup Inner Workings

Page 9: Zararfa SummerCamp 2012 - Performing fast backups in large scale environments using open source backup tools

XtraBackup/innobackupex Operation

Performing and restoring a mixed full backup:

Backing up (1):1. Copy datafiles while recording transaction log changes2. FLUSH TABLES WITH READ LOCK;3. Get binlog position�4. Copy all .MYD, .MYI, .TRG, .TRN, ... files5. Stop recording transaction log changes6. UNLOCK TABLES;

Preparing/Restoring:7. Prepare backup by applying recorded tlog changes (2)8. Restoring files to original location (3)

Page 10: Zararfa SummerCamp 2012 - Performing fast backups in large scale environments using open source backup tools

Getting down to business...

innobackupex vs. xtrabackup? xtrabackup - Compiled C application, focuses on InnoDB only innobackupex - Perl script, automates surrounding tasks

3 separate "manual" steps are required: (1) - Backing up (2) - Preparing InnoDB files for recovery (3) - Restoring the files

All of these are easily scriptable!

Page 11: Zararfa SummerCamp 2012 - Performing fast backups in large scale environments using open source backup tools

Some recipes

Simple full backup and restore:(1) # innobackupex /path/to/your/backups

(2) # innobackupex --apply-log \ /path/to/your/backups/2012-06-21_13-45-00/

(3) # innobackupex --copy-back \ /path/to/your/backups/2012-06-21_13-45-00/ # chown -R mysql:mysql /var/lib/mysql

Page 12: Zararfa SummerCamp 2012 - Performing fast backups in large scale environments using open source backup tools

Options

● Specified as --variable-name=value● innobackupex/xtrabackup will read options from your config

○ [client] or [mysql] for credentials

○ [mysqld] for location of datadir, InnoDB startup options

○ Lastly, [xtrabackup] to override any of the previous and specify xtrabackup-specific options*

* percona.com/doc/percona-xtrabackup/xtrabackup_bin/xbk_option_reference.html* percona.com/doc/percona-xtrabackup/innobackupex/innobackupex_option_reference.html

Page 13: Zararfa SummerCamp 2012 - Performing fast backups in large scale environments using open source backup tools

Some recipes

Incremental backup:● Repeat (1) to create a full backup at location $fullbackup● # innobackupex --incremental $incbackup \ --incremental-

basedir=$fullbackup● # innobackupex --apply-log --redo-only \ $fullbackup

■ Preparing the base backup FIRST● # innobackupex --apply-log --redo-only \ $fullbackup --incremental-

basedir=$incbackup■ Applying each incremental backup to the base

● # innobackupex --apply-log $fullbackup■ Finish preparing the now completed base backup

Page 14: Zararfa SummerCamp 2012 - Performing fast backups in large scale environments using open source backup tools

Some recipes

Streaming:# innobackupex --stream=tar ./ | ssh user@desthost \ "cat - > /data/backups/backup.tar"Note: Extract with tar -i!

Filtering tablespaces: --tables, --databases, --tables-fileThrottling:

● Limit to 100 read/writes IOs: --throttle=100● In streaming backup, use pv to limit to 10MB/s

○ # innobackupex --stream=tar ./ | pv -q -L10m | \ ssh user@desthost "cat - > \ /data/backups/backup.tar"

Parallel copying of tablespaces: --parallel 2 #threads

Page 15: Zararfa SummerCamp 2012 - Performing fast backups in large scale environments using open source backup tools

A note about versions

● xtrabackup 1.6● xtrabackup 2.0 (GA since 4 April 2012)

○ Backs up galera cluster information○ Supports parallel compression○ Streaming incremental backups○ Backs up LRU dumpfile

Note: When using the xtrabackup binary directly, make sure to use the correct binary for your MySQL version!

Page 16: Zararfa SummerCamp 2012 - Performing fast backups in large scale environments using open source backup tools

Short demo

Page 17: Zararfa SummerCamp 2012 - Performing fast backups in large scale environments using open source backup tools

Percona Live New York MySQL ConferenceNYC, NY - October 1 & 2 2012