How to Backup

From wiki.zmanda.com
Revision as of 18:38, 3 April 2008 by Paddy (talk | contribs) (→‎Raw)
Jump to navigation Jump to search

When planning how to backup, there are two aspects to look at. One is the method to be used for backup and the other is the backup level that can be used to tune how much data gets backed up each time.

Backups occupy hard disk space. While they are being run, the application performance suffers. Network bandwidth can also be cramped. It is important that the method used and level of Backups are optimised to ensure easy recovery of data along with least degradation of application performance. Full backups take the most time and cause the maximum disruption to users. Incremental backups occupy much less space and has minimum impact on users. Similarly the backup method used also has major effect on the impact of backups on the database users.

Backup Mode

ZRM for MySQL provides two methods to backup the database, namely logical and raw. The mode to be used can be specified using the parameter backup-mode. Please refer to Backup Set Parameters for more details.

Logical

Logical backups of a database contain set of SQL statements that can be used to recreate the databases. All storage engines can be backed up using the logical backup method. When this is specified, all of the databases are backed up using mysqldump command. To specify that the backup mode to be used must be logical, add the following parameter to the mysql-zrm.conf.

backup-mode=logical

Advantages

  • This backup method works for all MySQL storage engines (except MySQL cluster NDB storage engine)
  • The backup image can be restored to any platform architecture or another database. For example: Backups of MySQL database running on Redhat Enterprise server powerpc platform can be restored to Ubuntu server running on x86 platform.
  • The logical backup requires ZRM for MySQL to obtain a read lock on the database(s) or tables being backed up or run as a single transaction. As a result, the backup will have an impact on the applications using the MySQL database.

Disadvantages

  • Both backup and restoration of the database can be slow compared to other backup methods.
  • Backup size can be larger than the actual database(s) or tables being backed up.

Raw

Raw backups contain binary copies of the data being backed up. When the backup mode is specified as raw, ZRM for MySQL will choose the optimal backup method to use for the backup set. To specify that the backup mode to be used must be raw, add the following line in the mysql-zrm.conf confoiguration file.

backup-mode=raw

If snapshot-plugin is specified, it will use snapshots to backup the database, if the database and all its related data are on volumes that can be snapshot.

If snapshot-plugin is not specified or if there is a backup failure,

  • If all of the tables in the database use non transactional storage engines, then mysqlhotcopy command is used to backup the database.
  • If any of the tables in the database uses transactional storage engines then mysqldump is used to backup the database.

Under all backup methods, suitable precautions are taken to obtain a consistent copy of the database.

Advantages

  • Backup window will be smaller than logical backups.
  • Size of the backup is same as the size of data being backed up.
  • Raw backup method scales better with database size compared to logical backups.
  • Under some circumstances, the read locks have to be obtained on the database. If snapshots are being used to get consistent copy, the application interruption is minimal.

Disadvantages

  • Backup set can be restored only to same version of MySQL server on the same platform architecture.

Backup Levels

ZRM for MySQL allows you to schedule a mix of full and incremental backups as is suitable for your users and your environment. It makes it convenient for you to schedule by using almost identical commands for both type of backups. Note that the only difference between the command for full backup and incremental backup is the backup-level specified. Specify 0 for full backup and 1 for incremental backup.

Full Backups

Full backups cover all data present in the databases specified.

Full backup is done when the backup level is set to 0 on the mysql-zrm-scheduler command line or in the mysql-zrm.conf configuration file.

The following command will fire an immediate full backup of backup set dailyrun :

# mysql-zrm-scheduler --now --backup-set dailyrun --backup-level 0

Incremental Backups

Incremental backups cover changed data since the last backup.

Incremental backup are done when backup level is set to 1 on the mysql-zrm-scheduler command line or in the mysql-zrm.conf configuration file. Additionally, Binary logging should be enabled in the MySQL server. MySQL binary logs contain all database events executed by the MySQL server.

The following command will fire an immediate incremental backup of backup set dailyrun :

# mysql-zrm-scheduler --now --backup-set dailyrun --backup-level 1

The default location where ZRM for MySQL will look for binary logs is /var/lib/mysql. If a different location is used for storing the binary logs the the mysql-binlog-path needs to be specified in the configuration file. For example

mysql-binlog-path=/var/log/mysql