Top Banner
MySQL Backup Strategy @ IEDR Marcelo Altmann Oracle Certified Professional, MySQL 5 Database Administrator Oracle Certified Professional, MySQL 5 Developer Percona Live London – November 2014
38

MySQL Backup Strategy @ IEDR - MySQL by Marcelo

Dec 21, 2016

Download

Documents

dinhduong
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: MySQL Backup Strategy @ IEDR - MySQL by Marcelo

MySQL Backup Strategy

@ IEDRMarcelo Altmann

Oracle Certified Professional, MySQL 5 Database Administrator

Oracle Certified Professional, MySQL 5 Developer

Percona Live London – November 2014

Page 2: MySQL Backup Strategy @ IEDR - MySQL by Marcelo

Who am I ?

MySQL Database Administrator @ IE Domain Registry (IEDR)

Student

Systems for Internet @ FEEVALE University

Oracle Certified Professional

MySQL 5 Database Administrator

MySQL 5 Developer

marceloaltmann.com

@altmannmarcelo

Page 3: MySQL Backup Strategy @ IEDR - MySQL by Marcelo

What IEDR Does ?

Manages the official country code top level domain for Ireland - .ie

Maintain the database of .ie registered domain names

MySQL 5.6

Mainly InnoDB

~80% reads

Page 4: MySQL Backup Strategy @ IEDR - MySQL by Marcelo

Backup Introduction – What for ?

Add new slave to your replication topology

Reproduce some bug on your labs

Point-in-time recovery

Disaster Recovery

Page 5: MySQL Backup Strategy @ IEDR - MySQL by Marcelo

Backup Introduction - Replication as backup

Replication is a backup, but not for all scenarios:

When is replication a backup ?

Physical file corruption

Any Master Server component fail ( RAM, Disk, Network, CPU )

Page 6: MySQL Backup Strategy @ IEDR - MySQL by Marcelo

Backup Introduction – Replication as backup

Including OS errors

Page 7: MySQL Backup Strategy @ IEDR - MySQL by Marcelo

Backup Introduction – When Replication doesn’t

works as a backup?

Application bugs

Someone hacks into your database server

Wrong admin commands like DELETE / UPDATE / DROP

Page 8: MySQL Backup Strategy @ IEDR - MySQL by Marcelo

Backup - Logical

Logical

Save information represented as logical structure ( CREATE DATABASE, CREATE

TABLE, INSERT )

Can be used to restore all databases, single database, single table

Slower than Physical

It's taken while MySQL is running

Done via mysqldump, mydumper, SELECT ... INTO OUTFILE

Page 9: MySQL Backup Strategy @ IEDR - MySQL by Marcelo

Backup - Physical

Raw copies of directory and files of database contents (copy of MySQL

datadir)

No selective restore

Faster than Logical

Done via OS copy commands, mysqlbackup, mysqlhotcopy, percona

xtrabackup

Page 10: MySQL Backup Strategy @ IEDR - MySQL by Marcelo

Backup life cycle

Backup (Logical)

Verify

Encrypt

Distribute

Restore

Backup (Physical)

Slave

Checksum

Page 11: MySQL Backup Strategy @ IEDR - MySQL by Marcelo

Backup - Infrastructure

Page 12: MySQL Backup Strategy @ IEDR - MySQL by Marcelo

Backup - Infrastructure

Page 13: MySQL Backup Strategy @ IEDR - MySQL by Marcelo

Logical Backup

Backup (Logical)

Verify

Encrypt

Distribute

Restore

Backup (Physical)

Slave

Checksum

Page 14: MySQL Backup Strategy @ IEDR - MySQL by Marcelo

Logical Backup

mysqldump

Store backup duration

Backup output of SHOW SLAVE STATUS\G

Verify exit status and last line of the dump

Page 15: MySQL Backup Strategy @ IEDR - MySQL by Marcelo

Logical Backup – exit status and last line

Backup (Logical)

Verify

Encrypt

Distribute

Restore

Backup (Physical)

Slave

Checksum

Page 16: MySQL Backup Strategy @ IEDR - MySQL by Marcelo

