21.5.24 ndb_restore — Restore an NDB Cluster Backup (original) (raw)

21.5.24 ndb_restore — Restore an NDB Cluster Backup

The NDB Cluster restoration program is implemented as a separate command-line utility ndb_restore, which can normally be found in the MySQL bin directory. This program reads the files created as a result of the backup and inserts the stored information into the database.

Note

Beginning with NDB 7.5.15 and 7.6.11, this program no longer prints NDBT_ProgramExit: ... when it finishes its run. Applications depending on this behavior should be modified accordingly when upgrading from earlier releases.

ndb_restore must be executed once for each of the backup files that were created by theSTART BACKUP command used to create the backup (seeSection 21.6.8.2, “Using The NDB Cluster Management Client to Create a Backup”). This is equal to the number of data nodes in the cluster at the time that the backup was created.

Options that can be used with ndb_restore are shown in the following table. Additional descriptions follow the table.

Table 21.38 Command-line options used with the program ndb_restore

Format Description Added, Deprecated, or Removed
--allow-pk-changes[=0|1] Allow changes to set of columns making up table's primary key ADDED: NDB 7.6.14
--append Append data to tab-delimited file (Supported in all NDB releases based on MySQL 5.7)
--backup-path=path Path to backup files directory (Supported in all NDB releases based on MySQL 5.7)
--backupid=#, -b # Restore from backup having this ID (Supported in all NDB releases based on MySQL 5.7)
--character-sets-dir=path Directory containing character sets (Supported in all NDB releases based on MySQL 5.7)
--connect=connection_string, -c connection_string Alias for --connectstring (Supported in all NDB releases based on MySQL 5.7)
--connect-retries=# Number of times to retry connection before giving up (Supported in all NDB releases based on MySQL 5.7)
--connect-retry-delay=# Number of seconds to wait between attempts to contact management server (Supported in all NDB releases based on MySQL 5.7)
--connect-string=connection_string, -c connection_string Same as --ndb-connectstring (Supported in all NDB releases based on MySQL 5.7)
--core-file Write core file on error; used in debugging (Supported in all NDB releases based on MySQL 5.7)
--defaults-extra-file=path Read given file after global files are read (Supported in all NDB releases based on MySQL 5.7)
--defaults-file=path Read default options from given file only (Supported in all NDB releases based on MySQL 5.7)
--defaults-group-suffix=string Also read groups with concat(group, suffix) (Supported in all NDB releases based on MySQL 5.7)
--disable-indexes Causes indexes from backup to be ignored; may decrease time needed to restore data (Supported in all NDB releases based on MySQL 5.7)
--dont-ignore-systab-0, -f Do not ignore system table during restore; experimental only; not for production use (Supported in all NDB releases based on MySQL 5.7)
--exclude-databases=list List of one or more databases to exclude (includes those not named) (Supported in all NDB releases based on MySQL 5.7)
--exclude-intermediate-sql-tables[=TRUE|FALSE] Do not restore any intermediate tables (having names prefixed with '#sql-') that were left over from copying ALTER TABLE operations; specify FALSE to restore such tables (Supported in all NDB releases based on MySQL 5.7)
--exclude-missing-columns Causes columns from backup version of table that are missing from version of table in database to be ignored (Supported in all NDB releases based on MySQL 5.7)
--exclude-missing-tables Causes tables from backup that are missing from database to be ignored (Supported in all NDB releases based on MySQL 5.7)
--exclude-tables=list List of one or more tables to exclude (includes those in same database that are not named); each table reference must include database name (Supported in all NDB releases based on MySQL 5.7)
--fields-enclosed-by=char Fields are enclosed by this character (Supported in all NDB releases based on MySQL 5.7)
--fields-optionally-enclosed-by Fields are optionally enclosed by this character (Supported in all NDB releases based on MySQL 5.7)
--fields-terminated-by=char Fields are terminated by this character (Supported in all NDB releases based on MySQL 5.7)
--help, -? Display help text and exit (Supported in all NDB releases based on MySQL 5.7)
--hex Print binary types in hexadecimal format (Supported in all NDB releases based on MySQL 5.7)
--ignore-extended-pk-updates[=0|1] Ignore log entries containing updates to columns now included in extended primary key ADDED: NDB 7.6.14
--include-databases=list List of one or more databases to restore (excludes those not named) (Supported in all NDB releases based on MySQL 5.7)
--include-tables=list List of one or more tables to restore (excludes those in same database that are not named); each table reference must include database name (Supported in all NDB releases based on MySQL 5.7)
--lines-terminated-by=char Lines are terminated by this character (Supported in all NDB releases based on MySQL 5.7)
--login-path=path Read given path from login file (Supported in all NDB releases based on MySQL 5.7)
--lossy-conversions, -L Allow lossy conversions of column values (type demotions or changes in sign) when restoring data from backup (Supported in all NDB releases based on MySQL 5.7)
--no-binlog If mysqld is connected and using binary logging, do not log restored data (Supported in all NDB releases based on MySQL 5.7)
--no-defaults Do not read default options from any option file other than login file (Supported in all NDB releases based on MySQL 5.7)
--no-restore-disk-objects, -d Do not restore objects relating to Disk Data (Supported in all NDB releases based on MySQL 5.7)
--no-upgrade, -u Do not upgrade array type for varsize attributes which do not already resize VAR data, and do not change column attributes (Supported in all NDB releases based on MySQL 5.7)
--ndb-connectstring=connection_string, -c connection_string Set connect string for connecting to ndb_mgmd. Syntax: "[nodeid=id;][host=]hostname[:port]". Overrides entries in NDB_CONNECTSTRING and my.cnf (Supported in all NDB releases based on MySQL 5.7)
--ndb-mgmd-host=connection_string, -c connection_string Same as --ndb-connectstring (Supported in all NDB releases based on MySQL 5.7)
--ndb-nodegroup-map=map, -z Specify node group map; unused, unsupported (Supported in all NDB releases based on MySQL 5.7)
--ndb-nodeid=# Set node ID for this node, overriding any ID set by --ndb-connectstring (Supported in all NDB releases based on MySQL 5.7)
--ndb-optimized-node-selection Enable optimizations for selection of nodes for transactions. Enabled by default; use --skip-ndb-optimized-node-selection to disable (Supported in all NDB releases based on MySQL 5.7)
--nodeid=#, -n # ID of node where backup was taken (Supported in all NDB releases based on MySQL 5.7)
--num-slices=# Number of slices to apply when restoring by slice ADDED: NDB 7.6.13
--parallelism=#, -p # Number of parallel transactions to use while restoring data (Supported in all NDB releases based on MySQL 5.7)
--preserve-trailing-spaces, -P Allow preservation of trailing spaces (including padding) when promoting fixed-width string types to variable-width types (Supported in all NDB releases based on MySQL 5.7)
--print Print metadata, data, and log to stdout (equivalent to --print-meta --print-data --print-log) (Supported in all NDB releases based on MySQL 5.7)
--print-data Print data to stdout (Supported in all NDB releases based on MySQL 5.7)
--print-defaults Print program argument list and exit (Supported in all NDB releases based on MySQL 5.7)
--print-log Print log to stdout (Supported in all NDB releases based on MySQL 5.7)
--print-meta Print metadata to stdout (Supported in all NDB releases based on MySQL 5.7)
--print-sql-log Write SQL log to stdout ADDED: NDB 7.5.4
--progress-frequency=# Print status of restore each given number of seconds (Supported in all NDB releases based on MySQL 5.7)
--promote-attributes, -A Allow attributes to be promoted when restoring data from backup (Supported in all NDB releases based on MySQL 5.7)
--rebuild-indexes Causes multithreaded rebuilding of ordered indexes found in backup; number of threads used is determined by setting BuildIndexThreads (Supported in all NDB releases based on MySQL 5.7)
--remap-column=string Apply offset to value of specified column using indicated function and arguments. Format is [db].[tbl].[col]:[fn]:[args]; see documentation for details ADDED: NDB 7.6.14
--restore-data, -r Restore table data and logs into NDB Cluster using NDB API (Supported in all NDB releases based on MySQL 5.7)
--restore-epoch, -e Restore epoch info into status table; useful on replica cluster for starting replication; updates or inserts row in mysql.ndb_apply_status with ID 0 (Supported in all NDB releases based on MySQL 5.7)
--restore-meta, -m Restore metadata to NDB Cluster using NDB API (Supported in all NDB releases based on MySQL 5.7)
--restore-privilege-tables Restore MySQL privilege tables that were previously moved to NDB (Supported in all NDB releases based on MySQL 5.7)
--rewrite-database=string Restore to differently named database; format is olddb,newdb (Supported in all NDB releases based on MySQL 5.7)
--skip-broken-objects Ignore missing blob tables in backup file (Supported in all NDB releases based on MySQL 5.7)
--skip-table-check, -s Skip table structure check during restore (Supported in all NDB releases based on MySQL 5.7)
--skip-unknown-objects Causes schema objects not recognized by ndb_restore to be ignored when restoring backup made from newer NDB version to older version (Supported in all NDB releases based on MySQL 5.7)
--slice-id=# Slice ID, when restoring by slices ADDED: NDB 7.6.13
--tab=path, -T path Creates a tab-separated .txt file for each table in path provided (Supported in all NDB releases based on MySQL 5.7)
--timestamp-printouts{=true|false} Prefix all info, error, and debug log messages with timestamps ADDED: NDB 7.5.30, 5.7.41-ndb-7.6.26
--usage, -? Display help text and exit; same as --help (Supported in all NDB releases based on MySQL 5.7)
--verbose=# Level of verbosity in output (Supported in all NDB releases based on MySQL 5.7)
--version, -V Display version information and exit (Supported in all NDB releases based on MySQL 5.7)
$> ndb_restore [...] --exclude-databases=db1,db2 --exclude-tables=db3.t1,db3.t2  

