Best practices for maria db and mysql backups

10.256 Aufrufe

Veröffentlicht am

Slides from Jon Day's webcast on best practices for MySQL and MariaDB backup policy. An excellent overview for anyone who is running applications back-ended with MySQL or MariaDB

Veröffentlicht in: Internet

Best practices for maria db and mysql backups

  1. 1. © MariaDB MariaDB and MySQL Backup Best Practices Jonathan Day, Sales Engineer - MariaDB
  2. 2. ● Nexus of Open Source Database Innovation ● Broad Community Adoption Linux distros, leading web companies ● Innovative products enhance MariaDB. ● Enterprise Subscriptions documentation, optimized binaries, patches, bug fixes, included upgrades, 24/7 support, certain legal protections, customer portal. ● Core MySQL founding team, including Monty Widenius and David Axmark - over 400 years cumulative MySQL Experience. ● Proven Open Source and Cloud management team
  3. 3. ● Unusual to debut as a leader! ● Strengths: ○ Functionality ○ Value ○ Community ○ Partners MariaDB received one of the three highest scores for value for money, as it did for suitability of pricing method. It also received one of the highest scores for "no problems encountered." -- Gartner
  4. 4. © MariaDB Topics for Today ● Things to Consider ● Terms ● Types of Backups ● Principles and Strategies ● Backup Tools ● Q & A
  5. 5. © MariaDB Things to Consider - The Data ● What is the nature of the data? ○ Does it compress well? ● How much data do you have? ○ Will it grow? ● Is the data itself sensitive? ● Is the data regulated?
  6. 6. © MariaDB Things to Consider - The Users ● What is the data worth to your organization? ● What internal groups own the data? ● How is the data used? ● Is the data customer facing or used internally?
  7. 7. © MariaDB Things to Consider - Bad Things ● What would happen if the data was permanently lost? ○ Could it be re-created easily? ○ Are there legal ramifications? ● How long can the data be unavailable? ○ How many minutes or hours or days? ○ What would each cost the organization? ● What are the expectations of the organization? ○ Unrealistic assumptions?
  8. 8. © MariaDB Some Backup Terms Consistency - A backup is consistent if it accurately contains all the data from a specific point in time. Cold Backup - A backup performed with MariaDB / MySQL stopped Warm Backup - A backup performed with the database running that significantly affects performance (locks for example)
  9. 9. © MariaDB Some Backup Terms Hot Backup - A backup performed with the database running that does not significantly affect performance. Logical Backup - A text based backup that includes data and commands to recreate the schema and restore the data Physical Backup - A physical copy of the database files
  10. 10. © MariaDB Logical Backups ● Produce text files with SQL statements that can be replayed to rebuild database ● Allows backup of databases or specific tables - schema or only data ● A SQL dump is independent of storage engine, and can be restored to a different storage engine, or used for migration
  11. 11. © MariaDB Logical Backups ● Process can be slow and requires Locks. ● Use a local drive, not across network ● Multiple options exist: mysqldump SELECT INTO OUTFILE
  12. 12. © MariaDB Making Physical Backups ● Produces a binary copy of data ● Faster than dumping to SQL text file ● Recovered only to the same storage engine ● Not useful for migrations ● In the event of file corruption, errors remain unseen and affect the backup too
  13. 13. © MariaDB Making Physical Backups ● Multiple options ○ Copy manually data directory (stopping mysqld necessary) ○ LVM on Linux for volume snapshot ○ (Data complete and consistent, but still trigger InnoDB recovery after restore) ○ InnoDB Hot Backup tool, or XtraBackup
  14. 14. © MariaDB Recovery with Logical Backups ● Recovery is a simple with logical backups ○ $ cat backup.sql | mysql ○ mysql> source backup.sql ● They can also be relatively slow ● mysqldump generates UTF8 Text Files
  15. 15. © MariaDB Recovery with Physical Backups ● Stop the server ● Replace the data with the backup data ● Start the server and let InnoDB perform recovery ● Tip: You can perform this on another system, make a new copy of the recovered data directory ○ This saves time should you need to use it to recover in an emergency
  16. 16. © MariaDB Recovery with Binary Logs ● Restore databases with backup dump file, and use the binary logs to execute remaining SQL statements to a specific point ● Get a list of binary log files and then determine current log file: ○ SHOW BINARY LOGS; ○ SHOW MASTER STATUS; ● Use mysqlbinlog to convert binary log and pipe to mysql client: ○ mysqlbinlog binlog.000005 binlog.000006 | mysql -u root -p
  17. 17. © MariaDB Point-in-Time Recovery ● Give a stop time to mysqlbinlog to recover until then (e.g., Noon): ○ mysqlbinlog --stop-datetime=`2013-11-03 11:59:59 ́ ○ /var/log/mysql/bin.000006 | mysql -u root -p ● Give a start time to mysqlbinlog to recover from then: ○ mysqlbinlog --start-datetime=`2013-11-03 12:01:00 ́ ○ /var/log/mysql/bin.000006 | mysql -u root -p
  18. 18. © MariaDB Point-in-Time Recovery - Event Positions ● Determine event position numbers (log_pos): ○ mysqlbinlog --start-datetime=`2013-11-03 11:55:00 ́ ○ --stop-datetime=`2013-11-03 12:05:00 ́ ○ /var/log/mysql/bin.000001 > /tmp/mysql_restore.sql ● Restore dump file, then run mysqlbinlog until stop position and Resume from a start position: ○ mysqlbinlog --stop-position=342839 /var/log/mysql/bin. 0000006 ○ | mysql -u root -p ○ mysqlbinlog --start-position=342841 /var/l
  19. 19. © MariaDB Point-in-Time Recovery - Event Positions ● The mysqldump option –master-data is very important ● Using –master-data=2 stores the binlog file and offset in the backup as a comment
  20. 20. © MariaDB Replication as a Backup Method ● Use MySQL replication to copy data to slave (close to real time, but technically asynchronous) ● Recovery can be as fast and simple ○ Switch traffic to slave, restore master, switch traffic back to master ○ Alternatively, replay binary logs with mysqlbinlog tool ● Allows other methods to be executed on slave without increasing load on master ● Allows the use of other replication features
  21. 21. © MariaDB Backup Principles ● Even with HA in place, you still need backups ○ For example, HA can’t stop user errors ● Consider both nightly snapshots and real-time backup ○ Daily snapshots (mysqldump, InnoDB Hot Backup, LVM) and real-time backups (Replication) ● Store backups in multiple locations ○ On-site for fast access; Off-site for security
  22. 22. © MariaDB Backup Principles ● Include both data and config files in your backup ○ Copy data, logs, and configuration Files ○ Synchronize binary logs with backup files! ● Test Backup and Recovery ○ Note how long recovery takes
  23. 23. © MariaDB Backup Tools The table below shows a comparison of the common backup tools available for MySQL and MariaDB.
  24. 24. © MariaDB Tools - mysqldump ● Creates Logical Backups ● Is included with MariaDB and MySQL ● Very useful in doing partial backups and selective restores ● Is technically a warm backup when run in default way
  25. 25. © MariaDB Tools - mysqldump ● Creates locks during backup ● Simple to use ● Single threaded ○ SLOW to create backup ○ SLOW to restore
  26. 26. © MariaDB Tools - mydumper ● Creates logical backups ● A faster alternative to mysqldump as it uses multiple threads ● Uses companion application myloader to restore ● Creates files per table which makes restores multithreaded ● Almost no locking with InnoDB ● Uses compression ● Created by Domas Mituzas
  27. 27. © MariaDB Tools - XtraBackup ● Fast BackUp Process ● Transactions Processed during BackUp Process, a warm backup if not hot ● Low Drain on System Resources ● Back-Up Files Verified Automatically ● Faster Restore Process ● Incremental Backup ● Streaming Backup
  28. 28. © MariaDB Tools - LVM Snapshots Logical Volume Manager (LVM) is a block device subsystem included with Linux that sits between the file system and the physical disk. Among other things, it provides the ability to quickly take snapshots of a disk volume. The steps to create a backup are: 1. Flush the logs and lock the tables “FLUSH TABLES WITH READ LOCK” 2. Create the snapshot 3. Unlock the tables “UNLOCK TABLES” 4. Mount the snapshot volume and back it up or make a copy 5. Delete the snapshot (there is a performance penalty while it exists)
  29. 29. © MariaDB Tools - LVM Snapshots mylvmbackup is a scripted solution that automates much of this process. It was created by Lenz Grimmer and can find it here:
  30. 30. © MariaDB MariaDB & MySQL Remote DBA Subscription The MariaDB & MySQL Remote DBA Subscription is a yearly subscription and it includes: ● Monitoring and Backup tools ● Integration with our 24x7 support ● The Remote DBA services pack includes the following services: ● Initial setup and tuning of monitoring servers ● Initial health check to ensure best practices and minimise downtime ● Backup install ● Backup verification ● Continuous 24x7 monitoring ● Regular health checks ● Proactive tuning and maintenance ● Consistency, latency and state checks for replicated environments ● Support response to monitoring alerts and other issues ● 30 min SLA for severe (S1) issues
  31. 31. © MariaDB Thank You!