Logical Backup – exit status and last line

Page 17: MySQL Backup Strategy @ IEDR - MySQL by Marcelo

Logical Backup – exit status and last line

Page 18: MySQL Backup Strategy @ IEDR - MySQL by Marcelo

Logical Backup – Compress and Encrypt

Backup (Logical)

Verify

Encrypt

Distribute

Restore

Backup (Physical)

Slave

Checksum

Page 19: MySQL Backup Strategy @ IEDR - MySQL by Marcelo

Logical Backup – Compress and Encrypt

Change file permissions

Compress backup to save disk space (GZIP, BZIP2, …)

Encrypt your backups ( openssl )

Page 20: MySQL Backup Strategy @ IEDR - MySQL by Marcelo

Logical Backup – Compress and Encrypt

Page 21: MySQL Backup Strategy @ IEDR - MySQL by Marcelo

Distribute – Same Server

Backup (Logical)

Verify

Encrypt

Distribute

Restore

Backup (Physical)

Slave

Checksum

Page 22: MySQL Backup Strategy @ IEDR - MySQL by Marcelo

Distribute – Same Server

Page 23: MySQL Backup Strategy @ IEDR - MySQL by Marcelo

Distribute – Same DC

Page 24: MySQL Backup Strategy @ IEDR - MySQL by Marcelo

Distribute – Same Region

Page 25: MySQL Backup Strategy @ IEDR - MySQL by Marcelo

Distribute

Page 26: MySQL Backup Strategy @ IEDR - MySQL by Marcelo

Distribute

Send copy of your backups to different datacenter

Pay attention on the distance between datacenters – Natural Disasters!

scp / rsync

Keep copy for 1 week

Page 27: MySQL Backup Strategy @ IEDR - MySQL by Marcelo

Restore

Backup (Logical)

Verify

Encrypt

Distribute

Restore

Backup (Physical)

Slave

Checksum

Page 28: MySQL Backup Strategy @ IEDR - MySQL by Marcelo

Restore

Drop everything on MySQL restore instance

Restore dump

Check exit status of mysql command

Page 29: MySQL Backup Strategy @ IEDR - MySQL by Marcelo

Physical Backup – Fast Recovery

Backup (Logical)

Verify

Encrypt

Distribute

Restore

Backup (Physical)

Slave

Checksum

Page 30: MySQL Backup Strategy @ IEDR - MySQL by Marcelo

Physical Backup – Fast Recovery

Stop MySQL

Compress datadir

Encrypt file

Page 31: MySQL Backup Strategy @ IEDR - MySQL by Marcelo

Slave

Backup (Logical)

Verify

Encrypt

Distribute

Restore

Backup (Physical)

Slave

Checksum

Page 32: MySQL Backup Strategy @ IEDR - MySQL by Marcelo

Slave

Page 33: MySQL Backup Strategy @ IEDR - MySQL by Marcelo

Slave

Configure restore server as slave

Use --master-data

Use --relay-log-info-repository=TABLE

Use Relay_Master_Log_File and Exec_Master_Log_Pos from SHOW SLAVE STATUS

Use GTID

Page 34: MySQL Backup Strategy @ IEDR - MySQL by Marcelo

Checksum

Backup (Logical)

Verify

Encrypt

Distribute

Restore

Backup (Physical)

Slave

Checksum

Page 35: MySQL Backup Strategy @ IEDR - MySQL by Marcelo

Checksum

Verify data integrity between master and slaves

pt-table-checksum

Monitor time

Page 36: MySQL Backup Strategy @ IEDR - MySQL by Marcelo

Backup binlog - Point in time recovery

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

Checksum master binlog and backup binlog

Compress

Encrypt

Page 37: MySQL Backup Strategy @ IEDR - MySQL by Marcelo

Audit Copy

Allows you to restore your database to any point in time

Grouped by month

First Logical and Physical backup of each month

All binary logs

Page 38: MySQL Backup Strategy @ IEDR - MySQL by Marcelo

Questions?

@altmannmarcelo

marceloaltmann.com