(Again, we have omitted other possibly necessary options in the interest of clarity and brevity from the example just shown.)
You can use --include-* and--exclude-* options together, subject to the following rules:

--include-databases=db1 --exclude-tables=db1.t1  

However, reversing the order of the options just given simply causes all tables from databasedb1 to be restored (includingdb1.t1, but no tables from any other database), because the--include-databases option, being farthest to the right, is the first match against database db1 and thus takes precedence over any other option that matchesdb1 or any tables indb1:

--exclude-tables=db1.t1 --include-databases=db1  
$> ndb_restore [...] --include-databases=db1,db2 --include-tables=db3.t1,db3.t2  

(Again we have omitted other, possibly required, options in the example just shown.)
It also possible to restore only selected databases, or selected tables from a single database, without any--include-* (or--exclude-*) options, using the syntax shown here:

ndb_restore other_options db_name,[db_name[,...] | tbl_name[,tbl_name][,...]]  

In other words, you can specify either of the following to be restored:

[slice_ID] = [fragment_counter] % [number_of_slices]  

For a BLOB table, a fragment counter is not used; the fragment number is used instead, along with the ID of the main table for theBLOB table (recall thatNDB stores_BLOB_ values in a separate table internally). In this case, the slice ID for a given fragment is calculated as shown here:

