Download presentation
Presentation is loading. Please wait.
Published byTheresa Atkinson Modified over 8 years ago
1
1 Backup and Replication Integration Techniques MySQL 6.0 Lars Thalmann, PhD Mats Kindahl, PhD Chuck Bell, PhD Replication and Backup Team Sun Microsystems 1
2
2 About the Speakers Lars Thalmann, PhD > Development Manager, Replication and Backup > lars.thalmann@sun.com Mats Kindahl, PhD > Lead Developer, Replication > mats.kindahl@sun.com Chuck Bell, PhD > Lead Developer, Backup > charles.bell@sun.com
3
3 Topics What is MySQL Backup and what can it do for me? Scenarios How Backup Works with Replication How Restore Works with Replication Use Cases Tips and Tricks Demonstrations Resources
4
4 What is MySQL Backup? SQL commands for backup and restore of data. Key Features > All database-level objects are included > Backup multiple databases > Non-blocking backup for InnoDB, MyISAM, and Falcon > Database-level (and below) privileges > Logging mechanism for backup and restore > Built-in compression of backup image file > Client application (mysqlbackup)
5
5 Database-level Backup and Restore Objects included > tables > views > stored procedures > functions > triggers > events > grants Tablespaces are a special case
6
6 Overview of Backup Technology Communication with storage engines is accomplished using a specialized driver interface Three types of drivers > Default > Consistent Snapshot > Native
7
7 Overview of Backup Technology Default Driver > Blocking > Backup any storage engine > Reads data using a table scan > Holds exclusive lock on tables for entire backup operation
8
8 Overview of Backup Technology Consistent Snapshot Driver > Non-blocking > Backup any storage engine that supports consistent read > Reads data using a table scan > Holds a consistent read transaction on all tables
9
9 Overview of Backup Technology Native Driver > A specially constructed driver for a specific storage engine > Non-blocking > Normally uses a direct copy mechanism > Required to provide a frozen state during a very short validity point*** > Available for MyISAM
10
10 A word about blocking... Blocking implies locking of some sort (e.g., table locking) where access is denied for a brief period Restore is always blocking and destructive
11
11 A word about blocking... Non-blocking implies no locks Transactional engines are non-blocking if they support the consistent read mechanism defined in the handler interface (Falcon, InnoDB) MyISAM is non-blocking because it has a native driver that permits this mode
12
12 Backup logging All commands generate a record of the event – either backup or restore Lots of pertinent information stored > binlog information > start datetime > database(s) included > etc. See mysql.backup_history
13
13 mysql.backup_history backup_id: 1100 process_id: 0 binlog_pos: 190 binlog_file: mysql-bin.000001 backup_state: complete operation: backup error_num: 0 num_objects: 5 total_bytes: 8705 validity_point_time: 2009-04-11 21:56:56 start_time: 2009-04-11 21:56:55 stop_time: 2009-04-11 21:56:56 host_or_server_name: localhost username: tm backup_file: tm.bak backup_file_path: c:\users\public\ command: BACKUP DATABASE tm, d1 TO 'c:/users/public/tm.bak'
14
14 The MySQL Backup Client Named mysqlbackup Currently allows you to see metadata and other pertinent information stored in the backup image Use it to see what is included in the backup
15
15 Limitations of MySQL Backup Does not (currently) backup entire instance of server – variables, configuration, etc. Does not (currently) backup users and global privileges > You must use mysqldump for this No incremental backup Cannot schedule a backup (yet – we're working on this now)
16
16 How Can I Use MySQL Backup? Available in MySQL 6.0+ Backup BACKUP {DATABASE | SCHEMA} { * | db_name [, db_name]... } TO 'image_file_name' [WITH COMPRESSION [COMPRESSION_ALGORITHM [=] algorithm_name]] backupdir – specify default path for backup images
17
17 How Can I Use MySQL Backup? Restore RESTORE FROM 'image_file_name' [OVERWRITE] [SKIP_GAP_EVENT] Command-line utility : mysqlbackup
18
18 Scenarios Increase recovery success with offline backup storage Secondary recovery plan to replication Creating a new slave Returning a repaired master to service Simplified point-in-time recovery
19
19 How Backup Works with Replication Backups do not affect replication Backup records the current binary information in the backup history log binlog_pos: 190 binlog_file: mysql-bin.000001... validity_point_time: 2009-04-11 21:56:56 start_time: 2009-04-11 21:56:55 stop_time: 2009-04-11 21:56:56
20
20 How Restore Works with Replication Restore may affect replication depending on whether it is run on a master or slave > Master – a gap event is written to the binary log > Slave – does not affect replication but can have side effects such as duplicate keys, conflicting updates
21
21 Use Cases Backup command executed on a master > Master does not log anything > Replication is not affected Restore command executed on a master > An incident event (gap event) will be written to the binary log > While restore is running –New slave connections are blocked with an error –Existing slave connections are blocked (but remain connected) > Slave will stop replication when incident is received***
22
22 Use Cases Backup executed on a slave > Binary log position of the master is not saved > Binary log position of the slave is saved > Replication is not affected Restore command executed on a slave > A incident event will be written to the binary log > If slave is also a master, its slaves will stop***
23
23 Use Cases Backup command executed with no logging > No effect - nothing is logged Restore command executed with logging but no slaves > A restore incident event will be written to the binary log.
24
24 Tips and Tricks Recovery of unintentional changes in a replication topology > Some unintentional change replicated that corrupted the data > Replication alone cannot save you but backup can! Procedure > Drop the databases on the master > Restore latest backup image before the event on the master –Replication stops –Record master's binary log position > Restore latest backup image before the event on the slave(s) > Perform point-in-time recovery on the master using backup validity point as start point and time just prior to change as stop point > Restart replication from recorded position and allow slaves to sync
25
25 Tips and Tricks Which binary log do I use for point-in-time recovery after a backup? Depends on how you do the backup > If you flush the binary log prior to backup, the backup history log will contain the name and position of the new log. > If you do not flush the binary log prior to backup, the backup history log will contain the name and position of the current log. For easier point-in-time recovery, always flush the logs prior to a backup. The starting point is then at the start of the file.
26
26 Tips and Tricks When to skip the gap event > When the database being restored is not replicated (e.g. not in the --replicate-do-db= directives) > Be sure to examine and consider the impact of this option on the replicated data Specify SKIP_GAP_EVENT on restore command: RESTORE FROM '2009_6.bak' OVERWRITE SKIP_GAP_EVENT; Skipping incident event on the slave SET SQL_SKIP_COUNTER = 1;
27
27 Tips and Tricks Oh, no! My backup logs are gone! What do I do now? Use mysqlbackup! Use mysqlbackup to dump metadata for the image. mysqlbackup --all myimage.bak Record the binary log information and necessary metadata for point-in-time recovery. See what is in the backup image.
28
28 Demonstrations
29
29 Resources Books > Expert MySQL > Attribute Level Versioning http://www.apress.com/book/bookDisplay.html?bID=10200 http://dev.mysql.com/doc/refman/6.0/en/replication.html http://dev.mysql.com/doc/refman/6.0/en/backup-and-recovery.html http://dev.mysql.com/downloads http://forge.mysql.com/wiki/OnlineBackup http://dev.mysql.com/doc/refman/6.0/en/installing.html http://dev.mysql.com/backup
30
30 Questions?
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.