Mysql-zrm: Difference between revisions

From wiki.zmanda.com
Jump to navigation Jump to search
Line 189: Line 189:


  # mysql-zrm --action restore --bin-logs \
  # mysql-zrm --action restore --bin-logs \
   "/var/lib/mysql-zrm/backupset1/20060818121532/mysql-bin.[0-9]* \         /var/lib/mysql-zrm/backupset1/20060819121532/mysql-bin.[0-9]*"
   "/var/lib/mysql-zrm/backupset1/20060818121532/mysql-bin.[0-9]* \  
    /var/lib/mysql-zrm/backupset1/20060819121532/mysql-bin.[0-9]*"


==FILES==
==FILES==

Revision as of 21:30, 7 September 2006

NAME

mysql-zrm - MySQL backup and recovery tool

SYNOPSIS

mysql-zrm --action <backup|restore|list|purge>
         [--backup-set <name>]
         [--source-directory <directory name>]
         [--replication | --noreplication]
         [--backup-name <name>]
         [--all-databases]
         [--databases <"name1 name2 ...">]
         [--destination <directory name>]
         [--database <name> [--tables <"name1 name2 ...">]]
         [--backup-level <0|1>]
         [--backup-mode <raw|logical>]
         [--lvm-snapshot <size>]
         [--retention-policy <backup retention time>]
         [--bin-logs <"name1 name2 ...">]
         [--start-position <#>]
         [--stop-position <#>]
         [--offset <#>]
         [--start-datetime <name>]
         [--stop-datetime <name>]
         [--index|--noindex]
         [--till-lastfull]
         [--all-backups]
         [--options-file <filename>]
         [--mailto <mail address>]
         [--user <user>]
         [--password <password>]
         [--host <hostname>]
         [--port <portnumber>]
         [--mysql-binpath <location of MySQL commands>]
         [--ssl-options <"MySQL ssl options">]
         [--comment <"Note about the backup">]
         [--quiet|--no-quiet]
         [--verbose]
         [--help]

DESCRIPTION

This tool is part of Zmanda Recovery Manager for MySQL (MySQL ZRM) and can be used to backup and restore MySQL databases. This tool does full and incremental backups as well as full and selective restores. The tool also provides a list option to provide information about the prior backups.

This tool is part of Zmanda Recovery Manager for MySQL (MySQL ZRM) and can be used to backup and restore MySQL databases. This tool does full and incremental backups as well as full and selective restores. The tool also provides a list option to provide information about the prior backups. The tool also implements retention policy for the backup images.

Users are expected to schedule backups with mysql-zrm tool using mysql-zrm-scheduler(1) tool. MySQL database recovery has to be done using the mysql-zrm tool.

Users are expected to schedule backups with mysql-zrm tool using mysql-zrm-scheduler(1) tool. MySQL database recovery has to be done using mysql-zrm tool.

BACKUP SETS

MySQL ZRM organizes the backups in terms of backup sets. Each backup set defines the list of databases or tables within a database, how it should be backed up and the backup schedule for the data. Backup set is identified by an unique string for each MySQL ZRM instance.

Every backup run (each time mysql-zrm is executed) is associated with one backup set.

Every backup run (each time mysql-zrm is executed) is associated with one backup set.

The mysql-zrm tool reads global MySQL ZRM configuration file - /etc/mysql-zrm/mysql-zrm.conf. The global configuration file can be overridden by backup set specific configuration file stored in /etc/mysql-zrm/<backup set name>/ directory.

The mysql-zrm command line options will override the parameters specified in the configuration files. The order in the which backup set parameters will be read:

  1. /etc/mysql-zrm/mysql-zrm.conf
  2. /etc/mysql-zrm/<backup set>/mysql-zrm.conf
  3. Parameters read from --options-file command line argument
  4. Options specified on the command line

BACKUP METHODS

The mysql-zrm full backups can be logical backups or raw backups. Logical backups contain SQL statements to recreate the database. Raw backups are actual copy of the database files. If backup-mode is specified as raw the tool has the ability to decide which backup mechanism to use for a particular database. If there are no transactional storage engine based tables in the specified database, then the utility will use mysqlhotcopy for backing up that database. Otherwise, it will use mysqldump for backing up the specified database. If backup-mode option is specified as logical then only mysqldump will be used for backing up specified databases and tables.

If the lvm-snapshot option is specified and if the specified database is put on an LVM volume then a snapshot of that volume is taken and the database is backed up from that snapshot. If the database is not on a lvm volume then the mysqlhotcopy or mysqldump will be used as per the logic in the last paragraph.

If the replication option is specified and if the mysql server is a slave server, then the tool will also backup all replication related files.

If the destination option is specified then the backups are stored in a sub directory under the specified directory. Default value is /var/lib/mysql-zrm.

An index file is also created in the backup directory. The index file contains the details of the backup run.

If incremental backup is specified, then the command line options backup-mode, lvm-snapshot, all-databases, databases, database and tables are ignored.

RECOVERY

For restores, only all-databases and databases options are supported. So if the backup contains only specific tables from a database, you need to specify mysql-zrm action as restore and the database name to restore the backed up tables. This will only restore the backed up tables. If there are other tables in the database, those will be left untouched.

If the list action is specified, the tool will display the backup level, the name of the directory containing the backup and the index of the last backup of the specified backup set.

If the all-backups option is specified then the above specified data will be displayed for all of the backups that has happened till date for the given backup-set.

If the option till-lastfull is specified then the data since last full backup will be displayed. This option is useful to find out which backups are need to be able to complete a full restore.

If the option source-directory is specified then the index of that backup is displayed.

If the option noindex is specified then the level of backup and the name of the directory containing the backup will be displayed and the contents of the index file will not be displayed.

OPTIONS

--action <backup|restore|list|purge>
Specify which action to do. This option cannot be specified in the options file.
--backup-set <name>
Specify backup-set for the backup run. This option cannot be specified in the options file. The default value for this parameter is BackupSet1
--source-directory <directory name>
Specify the directory containing a backup. This option is ignored if the action specified is backup. During restore both source-directory and bin-logs options should not be specified.
--replication | --noreplication
Specify if replication files should be backed up. The replication related files will be backed up only if the host is a replication slave. Default option is --noreplication
--backup-name <name>
Specifies the name of the directory in which backup should be done. This should be a unique name for each backup run. If not specified, the current timestamp will be used as the backup-name.
--all-databases
Specifies that all databases should be backed up or restored. This is the default if databases or database is not specified
--databases <"name1 name2 ...">
Specifies the specific databases to backup or restore
--database <name> [--tables <"name1 name2 ...">]
Specifies which specific tables should be backed up. This option is only supported during the backup operation.
--destination <directory name>
Directory to which backup should be done. Default location is /var/lib/mysql-zrm
--backup-level <0|1>
If 0 is specified, then a full backup is done. If 1 is specified, an incremental backup is done. Default is 0 if backup-level option is not specified
--backup-mode <raw|logical>
If raw is specified then mysqlhotcopy is used to backup the specified database/tables if the database does not contain any tables that uses a transactional engine. Otherwise, mysqldump is used. If logical is specified then mysqldump is only used. Default is raw.
--lvm-snapshot <size>
This specifies the size of the lvm snapshot to be used. For raw backups, each specified database is checked to see if that is on a LVM volume. If it is then a snapshot of the specified size is created and that is used to backup up the database. If not it will use either mysqlhotcopy or mysqldump based on the logic described in the backup-mode option. This option is ignored if the backup-mode is specified as logical.
--retention-policy <backup retention time>
Backup image for this backup run will retained for the time specified as parameter. A suffix of 'D' indicates time specified in days. A suffix of 'W' indicates amount specified in weeks (number of days are computed as 7*amount). A suffix of 'M' indicates amount in months (number of days are computed as 30*amount). A suffix of 'Y' indicates amount specified in years (number of days are computed as 365*amount). For e.g. if --retention-policy 10M is specified, it indicates that the backup should be retained for 300 days. If no suffix is specified, the amount specified is assumed to be number of days the backup should be retained.
--bin-logs <"name1 name2 ...">
List of binary log files to be used for restore. The full path for each file should be specified. During restore both source-directory and bin-logs options should not be specified.
--start-position N
Start selective restore of all events after log position N. Log positions can be determined using mysqlbinlog --hexdump option.
--stop-position N
Stop selective restore of all events before log position N. Log positions can be determined using mysqlbinlog --hexdump option.
--offset N
Skip the first N entries during selective recovery from incremental backups.
--start-datetime <name>
Selective restore till specified date and time (should be in MySQL DATETIME or TIMESTAMP format)
--stop-datetime <name>
Selective restore till specified date and time (should be in MySQL DATETIME or TIMESTAMP format)
--index|--noindex
Specify if the contents of the index file should be displayed during the list action
--all-backups
Specifies that information about all available backups should be displayed
--till-lastfull
Specifies that information till the last full backup should be displayed
--options-file <filename>
Specify the file containing all of the options
--mailto <mail address>
Address to which backup report to be sent.
--user <user>
Specify MySQL backup/restore user
--password <password>
Specify password for the MySQL user
--host <hostname>
MySQL server host name or IP name
--port <portnumber>
MySQL server port
--mysql-binpath <mysql binaries directory>
Full path where mysql binaries are installed. For e.g. /opt/lampp/bin
--ssl-options <"MySQL ssl options">
Any --ssl* options that MySQL supports. Please refer to MySQL documentation for details of the ssl* options.

--comment <"Note about the backup run">
Comment or a note about the backup run. This can be used to tag backup runs and the note can retrieved using msql-zrm-reporter(1) tool.
--quiet|--no-quiet
Specifying no-quiet will lead to the log messages also being displayed on stdout. Default is quiet.
--verbose
Provide more verbose output in the log
--help
Display help message and exit. This option cannot be specified in the options file

EXAMPLES

For backup the most common usage of mysql-zrm will be to specify replication, an appropriate lvm-snapshot size and the destination directory for backup. Usually, these backup parameters are specified in the configuration file and the MySQL backups are done using mysql-zrm-scheduler(1).

# mysql-zrm  --action  backup  --replication  --lvm-snapshot 100MB --destination /var/lib/mysql-zrm

For a logical backup of specific tables you would use

# mysql-zrm  --action  backup  --replication  --lvm-snapshot 100MB --destination /var/lib/mysql-backup \
  --backup-mode   logical --database dbname --tables "table1 table2 table"

Following command will list contents of backup

# mysql-zrm --action list --source-directory /var/lib/mysql-zrm/backupset1/2006081812153

For restoring the following can be used

# mysql-zrm --action restore --source-directory /var/lib/mysql-zrm/backupset1/20060818121532

This will restore all databases that were backed up. If the source directory points to a full backup, it will do a full restore else it will do a incremental restore.

The following example will do an incremental restore of all of the specified binary log files using a single connection.

# mysql-zrm --action restore --bin-logs \
  "/var/lib/mysql-zrm/backupset1/20060818121532/mysql-bin.[0-9]* \ 
   /var/lib/mysql-zrm/backupset1/20060819121532/mysql-bin.[0-9]*"

FILES

/var/lib/mysql-zrm
Directory under which all backup data is stored.
/etc/mysql-zrm/<backup set name>/mysql-zrm.conf
Configuration file read by mysql-zrm tool.

RETURN VALUES

On success, zero is returned. On error, non-zero value is returned.

SEE ALSO

mysql-zrm-scheduler(1), mysql-zrm-reporter(1), mysqldump(1), mysqlbinlog(1), mysql(1), lvm(8)

AUTHOR

Zmanda Inc. (http://www.zmanda.com)