[slice_ID] =  
([main_table_ID] + [fragment_ID]) % [number_of_slices]  

Thus, restoring by N slices means running N instances ofndb_restore, all with--num-slices=_`N`_ (along with any other necessary options) and one each with--slice-id=1,--slice-id=2,--slice-id=3, and so on throughslice-id=_`N`_-1.

$> ndb_restore --restore-data --remap-column=hr.employee.id:offset:1000 \  
    --remap-column=hr.manager.id:offset:1000 --remap-column=hr.firstaiders.id:offset:1000  

(Other options not shown here may also be used.)
--remap-column can also be used to update multiple columns of the same table. Combinations of multiple tables and columns are possible. Different offset values can also be used for different columns of the same table, like this:

$> ndb_restore --restore-data --remap-column=hr.employee.salary:offset:10000 \  
    --remap-column=hr.employee.hours:offset:-10  

When source backups contain duplicate tables which should not be merged, you can handle this by using--exclude-tables,--exclude-databases, or by some other means in your application.
Information about the structure and other characteristics of tables to be merged can obtained usingSHOW CREATE TABLE; thendb_desc tool; andMAX(),MIN(),LAST_INSERT_ID(), and other MySQL functions.
Replication of changes from merged to unmerged tables, or from unmerged to merged tables, in separate instances of NDB Cluster is not supported.

