OnlineBackup
[edit] Introduction
MySQL Backup is currently being developed and this page describes the work in progress.
MySQL Backup enables you to backup a consistent image of a MySQL Server's data and associated metadata via a direct connection to the MySQL server.
The backup is synchronized between different storage engines and with the binary log (that can be used for point in time recovery). Different techniques are used by different storage engines to provide the best possible backup and restore. The backup image is stored as a file by the MySQL server.
You can read more about this in MySQL Backup Reference Manual
This project is run by the MySQL Replication and Backup Team with the help of contributors to separate modules:
- Lars Thalmann leads the project
- Chuck Bell, Rafal Somla, Øystein Grøvlen and Jørgen Løland are main developers
- Hema Sridharan ensures the quality and writes tests
- Peter Gulutzan is architecture reviewer
- Guilhem Bichot developed the MyISAM native driver
- Alexander Nozdrin is developing service interface to MySQL kernel
- Stewart Smith and Sergey "Svoj" Vojtovich works on the Compression and Encryption features
- Ingo Strüwing works on the client program
- Robin Schumacher is the Product Manager
Please send us (Lars Thalmann <lars@mysql.com>, Rafal Somla <rafal@mysql.com>, or Chuck Bell <cbell@mysql.com>) any comments you may have.
We'll are looking for and encouraging people to help review and test the code. The first parts of MySQL Backup was released in MySQL 6.0.5.
[edit] Download
- Releases (NOTE: Preview Binaries are not tested -- Evaluate on your own risk!)
- Encryption Release 2008-07-16 - This preview release highlights the latest development for MySQL Backup. It includes all of the preview releases below plus the new encryption feature.
- mysql-6.0.6-alpha-debug-backup-0.5-linux-i686.tar.gz (Updated 5 August 2008)
- mysql-6.0.6-alpha-debug-backup-0.5-win32.zip (Note: no NDB support)
- Debug Facility + Compression Release - This preview release highlights the latest development for MySQL Backup. It includes all of the preview releases below plus the very latest bug fixes.
- mysql-6.0.6-alpha-debug-backup-0.4-linux-i686.tar.gz
- mysql-6.0.6-alpha-debug-backup-0.4-win32.zip (Note: no NDB support)
- Backup Logs Preview Release - This preview release highlights changes to the way backup and restore record information. Instead of writing the information to tables in the mysql database, you now have the ability to write the results of the backup commands to a table, a file, or both. You can even turn the logs on and off on the fly. Additionally, you can redirect the output/input of the backup commands using a new dynamic variable named backupdir.
- mysql-6.0.6-alpha-debug-backup-0.3-linux-i686.tar.gz (Backup Kernel + Logging)
- mysql-6.0.6-alpha-debug-backup-0.3-win32.zip (Backup Kernel + Logging) (Note: no NDB support)
- Compression Preview Release: (Updated 27 June 2008)
- mysql-6.0.6-alpha-debug-backup-0.2-linux-i686.tar.gz (Backup Kernel + Compression)
- mysql-6.0.6-alpha-debug-backup-0.2-win32.zip (Backup Kernel + Compression) (Note: no NDB support)
- Preview Release (Note: no NDB support):
- mysql-6.0.5-alpha-debug-backup-0.1-linux-i686.tar.gz (with Backup Kernel + MyISAM Driver)
- mysql-6.0.5-alpha-debug-backup-0.1-win32.zip (with Backup Kernel + MyISAM Driver)
- Official Alpha/Beta Releases:
- MySQL 6.0.4 does not contain backup
- MySQL 6.0.5 will contain Backup Kernel but not MyISAM driver
- MySQL 6.0.6 will contain Backup Kernel + MyISAM driver
- Source code: https://code.launchpad.net/mysql-server (mysql-6.0 and mysql-6.0-backup)
- Encryption Release 2008-07-16 - This preview release highlights the latest development for MySQL Backup. It includes all of the preview releases below plus the new encryption feature.
- Programs (NOTE: Preview Binaries are not tested -- Evaluate on your own risk!)
- The mysqlbackup client program is now in mysql-6.0-backup. It will go into the main 6.0 tree soon, and will be part of the next 6.0 release.
- Documentation:
- MySQL Backup Reference Manual
- Functional specification, Ver 1.0 with use case examples, and a small FAQ (doc)
- Internals manual: MySQL Backup
[edit] MySQL 6.0.5 Features - completed (phases 1-6)
- Online backup of table data, i.e. non-blocking for DML
- Version handling to ensure that backup files are always restorable
- Simple-to-use SQL interface
- Fast backup and restore using engine-specific drivers that take advantage of each storage engine's unique features
- Default blocking driver for any engine (note that this is not online)
- Default consistent snapshot driver for InnoDB, Falcon
- Backup of table and database definitions
- Privileges to control who can do backups and restores
- WL#3576 Point-in-time restore using binlog synchronization
- WL#3956 Consistent backup between and within engines
- WL#4062 Blocking of metadata statements during backup/restore process so that they don't corrupt the ongoing backup
- WL#4116 Information schema with progress information
- WL#3574 Backup of Views
- WL#3574 Backup of Stored procedures and Stored functions
- WL#3582 Backup of Triggers
- WL#3574 Backup of database-owned Events
- WL#4240 Save/restore table space information
- BUG The information returned by BACKUP and RESTORE statements is not machine parsable (part of WL#4116)
- BUG The size of a buffer used for data transfers between backup kernel and drivers is fixed (2MB currently). This can make it impossible to backup some tables. E.g., the built-in backup drivers will refuse to backup tables in which single row is bigger than this limit.
- BUG Views can cause the server to crash
- BUG If a table name has non-standard characters in it, its name can be corrupted
- Bug#30340 Backup images can be large for default drivers (Bug#30340)
- Bug#32301 Falcon storage engine does not support consistent read via handler methods
- Bug#32190 Online backup does not save character set settings for databases
- Bug#32385 The test backup_no_data does not clean up after itself
[edit] MySQL 6.0.6 Features - completed (phase 7)
- WL#4212 Stabilize kernel code and correct memory allocation
- WL#3572 No-data backup engine (Code ready; to fix Bug#36380)
- WL#3572 Native driver for Blackhole engine
- WL#3572 Native driver for Example engine
- WL#3572 Native driver for Merge engine
- WL#3572 Native driver for Federated engine
- WL#4211 Dependency checking (Code will be ready May 8th; To fix Bug#36531)
- WL#4326 Disable events and triggers during restore (To fix Bug#36530)
- WL#866, WL#4279 Native driver for MyISAM
- WL#4037 Compression
[edit] MySQL 6.0.8 Features - completed (phase 7)
- WL#4296 Refine backup progress mechanism
- WL#4073 Backup/restore db objects permissions
- WL#4384 Revise error reporting (To fix Bug#36529, Bug#39089)
[edit] MySQL 6.0.X Features - completed (phase 7a)
- WL#4209 Integrate backup with replication (To fix Bug#36533)
- WL#4264 Backup: Stabilize Service Interface (Alexander)
[edit] Limitations and Features: To be fixed in 6.1
- WL#4271 Encryption
- WL#3781 Native driver for Falcon
- WL#4243 DDL blocker enhancements (Was strongly requested on MySQL UC BOF)
- WL#4405 Native driver for Memory Storage Engine
- WL#4385 Checksum checking (Was strongly requested on MySQL UC BOF)
- WL#4275 Online Backup: Driver Interface Simplification
- WL#3328 Native driver for Archive
- WL#4295 Update the main read/write loop
- WL#3505 Extend I_S.ENGINES with info about native backup support
- WL#4090 Backup privileges
- WL#4280 ST: Service Interface for Replication Services (part of WL#4209)
[edit] Limitations and Features: To be fixed in MySQL 6.1 or later
- WL#4190 Error handling II
- WL#3328 Native driver for Archive engine
- Selective backup/restore
- No Native driver for InnoDB
- WL#3960 Engine agnostic image format
- WL#4246 Stabilize object service interface
- WL#4279 Move native driver into library
- WL#4242 Asynchronous backup commands
- WL#3329 Online backup: Design Advanced SQL Interface
- WL#4272 Data inspection utilities (consistency, extract data, etc)/Client tool
- WL#4274 Incremental backup
- WL#4273 Streaming to other server
- WL#155 Initialization of replication slave/Auto-magic slave setup
- WL#4213 Consistency checking
- WL#4089 XBSA support
- WL#4105 Save slave status
- WL#2354 Native backup for NDB
- WL#4036 Refactor opening and locking tables for backup
- Native backup for CSV
- Native backup for Maria
- backup complete instance (BACKUP ALL)
- Differential backup (there is WL#4274 for incremental backup)
- Atomic restore
- Selective backup/restore implementation (this is not WL#3713).
- Backup of binary log
- Error overwrite (continue even if there is an error, i.e. best effort)
- No Streaming of backup image to other machine
- No Backup of User accounts
- No Backup of Generic Privileges
- No Backup of connections for federated tables
- No Client program to receive the backup image (for piping it somewhere)
- No Backup of partitions
- No Native driver for MySQL Cluster/NDB (WL#2354)
- No Backup of System variables
- No Backup of Plugins and UDFs
- No Backup of Log groups and Table spaces
- No Backup of Storage engine settings
- No Backup of Character set settings
- No Backup of Collations sequence settings
[edit] Limitations that will probably not be fixed ever
- DDL is locked very, very briefly during synchronization phase (should be sub-second time)
- BACKUP/RESTORE statements can not be executed within stored routine
- RESTORE creates database objects with a creation and/or modification time of their creation within the restore operation. For some database objects, e.g. stored procedures, time stamps for creation and/or modification are maintained in system tables. These are not reset to the value they had at backup time.
[edit] Objects to Backup and Restore (Defined in WL#3713)
The following tables include information about all of the objects in the MySQL server grouped by categories. The tables include references to which release these objects will be included for backup and restore as well as links to the relevant worklogs. "Backup Release 1" is the same as the "MySQL 6.0 Server release". The mysqldump column (will) show what can be backed up with the mysqldump program.
| RefId | Non-Persistent Objects | Worklog | Release | mysqldump | |||
|---|---|---|---|---|---|---|---|
| 1 | GLOBAL_STATUS | none | Never | Never | |||
| 2 | PROCESSLIST | none | Never | Never | |||
| 3 | SESSION_STATUS | none | Never | ||||
| 4 | SESSION_VARIABLES | none | Never | ||||
| 5 | All FALCON_* tables (if we get rid of FALCON_TABLES) | none | Never | ||||
| 6 | All tables made for 'community' | none | Never | ||||
| 7 | Contents of tables strictly for 'monitoring' purposes | none | Never | ||||
| 8 | Temporary tables | none | Never | ||||
| 9 | Prepared statements | none | Never | ||||
| 10 | Caches | none | Never | RefId | Static Objects | Worklog | Release |
| 11 | Static files that come as part of MySQL installation | none | Never | ||||
| 12 | User programs | none | Never | ||||
| 13 | Operating system shared libraries | none | Never | RefId | External Objects | Worklog | Release |
| 14 | Scripts for starting MySQL server when booting OS | none | Never | ||||
| 15 | Environment inits for $MYSQL_HOST or similar variables | none | Never | RefId | Non-exclusive Objects | Worklog | Release |
| 16 | Option files (also known as configuration files) | none | 3 | ||||
| 17 | Plugins (the loadables) | none | 3 | ||||
| 18 | Files in the basedir 'shared' directory | none | 3 | RefId | Server Objects | Worklog | Release |
| 19 | Global variables except global-status | none | 2 | ||||
| 20-a | master.info | none | 2 | ||||
| 20-b | relay-log.info | WL#4105 | 2 | ||||
| 21 | Tablespaces | none | 2 | ||||
| 22 | Logs | none | Never | ||||
| 23 | Binary log | none | 3 | ||||
| 24 | Users and global-level privileges | none | 2 | ||||
| 25 | Plugin info (mysql.plugin without code) | none | 2 | ||||
| 26 | Federated table connections (mysql.servers) | none | 2 | ||||
| 27 | "Help (4 tables: help_category, etc.)" | none | 3 | ||||
| 28 | "Time zone (5 tables: time_zone, etc.)" | none | 2 | ||||
| 29-a | general_log | none | 3 | ||||
| 29-b | slow_log | none | 3 | ||||
| 30 | Information about UDFs (without loadable) | none | 3 | ||||
| 31 | LOGFILE GROUPS | none | 3 | ||||
| 32 | mysql.host | none | 3 | ||||
| 33 | mysql.db | none | 3 | ||||
| 35 | mysql.ndb_binlog_index | none | 3 | ||||
| 36 | mysql.online_backup | none | 3 | RefId | Database Objects | Worklog | Release |
| 37 | View WL#3574 | none | 1 | ||||
| 38 | Stored Procedure | WL#3574 | 1 | ||||
| 39 | Function | WL#3574 | 1 | ||||
| 40 | Trigger | WL#3582, WL#3574 | 1 | ||||
| 41 | Event | WL#3574 | 1 | ||||
| 42 | Privileges (db tbl view sp/sf cols ev) | WL#3574 | 1 | ||||
| 43-a | Constraint (Primary Key) | DONE | 1 | ||||
| 43-b | Constraint (Unique) | DONE | 1 | ||||
| 43-c | Constraint (Foreign key) | none | Future | RefId | Future (non existing) Objects | Worklog | Release |
| 44 | Catalog | WL#2073, WL#942 | Future | ||||
| 45 | "Character Set (""dynamic"")" | WL#744 | Future | ||||
| 46 | "Collation (""dynamic"")" | WL#744 | Future | ||||
| 47 | Constraint (CHECK) | WL#929 | Future | ||||
| 48 | Domain | WL#933 | Future | ||||
| 49 | Module | WL#3416 | Future | ||||
| 50 | Profile (as in Oracle) | WL#3824 | Future | ||||
| 51 | Role | WL#988 | Future | ||||
| 52 | Sequence | WL#827 | Future | ||||
| 53 | Privilege (new ones) | WL#2227 | Future | ||||
| 54 | Registry (of plugins) | WL#4102 | Future | ||||
| 55 | Repository (of backups) | WL#3329 | Future | ||||
| 56 | Synonym | WL#1048 | Future | ||||
| 57 | Trigger (DDL) | WL#2418 | Future | ||||
| 58 | Type (distinct) | WL#933 | Future | ||||
| 59 | Type (structured) | WL#3862 | Future | RefId | Other Objects | Worklog | Release |
| 60 | Table definition | none | 1 | ||||
| 61 | Database definition | none | 1 | ||||
| 62 | Index (the actual index for physical native drivers) | none | 1 |
[edit] How to do backup
- Backup by executing statement: BACKUP DATABASE databasename1, databasename2 TO "filename.backup";
- Restore by executing statement: RESTORE FROM "filename.backup";
- For more info, see MySQL Manual: Using BACKUP DATABASE and RESTORE (and possibly WL#3762 SQL interface to Version 1 of MySQL Online Backup)
[edit] How to write native backup and restore drivers
- Read the Source code documentation, especially the Backup engine API documentation (in class backup::Backup_driver) and Restore engine API documentation (in class backup::Restore_driver).
[edit] High-level description
Online Backup enables external clients to back up a consistent image of an instance's data and associated metadata via a direct connection to the MySQL server.
"Consistency" includes the following constraints:
- Transactional tables will contain data only from committed transactions.
- Non-transactional tables will contain data only from completed statements.
- Referential integrity will be maintained between all tables backed up with a specific backup command.
[edit] Main requirements influencing the current design
- Backup is online, i.e., database is functional during backup process (DML only).
- Using efficient, storage-engine specific methods for creating backup image. Engines on which tables are stored are free to choose whatever method they find most appropriate to back up their data.
- Possible to use several different backup methods at the same time. For example some engines might create complete backup image at the beginning of backup process (using consistent snapshot of the data) while others might need to perform a dirty scan of the data, followed by change-logs. Online backup should work with both these methods and correctly synchronize them.
- Possibility to restore only parts of a given backup image. For example only selected tables.
- Accepts/produces streaming backup data. That is, data formats and algorithms are designed so that random access to backup data is not needed.
[edit] Q: How tables stored in engine X are backed up?
There are three methods to back up an engine:
- Native driver. Storage engine can use a specialized method (a so called native driver) for creating backup image in the most efficient way for the particular engine, possibly exploiting the physical layout of its data. At the moment there are no engine-specific backup solutions available in MySQL 5.2.
- Consistent snapshot driver. For engines that do not have a native driver but that support consistent snapshot (e.g. InnoDB), there is a consistent snapshot algorithm in the MySQL server to do backups of these engines.
- Default driver. For engines that do not have a native driver and do not support consistent snapshot, there is a default algorithm that does a backup of the engine. In contrast with the methods above, this algorithm is blocking.
Currently the method is automatically selected by the MySQL server and it is not possible for the user to select method.
[edit] Architecture of online backup system
[edit] Backup Kernel
- Execute BACKUP/RESTORE SQL statements,
- Backup/restore metadata (table definitions, per database and per instance metadata),
- Initialize and coordinate work of backup/restore drivers provided by backup engines,
- Write/read backup archive to/from the backup storage media.
The metadata saved by backup kernel has several components and in the future versions of the system user is supposed to be able to select which of these components to save/restore. Current prototype backs up only the basic metadata, i.e., table definitions. This is to be soon extended by
- per table metadata, e.g. triggers,
- per database metadata, e.g. stored functions and procedures.
[edit] Backup Engine
- create consistent image of data stored in tables,
- restore contents of tables from a previously created image,
- estimate size of the backup image.
Note that a backup engine is not responsible for backing up table definitions or other metadata (this is done by the backup kernel). Only data contained in tables is to be saved.
Consistency of the image means that data saved there coresponds to the data which was stored in the tables at some definite point in time. This moment is called the validity point of the image. The image should contain only data which was commited at the time of validity point.
To synchronize several images created by different backup engines, validity point of each image must be chosen by the backup kernel, not by the involved engines. This adds extra complexity to the design and is implemented using backup API and protocols described below.
[edit] Backup/Restore API
This is the API used for communication between backup kernel and backup engines. It has form of virtual classes defining necessary interfaces to be implemented by a backup solution provider (a storage engine usually).
Handlerton structure has been extended with one extra pointer to a factory function creating Backup_engine
object, which encapsulates backup and restore functionality of the engine.
typedef backup_result_t backup_factory(handlerton*, Backup_engine*&);
struct handlerton
{
...
backup_factory *get_backup_engine;
}
Engines which don't support native backup/restore functionality should set this pointer to NULL. If the pointer is set, backup kernel uses the function to create an instance of Backup_engine
object which contains further information about provided backup/restore functionality.
The main methods of Backup_engine object are get_backup() and
get_restore(). When backing-up or restoring a given list of tables they create instances of backup/restore driver objects (of type Backup_driver and
Restore_driver respectively) with which backup kernel interacts to create backup image or restore data from such an image.
Note that a driver object corresponds to and realizes a single backup/restore operation. For each executed backup/restore, a new driver is created.
[edit] Default Backup Engine
Some storage engines may not supply the interface to this API. Initially this will be the case for all engines, but it is possible that some engines may never be converted. Online backup system implements a default backup engine which will be used for storage engines which don't support native backup. This engine uses standard storage engine API to scan table data. Currently, this default backup method blocks all the backed-up tables for the period of backup operation.
[edit] Server Interface
We try to clearly define the interface between Online Backup module and the rest of the server. Here is a page documenting a discussion with Runtime team about the interface.
[edit] Backup Protocol - Multi Engine Synchronization
To correctly operate with backup kernel, backup driver needs to follow the backup protocol described here. The protocol is designed to allow for synchronization of several backup drivers, possibly using different backup techniques.
[edit] Types of Backup Drivers
Drivers can use different methods for creating their backup images. These methods can be divided into two broad classes:
- "At end", or Point Behind methods: engine scans its data while continuing normal operation. On-going changes to the data are recorded in a log which is added to the backup image. The validity point of the image can be created only after the data scan is complete, i.e., "at end" of the backup operation.
- "At begin", or Point Forward methods: engine can create a snapshot of its data at any given moment and continue to work normally. The snapshot will be sent to backup kernel after its creation. The validity point of the backup image is the moment at which snapshot was created, i.e., "at begin" of backup operation.
Regardless of the method used, backup kernel treats all drivers in a uniform way. From its perspective, backup process always consists of 7 phases described in the documentation of
Backup_driver class. Depending of the backup method used, some of these phases can be empty.
A driver informs backup kernel about its type by estimating size of data it is going to send in the initial phase of the backup. For example, "at begin" drivers send no data in the initial phase thus their estimate is 0. "At end" drivers send all their data in the initial phase and they should give a non-zero estimate. If estimating is not possible or too expensive, an "at end" driver can return UNKNOWN_SIZE as the estimate (see init_size() method).
[edit] Driver-Kernel Interaction
Most of the time during the backup process, kernel is polling a driver for the backup image data using get_data method. Driver informs the kernel about its state via the returned value.
When all drivers are done sending the initial image data, kernel initializes the process of synchronizing all the images. First, prelock() is called on all drivers so that they can prepare for synchronization. When all drivers are ready, their lock() methods are called. Drivers are supposed to ensure that the time when lock() was called is the validity point of their images. Their should also freeze any changes to the data after a call to lock(), until the following unlock() call. This is crucial to ensure cross-driver consistency of the whole backup archive.
Since a driver which freezes after a lock() call must wait for all other drivers to complete their calls to lock(), it is important that lock() returns fast (in a matter of seconds). No time consuming operations or ones which involve waiting (e.g., file access) should be done inside the lock() method.
After the unlock() call, when the synchronization phase is finished, kernel continues to poll data from drivers until they signal that all data has been sent.
A typical interaction between kernel and a backup driver should look as follows:
// Preparation
drv->size(); // get estimate of the total size of backup image
drv->init_size(); // get estimate of the amount of data to be sent in the
// initial phase of backup (can be 0)
drv->begin(size); // from now on driver should be ready for get_data()
// requests; buffers sent by kernel will be at leas size long.
// Initial data transfer
drv->get_data(buf); // kernel polls data from driver
... // driver signals that it is done with the
drv->get_data(buf); // initial phase by returning READY.
// Wait for prelock
drv->get_data(buf); // driver is waiting for other drivers to finish they initial
... // data transfer; kernel still polls data during that phase
// Prepare for lock
drv->prelock(); // kernel ask all drivers to prepare for a lock() call
// below; driver signals that it is ready by returning READY,
drv->get_data(buf); // if driver returns OK from prelock() call above, kernel will
... // continue calling get_data() method until it sees READY answer
// Wait for lock
drv->get_data(buf); // driver waits for other drivers to finish preparations for lock;
... // kernel continues polling data
// Synchronization
drv->lock(); // this is a request to create local "validity point" of
// driver's backup image; the engine should be frozen so
// that this validity point remains valid while other
// engines process their lock() requests
drv->unlock(); // this method is called after all engines have been
// locked and the global validity point established; the
// engine should unlock data changes
// Final data transfer
drv->get_data(buf); // kernel polls for further data; driver singals end of data
... // for each table by setting buf.last flag
drv->get_data(buf); // when all data is sent, driver returns DONE from get_data() call
// Epilogue
drv->end(); // end of backup process -- driver can do additional cleaning.
drv->free(); // free allocated resources (can delete the driver).
[edit] Backup Driver Scheduling
Not all drivers are initialized by the kernel at the same time. Instead, backup image size estimates are used to time polling of the drivers so that they are ready for synchronization at approximately the same time. The rule is that drivers with biggest size of the initial transfer are initialized first. Thus kernel will start with polling any "at end" drivers and will activate "at begin" drivers (whose initial data size is 0) only when all other drivers have finished their initial transfer.
If there is more than one driver with non-zero estimate of the initial data size, the relative timing will be based on the amount of data received from them. For example, consider two drivers D1 and D2, the first one sending 1MB of data in the initial phase and the second one 1TB. To minimize the time D1 has to wait for D2, D1 will be initialized only after D2 sends 999MB of its initial data.
D1 initialized after E2 has sent 999MB of data -----+
D1 |===|--|----
D2 |============================================================|-|----
D2 needs to send 1TB in the initial phase... |
+- creating
validity
point.
[edit] Data Transfer Protocol
The data produced by a backup driver is mostly opaque for the backup kernel. The kernel doesn't try to understand the contents of an image: which part contains data, which is a log or indexes (if this type of backup is used). The image is to be read and interpreted by a restore driver during the restore operation.
However, certain assumptions about the format of a backup image data are made. It is assumed that the image consists of several blocks of data which can be of varied sizes. When a get_data(buf) call returns OK or READY, the buffer contains next block of the backup image data. Its actual size is stored in buf.size member which is set by the driver. Upon restore, kernel will send the same block (identical length and contents) back to a restore driver. Also, the order of data blocks will be preserved by the kernel but see the following description regarding block streams and handling of selective restores. If buf.size is set to 0, such empty block is ignored by the kernel and will not be sent back during restore.
It is possible that a user will select only certain tables to be restored from a backup archive. In that case one can reduce amount of data sent to a restore driver by sending only the data which is needed to restore the selected tables. To support this, a backup driver can assign each block of backup data to one of the tables being backed-up. This is done by setting buf.table_no member of the buffer structure. The member should contain number of the table to which the data belongs (tables are numbered from 1 according to the position in the list passed when driver is created). If some of the data doesn't correspond to any particular table, then buf.table_no should be set to 0.
This way, several "streams" of data blocks are created. For each table there is a stream corresponding to that table and there is one "shared stream" consisting of blocks with table_no set to 0. Upon restore, kernel sends to a restore driver only blocks corresponding to the tables being restored plus all the blocks from the shared stream.
For example, consider backing-up three tables t1, t2 and t3. Data blocks produced by a backup driver are divided into four streams:
#0: shared data #1: data for table t1 #2: data for table t2 #3: data for table t3
When a user restores tables t1 and t3, only blocks from streams #0, #1 and #3 will be sent to a restore driver, but not the ones from stream #2.
Using this approach, backup engine can arrange its backup image data in the way which best suits its internal data representation. If needed, all data can be put in the shared stream #0, so that all of it will be sent back to a restore driver. On the other hand, if possible, backup data can be distributed into per table streams to reduce the amount of data transferred upon a selective restore.
Backup driver signals end of data in a given stream by setting buf.last flag to TRUE when get_data(buf) fills the last block of data from that stream. This should be done for each stream used by the driver. Upon restore, kernel sets buf.last to TRUE when sending to a restore driver the last block of data from a stream.
Upon restore, backup kernel will send data blocks in the same order in which they were created.
[edit] Points for discussion
- Can we do full backup for some tables ... across multiple databases (and expect referential integrity)?.
- Currently no. Is this important?
- How do we direct the output data? Currently output redirection seems the only way. Is this enough?
- What about log backup? This could be treated as another kind of storage engine.
- How visible should the data structure be? It could be desirable to postprocess backup archives, for example to select specific tables from an archive. This is possible if the format is known, but it may be difficult to perform for some storage engines.
[edit] Restore
Restore operation is performed using similar but simpler interface and protocols. Backup kernel creates all involved tables from the metadata stored in a backup archive. Then it asks backup engines to create restore drivers and sends data blocks stored in the archive to these drivers using send_data() method. The drivers interpret the data created during backup process and fill tables with rows. All tables are blocked during restore process.
[edit] Changes to Driver API
- 2007-04-20
- Rename
Buffer::stream_no->Buffer::table_no(CSet).
[edit] Current list of people who have tried out the feature
- Padmanabhan Sreenivasan, Zmanda
- Jan Knechke, MySQL
- Robin Schumacher, MySQL
- Guilhem Bichot, MySQL
- Alexander Ivanov, Solid
- Peter Gulutzan, MySQL