$> ndb_restore --rewrite-database=product,inventory  

The option can be employed multiple times in a single invocation of ndb_restore. Thus it is possible to restore simultaneously from a database nameddb1 to a database nameddb2 and from a database nameddb3 to one named db4 using --rewrite-database=db1,db2 --rewrite-database=db3,db4. Otherndb_restore options may be used between multiple occurrences of --rewrite-database.
In the event of conflicts between multiple--rewrite-database options, the last--rewrite-database option used, reading from left to right, is the one that takes effect. For example, if --rewrite-database=db1,db2 --rewrite-database=db1,db3 is used, only--rewrite-database=db1,db3 is honored, and--rewrite-database=db1,db2 is ignored. It is also possible to restore from multiple databases to a single database, so that --rewrite-database=db1,db3 --rewrite-database=db2,db3 restores all tables and data from databases db1 anddb2 into database db3.
Important
When restoring from multiple backup databases into a single target database using--rewrite-database, no check is made for collisions between table or other object names, and the order in which rows are restored is not guaranteed. This means that it is possible in such cases for rows to be overwritten and updates to be lost.

Typical options for this utility are shown here:

ndb_restore [-c connection_string] -n node_id -b backup_id \
      [-m] -r --backup-path=/path/to/backup/files

Normally, when restoring from an NDB Cluster backup,ndb_restore requires at a minimum the--nodeid (short form:-n),--backupid (short form:-b), and--backup-path options. In addition, when ndb_restore is used to restore any tables containing unique indexes, you must include--disable-indexes or--rebuild-indexes. (Bug #57782, Bug #11764893)

The -c option is used to specify a connection string which tells ndb_restore where to locate the cluster management server (seeSection 21.4.3.3, “NDB Cluster Connection Strings”). If this option is not used, then ndb_restore attempts to connect to a management server onlocalhost:1186. This utility acts as a cluster API node, and so requires a free connection“slot” to connect to the cluster management server. This means that there must be at least one[api] or [mysqld] section that can be used by it in the clusterconfig.ini file. It is a good idea to keep at least one empty [api] or[mysqld] section inconfig.ini that is not being used for a MySQL server or other application for this reason (seeSection 21.4.3.7, “Defining SQL and Other API Nodes in an NDB Cluster”).

You can verify that ndb_restore is connected to the cluster by using theSHOW command in thendb_mgm management client. You can also accomplish this from a system shell, as shown here:

$> ndb_mgm -e "SHOW"

Error reporting. ndb_restore reports both temporary and permanent errors. In the case of temporary errors, it may able to recover from them, and reports Restore successful, but encountered temporary error, please look at configuration in such cases.

Important

After using ndb_restore to initialize an NDB Cluster for use in circular replication, binary logs on the SQL node acting as the replica are not automatically created, and you must cause them to be created manually. To cause the binary logs to be created, issue aSHOW TABLES statement on that SQL node before running START SLAVE. This is a known issue in NDB Cluster.