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.
In NDB 7.6 and earlier, this program printed NDBT_ProgramExit − status upon completion of its run, due to an unnecessary dependency on the NDBT testing library. This dependency has been removed in NDB 8.0, eliminating the extraneous output.
ndb_restore must be executed once for each of the backup files that were created by the START BACKUP command used to create the backup (see Section 18.104.22.168, “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.
Before using ndb_restore, it is recommended that the cluster be running in single user mode, unless you are restoring multiple data nodes in parallel. See Section 23.6.6, “NDB Cluster Single User Mode”, for more information.
Options that can be used with ndb_restore are shown in the following table. Additional descriptions follow the table.
Table 23.41. Command−line options used with the program ndb_restore
When this option is set to 1, ndb_restore allows the primary keys in a table definition to differ from that of the same table in the backup. This may be desirable when backing up and restoring between different schema versions with primary key changes on one or more tables, and it appears that performing the restore operation using ndb_restore is simpler or mor efficient than issuing many ALTER TABLE statements after restoring table schemas and data.
The following changes in primary key definitions are supported by −−allow−pk−changes:
• Extending the primary key: A non−nullable column that exists in the table schema in the backup becomes part of the table's primary key in the database.
When extending a table's primary key, any columns which become part of primary key must not be updated while the backup is being taken; any such updates discovered by ndb_restore cause the restore operation to fail, even when no change in value takes place. In some cases, it may be possible to override this behavior using the −−ignore−extended−pk−updates option; see the description of this option for more information.
• Contracting the primary key (1): A column that is already part of the table's primary key in the backup schema is no longer part of the primary key, but remains in the table.
• Contracting the primary key (2): A column that is already part of the table's primary key in the backup schema is removed from the table entirely.
These differences can be combined with other schema differences supported by ndb_restore, including changes to blob and text columns requiring the use of staging tables.
Basic steps in a typical scenario using primary key schema changes are listed here:
1. Restore table schemas using ndb_restore −−restore−meta
2. Alter schema to that desired, or create it
3. Back up the desired schema
4. Run ndb_restore −−disable−indexes using the backup from the previous step, to drop indexes and constraints
5. Run ndb_restore −−allow−pk−changes (possibly along with −−ignore−extended−pk−updates, −−disable−indexes, and possibly other options as needed) to restore all data
6. Run ndb_restore −−rebuild−indexes using the backup made with the desired schema, to rebuild indexes and constraints
When extending the primary key, it may be necessary for ndb_restore to use a temporary secondary unique index during the restore operation to map from the old primary key to the new one. Such an index is created only when necessary to apply events from the backup log to a table which has an extended primary key. This index is named NDB$RESTORE_PK_MAPPING, and is created on each table requiring it; it can be shared, if necessary, by multiple instances of ndb_restore instances running in parallel. (Running ndb_restore −−rebuild−indexes at the end of the restore process causes this index to be dropped.)
When used with the −−tab and −−print−data options, this causes the data to be appended to any existing files having the same names.
The path to the backup directory is required; this is supplied to ndb_restore using the −−backup−path option, and must include the subdirectory corresponding to the ID backup of the backup to be restored. For example, if the data node's DataDir is /var/lib/mysql−cluster, then the backup directory is /var/lib/mysql−cluster/BACKUP, and the backup files for the backup with the ID 3 can be found in /var/lib/mysql−cluster/BACKUP/BACKUP−3. The path may be absolute or relative to the directory in which the ndb_restore executable is located, and may be optionally prefixed with backup−path=.
It is possible to restore a backup to a database with a different configuration than it was created from. For example, suppose that a backup with backup ID 12, created in a cluster with two storage nodes having the node IDs 2 and 3, is to be restored to a cluster with four nodes. Then ndb_restore must be run twice—once for each storage node in the cluster where the backup was taken. However, ndb_restore cannot always restore backups made from a cluster running one version of MySQL to a cluster running a different MySQL version.
It is not possible to restore a backup made from a newer version of NDB Cluster using an older version of ndb_restore. You can restore a backup made from a newer version of MySQL to an older cluster, but you must use a copy of ndb_restore from the newer NDB Cluster version to do so.
For example, to restore a cluster backup taken from a cluster running NDB Cluster 7.5.25 to a cluster running NDB Cluster 7.4.35, you must use the ndb_restore that comes with the NDB Cluster 7.5.25 distribution.
For more rapid restoration, the data may be restored in parallel, provided that there is a sufficient number of cluster connections available. That is, when restoring to multiple nodes in parallel, you must have an [api] or [mysqld] section in the cluster config.ini file available for each concurrent ndb_restore process. However, the data files must always be applied before the logs.
This option specifies a password to be used when decrypting an encrypted backup with the −−decrypt option. This must be the same password that was used to encrypt the backup.
The password can be up to 256 characters in length, and must be enclosed by single or double quotation marks. It can contain any of the ASCII characters having character codes 32, 35, 38, 40−91, 93, 95, and 97−126; in other words, it can use any printable ASCII characters except for !, ', ", $, %, \, and ^.
In MySQL 8.0.24 and later, it is possible to omit the password, in which case ndb_restore waits for it to be supplied from stdin, as when using −−backup−password−from−stdin.
When used in place of −−backup−password, this option enables input of the backup password from the system shell (stdin), similar to how this is done when supplying the password interactively to mysql when using the −−password without supplying the password on the command line.
• −−backupid=#, −b
This option is used to specify the ID or sequence number of the backup, and is the same number shown by the management client in the Backup backup_id completed message displayed upon completion of a backup. (See Section 22.214.171.124, “Using The NDB Cluster Management Client to Create a Backup”.)
When restoring cluster backups, you must be sure to restore all data nodes from backups having the same backup ID. Using files from different backups results at best in restoring the cluster to an inconsistent state, and is likely to fail altogether.
In NDB 8.0, this option is required.
Directory containing character sets.
• −−connect, −c
Alias for −−ndb−connectstring.
Number of times to retry connection before giving up.
Number of seconds to wait between attempts to contact management server.
Same as −−ndb−connectstring.
Write core file on error; used in debugging.
Decrypt an encrypted backup using the password supplied by the −−backup−password option.
Read given file after global files are read.
Read default options from given file only.
Also read groups with concat(group, suffix).
Disable restoration of indexes during restoration of the data from a native NDB backup. Afterwards, you can restore indexes for all tables at once with multithreaded building of indexes using −−rebuild−indexes, which should be faster than rebuilding indexes concurrently for very large tables.
In NDB 8.0.27 and later, this option also drops any foreign keys specified in the backup.
• −−dont−ignore−systab−0, −f
Normally, when restoring table data and metadata, ndb_restore ignores the copy of the NDB system table that is present in the backup. −−dont−ignore−systab−0 causes the system table to be restored. This option is intended for experimental and development use only, and is not recommended in a production environment.
Comma−delimited list of one or more databases which should not be restored.
This option is often used in combination with −−exclude−tables; see that option's description for further information and examples.
When performing copying ALTER TABLE operations, mysqld creates intermediate tables (whose names are prefixed with #sql−). When TRUE, the −−exclude−intermediate−sql−tables option keeps ndb_restore from restoring such tables that may have been left over from these operations. This option is TRUE by default.
It is possible to restore only selected table columns using this option, which causes ndb_restore to ignore any columns missing from tables being restored as compared to the versions of those tables found in the backup. This option applies to all tables being restored. If you wish to apply this option only to selected tables or databases, you can use it in combination with one or more of the −−include−* or −−exclude−* options described elsewhere in this section to do so, then restore data to the remaining tables using a complementary set of these options.
It is possible to restore only selected tables using this option, which causes ndb_restore to ignore any tables from the backup that are not found in the target database.
List of one or more tables to exclude; each table reference must include the database name. Often used together with −−exclude−databases.
When −−exclude−databases or −−exclude−tables is used, only those databases or tables named by the option are excluded; all other databases and tables are restored by ndb_restore.
This table shows several invocations of ndb_restore usng −−exclude−* options (other options possibly required have been omitted for clarity), and the effects these options have on restoring from an NDB Cluster backup:
Table 23.42. Several
invocations of ndb_restore using
−−exclude−* options, and the effects these
options have on restoring from an NDB Cluster backup.
You can use these two options together. For example, the following causes all tables in all databases except for databases db1 and db2, and tables t1 and t2 in database db3, to be restored:
$> 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:
• The actions of all −−include−* and −−exclude−* options are cumulative.
• All −−include−* and −−exclude−* options are evaluated in the order passed to ndb_restore, from right to left.
• In the event of conflicting options, the first (rightmost) option takes precedence. In other words, the first option (going from right to left) that matches against a given database or table “wins”.
For example, the following set of options causes ndb_restore to restore all tables from database db1 except db1.t1, while restoring no other tables from any other databases:
However, reversing the order of the options just given simply causes all tables from database db1 to be restored (including db1.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 matches db1 or any tables in db1:
Each column value is enclosed by the string passed to this option (regardless of data type; see the description of −−fields−optionally−enclosed−by).
The string passed to this option is used to enclose column values containing character data (such as CHAR, VARCHAR, BINARY, TEXT, or ENUM).
The string passed to this option is used to separate column values. The default value is a tab character (\t).
Display help text and exit.
If this option is used, all binary values are output in hexadecimal format.
When using −−allow−pk−changes, columns which become part of a table's primary key must not be updated while the backup is being taken; such columns should keep the same values from the time values are inserted into them until the rows containing the values are deleted. If ndb_restore encounters updates to these columns when restoring a backup, the restore fails. Because some applications may set values for all columns when updating a row, even when some column values are not changed, the backup may include log events appearing to update columns which are not in fact modified. In such cases you can set −−ignore−extended−pk−updates to 1, forcing ndb_restore to ignore such updates.
When causing these updates to be ignored, the user is responsible for ensuring that there are no updates to the values of any columns that become part of the primary key.
For more information, see the description of −−allow−pk−changes.
Comma−delimited list of one or more databases to restore. Often used together with −−include−tables; see the description of that option for further information and examples.
In NDB 8.0, ndb_restore does not by default restore shared users and grants (see Section 23.6.12, “Distributed MySQL Privileges with NDB_STORED_USER”) to the ndb_sql_metadata table. Specifying this option causes it to do so.
Comma−delimited list of tables to restore; each table reference must include the database name.
When −−include−databases or −−include−tables is used, only those databases or tables named by the option are restored; all other databases and tables are excluded by ndb_restore, and are not restored.
The following table shows several invocations of ndb_restore using −−include−* options (other options possibly required have been omitted for clarity), and the effects these have on restoring from an NDB Cluster backup:
Table 23.43. Several
invocations of ndb_restore using
−−include−* options, and their effects on
restoring from an NDB Cluster backup.
You can also use these two options together. For example, the following causes all tables in databases db1 and db2, together with the tables t1 and t2 in database db3, to be restored (and no other databases or tables):
$> 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:
• All tables from one or more databases
• One or more tables from a single database
Specifies the string used to end each line of output. The default is a linefeed character (\n).
Read given path from login file.
• −−lossy−conversions, −L
This option is intended to complement the −−promote−attributes option. Using −−lossy−conversions allows lossy conversions of column values (type demotions or changes in sign) when restoring data from backup. With some exceptions, the rules governing demotion are the same as for MySQL replication; see Section 126.96.36.199.2, “Replication of Columns Having Different Data Types”, for information about specific type conversions currently supported by attribute demotion.
Beginning with NDB 8.0.26, this option also makes it possible to restore a NULL column as NOT NULL. The column must not contain any NULL entries; otherwise ndb_restore stops with an error.
ndb_restore reports any truncation of data that it performs during lossy conversions once per attribute and column.
This option prevents any connected SQL nodes from writing data restored by ndb_restore to their binary logs.
• −−no−restore−disk−objects, −d
This option stops ndb_restore from restoring any NDB Cluster Disk Data objects, such as tablespaces and log file groups; see Section 23.6.10, “NDB Cluster Disk Data Tables”, for more information about these.
• −−no−upgrade, −u
When using ndb_restore to restore a backup, VARCHAR columns created using the old fixed format are resized and recreated using the variable−width format now employed. This behavior can be overridden by specifying −−no−upgrade.
Set connect string for connecting to ndb_mgmd. Syntax: "[nodeid=id;][host=]hostname[:port]". Overrides entries in NDB_CONNECTSTRING and my.cnf.
Same as −−ndb−connectstring.
• −−ndb−nodegroup−map=map, −z
Intended for restoring a backup taken from one node group to a different node group, but never completely implemented; unsupported.
All code supporting this option was removed in NDB 8.0.27; in this and later versions, any value set for it is ignored, and the option itself does nothing.
Set node ID for this node, overriding any ID set by −−ndb−connectstring.
Enable optimizations for selection of nodes for transactions. Enabled by default; use −−skip−ndb−optimized−node−selection to disable.
Do not read default options from any option file other than login file.
• −−nodeid=#, −n
Specify the node ID of the data node on which the backup was taken.
When restoring to a cluster with different number of data nodes from that where the backup was taken, this information helps identify the correct set or sets of files to be restored to a given node. (In such cases, multiple files usually need to be restored to a single data node.) See the section called “Restoring to a different number of data nodes”, for additional information and examples.
In NDB 8.0, this option is required.
When restoring a backup by slices, this option sets the number of slices into which to divide the backup. This allows multiple instances of ndb_restore to restore disjoint subsets in parallel, potentially reducing the amount of time required to perform the restore operation.
A slice is a subset of the data in a given backup; that is, it is a set of fragments having the same slice ID, specified using the −−slice−id option. The two options must always be used together, and the value set by −−slice−id must always be less than the number of slices.
ndb_restore encounters fragments and assigns each one a fragment counter. When restoring by slices, a slice ID is assigned to each fragment; this slice ID is in the range 0 to 1 less than the number of slices. For a table that is not a BLOB table, the slice to which a given fragment belongs is determined using the formula shown here:
[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 the BLOB table (recall that NDB stores BLOB values in a separate table internally). In this case, the slice ID for a given fragment is calculated as shown here:
([main_table_ID] + [fragment_ID]) % [number_of_slices]
Thus, restoring by N slices means running N instances of ndb_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 through slice−id=N−1.
Example. Assume that you want to restore a backup named BACKUP−1, found in the default directory /var/lib/mysql−cluster/BACKUP/BACKUP−3 on the node file system on each data node, to a cluster with four data nodes having the node IDs 1, 2, 3, and 4. To perform this operation using five slices, execute the sets of commands shown in the following list:
1. Restore the cluster metadata using ndb_restore as shown here:
$> ndb_restore −b 1 −n 1 −m −−disable−indexes −−backup−path=/home/ndbuser/backups
2. Restore the cluster data to the data nodes invoking ndb_restore as shown here:
ndb_restore −b 1 −n 1 −r
$> ndb_restore −b 1 −n 1 −r −−num−slices=5 −−slice−id=1 −−backup−path=/var/lib/mysql−cluster/BACKUP/BACKUP−1
$> ndb_restore −b 1 −n 1 −r −−num−slices=5 −−slice−id=2 −−backup−path=/var/lib/mysql−cluster/BACKUP/BACKUP−1
$> ndb_restore −b 1 −n 1 −r −−num−slices=5 −−slice−id=3 −−backup−path=/var/lib/mysql−cluster/BACKUP/BACKUP−1
$> ndb_restore −b 1 −n 1 −r −−num−slices=5 −−slice−id=4 −−backup−path=/var/lib/mysql−cluster/BACKUP/BACKUP−1
$> ndb_restore −b 1 −n 2 −r −−num−slices=5 −−slice−id=0 −−backup−path=/var/lib/mysql−cluster/BACKUP/BACKUP−1
$> ndb_restore −b 1 −n 2 −r −−num−slices=5 −−slice−id=1 −−backup−path=/var/lib/mysql−cluster/BACKUP/BACKUP−1
$> ndb_restore −b 1 −n 2 −r −−num−slices=5 −−slice−id=2 −−backup−path=/var/lib/mysql−cluster/BACKUP/BACKUP−1
$> ndb_restore −b 1 −n 2 −r −−num−slices=5 −−slice−id=3 −−backup−path=/var/lib/mysql−cluster/BACKUP/BACKUP−1
$> ndb_restore −b 1 −n 2 −r −−num−slices=5 −−slice−id=4 −−backup−path=/var/lib/mysql−cluster/BACKUP/BACKUP−1
$> ndb_restore −b 1 −n 3 −r −−num−slices=5 −−slice−id=0 −−backup−path=/var/lib/mysql−cluster/BACKUP/BACKUP−1
$> ndb_restore −b 1 −n 3 −r −−num−slices=5 −−slice−id=1 −−backup−path=/var/lib/mysql−cluster/BACKUP/BACKUP−1
$> ndb_restore −b 1 −n 3 −r −−num−slices=5 −−slice−id=2 −−backup−path=/var/lib/mysql−cluster/BACKUP/BACKUP−1
$> ndb_restore −b 1 −n 3 −r −−num−slices=5 −−slice−id=3 −−backup−path=/var/lib/mysql−cluster/BACKUP/BACKUP−1
$> ndb_restore −b 1 −n 3 −r −−num−slices=5 −−slice−id=4 −−backup−path=/var/lib/mysql−cluster/BACKUP/BACKUP−1
$> ndb_restore −b 1 −n 4 −r −−num−slices=5 −−slice−id=0 −−backup−path=/var/lib/mysql−cluster/BACKUP/BACKUP−1
$> ndb_restore −b 1 −n 4 −r −−num−slices=5 −−slice−id=1 −−backup−path=/var/lib/mysql−cluster/BACKUP/BACKUP−1
$> ndb_restore −b 1 −n 4 −r −−num−slices=5 −−slice−id=2 −−backup−path=/var/lib/mysql−cluster/BACKUP/BACKUP−1
$> ndb_restore −b 1 −n 4 −r −−num−slices=5 −−slice−id=3 −−backup−path=/var/lib/mysql−cluster/BACKUP/BACKUP−1
$> ndb_restore −b 1 −n 4 −r −−num−slices=5 −−slice−id=4 −−backup−path=/var/lib/mysql−cluster/BACKUP/BACKUP−1
All of the commands just shown in this step can be executed in parallel, provided there are enough slots for connections to the cluster (see the description for the −−backup−path option).
3. Restore indexes as usual, as shown here:
$> ndb_restore −b 1 −n 1 −−rebuild−indexes −−backup−path=/var/lib/mysql−cluster/BACKUP/BACKUP−1
4. Finally, restore the epoch, using the command shown here:
$> ndb_restore −b 1 −n 1 −−restore−epoch −−backup−path=/var/lib/mysql−cluster/BACKUP/BACKUP−1
You should use slicing to restore the cluster data only; it is not necessary to employ −−num−slices or −−slice−id when restoring the metadata, indexes, or epoch information. If either or both of these options are used with the ndb_restore options controlling restoration of these, the program ignores them.
The effects of using the −−parallelism option on the speed of restoration are independent of those produced by slicing or parallel restoration using multiple instances of ndb_restore (−−parallelism specifies the number of parallel transactions executed by a single ndb_restore thread), but it can be used together with either or both of these. You should be aware that increasing −−parallelism causes ndb_restore to impose a greater load on the cluster; if the system can handle this, restoration should complete even more quickly.
The value of −−num−slices is not directly dependent on values relating to hardware such as number of CPUs or CPU cores, amount of RAM, and so forth, nor does it depend on the number of LDMs.
It is possible to employ different values for this option on different data nodes as part of the same restoration; doing so should not in and of itself produce any ill effects.
• −−parallelism=#, −p
ndb_restore uses single−row transactions to apply many rows concurrently. This parameter determines the number of parallel transactions (concurrent rows) that an instance of ndb_restore tries to use. By default, this is 128; the minimum is 1, and the maximum is 1024.
The work of performing the inserts is parallelized across the threads in the data nodes involved. This mechanism is employed for restoring bulk data from the .Data file—that is, the fuzzy snapshot of the data; it is not used for building or rebuilding indexes. The change log is applied serially; index drops and builds are DDL operations and handled separately. There is no thread−level parallelism on the client side of the restore.
• −−preserve−trailing−spaces, −P
Cause trailing spaces to be preserved when promoting a fixed−width character data type to its variable−width equivalent—that is, when promoting a CHAR column value to VARCHAR, or a BINARY column value to VARBINARY. Otherwise, any trailing spaces are dropped from such column values when they are inserted into the new columns.
Although you can promote CHAR columns to VARCHAR and BINARY columns to VARBINARY, you cannot promote VARCHAR columns to CHAR or VARBINARY columns to BINARY.
Causes ndb_restore to print all data, metadata, and logs to stdout. Equivalent to using the −−print−data, −−print−meta, and −−print−log options together.
Use of −−print or any of the −−print_* options is in effect performing a dry run. Including one or more of these options causes any output to be redirected to stdout; in such cases, ndb_restore makes no attempt to restore data or metadata to an NDB Cluster.
Cause ndb_restore to direct its output to stdout. Often used together with one or more of −−tab, −−fields−enclosed−by, −−fields−optionally−enclosed−by, −−fields−terminated−by, −−hex, and −−append.
TEXT and BLOB column values are always truncated. Such values are truncated to the first 256 bytes in the output. This cannot currently be overridden when using −−print−data.
Print program argument list and exit.
Cause ndb_restore to output its log to stdout.
Print all metadata to stdout.
Log SQL statements to stdout. Use the option to enable; normally this behavior is disabled. The option checks before attempting to log whether all the tables being restored have explicitly defined primary keys; queries on a table having only the hidden primary key implemented by NDB cannot be converted to valid SQL.
This option does not work with tables having BLOB columns.
Print a status report each N seconds while the backup is in progress. 0 (the default) causes no status reports to be printed. The maximum is 65535.
• −−promote−attributes, −A
ndb_restore supports limited attribute promotion in much the same way that it is supported by MySQL replication; that is, data backed up from a column of a given type can generally be restored to a column using a “larger, similar” type. For example, data from a CHAR(20) column can be restored to a column declared as VARCHAR(20), VARCHAR(30), or CHAR(30); data from a MEDIUMINT column can be restored to a column of type INT or BIGINT. See Section 188.8.131.52.2, “Replication of Columns Having Different Data Types”, for a table of type conversions currently supported by attribute promotion.
Beginning with NDB 8.0.26, this option also makes it possible to restore a NOT NULL column as NULL.
Attribute promotion by ndb_restore must be enabled explicitly, as follows:
1. Prepare the table to which the backup is to be restored. ndb_restore cannot be used to re−create the table with a different definition from the original; this means that you must either create the table manually, or alter the columns which you wish to promote using ALTER TABLE after restoring the table metadata but before restoring the data.
2. Invoke ndb_restore with the −−promote−attributes option (short form −A) when restoring the table data. Attribute promotion does not occur if this option is not used; instead, the restore operation fails with an error.
When converting between character data types and TEXT or BLOB, only conversions between character types (CHAR and VARCHAR) and binary types (BINARY and VARBINARY) can be performed at the same time. For example, you cannot promote an INT column to BIGINT while promoting a VARCHAR column to TEXT in the same invocation of ndb_restore.
Converting between TEXT columns using different character sets is not supported, and is expressly disallowed.
When performing conversions of character or binary types to TEXT or BLOB with ndb_restore, you may notice that it creates and uses one or more staging tables named table_name$STnode_id. These tables are not needed afterwards, and are normally deleted by ndb_restore following a successful restoration.
Enable multithreaded rebuilding of the ordered indexes while restoring a native NDB backup. The number of threads used for building ordered indexes by ndb_restore with this option is controlled by the BuildIndexThreads data node configuration parameter and the number of LDMs. It is necessary to use this option only for the first run of ndb_restore; this causes all ordered indexes to be rebuilt without using −−rebuild−indexes again when restoring subsequent nodes. You should use this option prior to inserting new rows into the database; otherwise, it is possible for a row to be inserted that later causes a unique constraint violation when trying to rebuild the indexes.
Building of ordered indices is parallelized with the number of LDMs by default. Offline index builds performed during node and system restarts can be made faster using the BuildIndexThreads data node configuration parameter; this parameter has no effect on dropping and rebuilding of indexes by ndb_restore, which is performed online.
Rebuilding of unique indexes uses disk write bandwidth for redo logging and local checkpointing. An insufficient amount of this bandwith can lead to redo buffer overload or log overload errors. In such cases you can run ndb_restore −−rebuild−indexes again; the process resumes at the point where the error occurred. You can also do this when you have encountered temporary errors. You can repeat execution of ndb_restore −−rebuild−indexes indefinitely; you may be able to stop such errors by reducing the value of −−parallelism. If the problem is insufficient space, you can increase the size of the redo log (FragmentLogFileSize node configuration parameter), or you can increase the speed at which LCPs are performed (MaxDiskWriteSpeed and related parameters), in order to free space more quickly.
When used together with −−restore−data, this option applies a function to the value of the indicated column. Values in the argument string are listed here:
• db: Database name, following any renames performed by −−rewrite−database.
• tbl: Table name.
• col: Name of the column to be updated. This column must be of type INT or BIGINT. The column can also be but is not required to be UNSIGNED.
• fn: Function name; currently, the only supported name is offset.
• args: Arguments supplied to the function. Currently, only a single argument, the size of the offset to be added by the offset function, is supported. Negative values are supported. The size of the argument cannot exceed that of the signed variant of the column's type; for example, if col is an INT column, then the allowed range of the argument passed to the offset function is −2147483648 to 2147483647 (see Section 11.1.2, “Integer Types (Exact Value) - INTEGER, INT, SMALLINT, TINYINT, MEDIUMINT, BIGINT”).
If applying the offset value to the column would cause an overflow or underflow, the restore operation fails. This could happen, for example, if the column is a BIGINT, and the option attempts to apply an offset value of 8 on a row in which the column value is 4294967291, since 4294967291 + 8 = 4294967299 > 4294967295.
This option can be useful when you wish to merge data stored in multiple source instances of NDB Cluster (all using the same schema) into a single destination NDB Cluster, using NDB native backup (see Section 184.108.40.206, “Using The NDB Cluster Management Client to Create a Backup”) and ndb_restore to merge the data, where primary and unique key values are overlapping between source clusters, and it is necessary as part of the process to remap these values to ranges that do not overlap. It may also be necessary to preserve other relationships between tables. To fulfill such requirements, it is possible to use the option multiple times in the same invocation of ndb_restore to remap columns of different tables, as shown here:
(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:
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 using SHOW CREATE TABLE; the ndb_desc tool; and MAX(), 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.
• −−restore−data, −r
Output NDB table data and logs.
• −−restore−epoch, −e
Add (or restore) epoch information to the cluster replication status table. This is useful for starting replication on an NDB Cluster replica. When this option is used, the row in the mysql.ndb_apply_status having 0 in the id column is updated if it already exists; such a row is inserted if it does not already exist. (See Section 23.7.9, “NDB Cluster Backups With NDB Cluster Replication”.)
• −−restore−meta, −m
This option causes ndb_restore to print NDB table metadata.
The first time you run the ndb_restore restoration program, you also need to restore the metadata. In other words, you must re−create the database tables—this can be done by running it with the −−restore−meta (−m) option. Restoring the metadata need be done only on a single data node; this is sufficient to restore it to the entire cluster.
In older versions of NDB Cluster, tables whose schemas were restored using this option used the same number of partitions as they did on the original cluster, even if it had a differing number of data nodes from the new cluster. In NDB 8.0, when restoring metadata, this is no longer an issue; ndb_restore now uses the default number of partitions for the target cluster, unless the number of local data manager threads is also changed from what it was for data nodes in the original cluster.
When using this option in NDB 8.0, it is recommended that auto synchronization be disabled by setting ndb_metadata_check=OFF until ndb_restore has completed restoring the metadata, after which it can it turned on again to synchronize objects newly created in the NDB dictionary.
The cluster should have an empty database when starting to restore a backup. (In other words, you should start the data nodes with −−initial prior to performing the restore.)
ndb_restore does not by default restore distributed MySQL privilege tables created in releases of NDB Cluster prior to version 8.0, which does not support distrubuted privileges as implemented in NDB 7.6 and earlier. This option causes ndb_restore to restore them.
In NDB 8.0, such tables are not used for access control; as part of the MySQL server's upgrade process, the server creates InnoDB copies of these tables local to itself. For more information, see Section 23.3.7, “Upgrading and Downgrading NDB Cluster”, as well as Section 6.2.3, “Grant Tables”.
This option makes it possible to restore to a database having a different name from that used in the backup. For example, if a backup is made of a database named products, you can restore the data it contains to a database named inventory, use this option as shown here (omitting any other options that might be required):
$> 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 named db1 to a database named db2 and from a database named db3 to one named db4 using −−rewrite−database=db1,db2 −−rewrite−database=db3,db4. Other ndb_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 and db2 into database db3.
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.
This option causes ndb_restore to ignore corrupt tables while reading a native NDB backup, and to continue restoring any remaining tables (that are not also corrupted). Currently, the −−skip−broken−objects option works only in the case of missing blob parts tables.
• −−skip−table−check, −s
It is possible to restore data without restoring table metadata. By default when doing this, ndb_restore fails with an error if a mismatch is found between the table data and the table schema; this option overrides that behavior.
Some of the restrictions on mismatches in column definitions when restoring data using ndb_restore are relaxed; when one of these types of mismatches is encountered, ndb_restore does not stop with an error as it did previously, but rather accepts the data and inserts it into the target table while issuing a warning to the user that this is being done. This behavior occurs whether or not either of the options −−skip−table−check or −−promote−attributes is in use. These differences in column definitions are of the following types:
• Different COLUMN_FORMAT settings (FIXED, DYNAMIC, DEFAULT)
• Different STORAGE settings (MEMORY, DISK)
• Different default values
• Different distribution key settings
This option causes ndb_restore to ignore any schema objects it does not recognize while reading a native NDB backup. This can be used for restoring a backup made from a cluster running (for example) NDB 7.6 to a cluster running NDB Cluster 7.5.
When restoring by slices, this is the ID of the slice to restore. This option is always used together with −−num−slices, and its value must be always less than that of −−num−slices.
For more information, see the description of the −−num−slices elsewhere in this section.
• −−tab=dir_name, −T dir_name
Causes −−print−data to create dump files, one per table, each named tbl_name.txt. It requires as its argument the path to the directory where the files should be saved; use . for the current directory.
Display help text and exit; same as −−help.
Sets the level for the verbosity of the output. The minimum is 0; the maximum is 255. The default value is 1.
Display version information and exit.
Restore all rows from the backup's ndb_apply_status table (except for the row having server_id = 0, which is generated using −−restore−epoch). This option requires that −−restore−data also be used.
If the ndb_apply_status table from the backeup already contains a row with server_id = 0, ndb_restore −−with−apply−status deletes it. For this reason, we recommend that you use ndb_restore −−restore−epoch after invoking ndb_restore with the −−with−apply−status option. You can also use −−restore−epoch concurrently with the last of any invocations of ndb_restore −−with−apply−status used to restore the cluster.
For more information, see the section called “ndb_apply_status Table”.
Typical options for this utility are shown here:
[−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.
The −c option is used to specify a connection string which tells ndb_restore where to locate the cluster management server (see Section 220.127.116.11, “NDB Cluster Connection Strings”). If this option is not used, then ndb_restore attempts to connect to a management server on localhost: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 cluster config.ini file. It is a good idea to keep at least one empty [api] or [mysqld] section in config.ini that is not being used for a MySQL server or other application for this reason (see Section 18.104.22.168, “Defining SQL and Other API Nodes in an NDB Cluster”).
In NDB 8.0.22 and later, ndb_restore can decrypt an encrypted backup using −−decrypt and −−backup−password. Both options must be specified to perform decryption. See the documentation for the START BACKUP management client command for information on creating encrypted backups.
You can verify that ndb_restore is connected to the cluster by using the SHOW command in the ndb_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.
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 a SHOW TABLES statement on that SQL node before running START SLAVE. This is a known issue in NDB Cluster.
an NDB Backup to a Different Version of NDB Cluster
The following two sections provide information about restoring a native NDB backup to a different version of NDB Cluster from the version in which the backup was taken.
In addition, you should consult Section 23.3.7, “Upgrading and Downgrading NDB Cluster”, for other issues you may encounter when attempting to restore an NDB backup to a cluster running a different version of the NDB software.
It is also advisable to review What is New in NDB Cluster 8.0, as well as Section 2.11.4, “Changes in MySQL 8.0”, for other changes between NDB 8.0 and previous versions of NDB Cluster that may be relevant to your particular circumstances.
Restoring an NDB backup to a previous version of NDB Cluster
You may encounter issues when restoring a backup taken from a later version of NDB Cluster to a previous one, due to the use of features which do not exist in the earlier version. Some of these issues are listed here:
utf8mb4_ai_ci character set. Tables created in NDB 8.0 by default use the utf8mb4_ai_ci character set, which is not available in NDB 7.6 and earlier, and so cannot be read by an ndb_restore binary from one of these earlier versions. In such cases, it is necessary to alter any tables using utf8mb4_ai_ci so that they use a character set supported in the older version prior to performing the backup.
Table metadata format. Due to changes in how the MySQL Server and NDB handle table metadata, tables created or altered using the included MySQL server binary from NDB 8.0 cannot be restored using ndb_restore to NDB 7.6 or an earlier version of NDB Cluster. Such tables use .sdi files which are not understood by older versions of mysqld. A backup taken in NDB 8.0 of tables which were created in NDB 7.6 or earlier, and which have not been altered since upgrading to NDB 8.0, should be restorable to older versions of NDB Cluster.
Since it is possible to restore metadata and table data separately, you can in such cases restore the table schemas from a dump made using mysqldump, or by executing the necessary CREATE TABLE statements manually, then import only the table data using ndb_restore with the −−restore−data option.
Multi-threaded backups. Multi−threaded backups taken in NDB 8.0 can be restored to an cluster running an earlier version of NDB in either of the following two ways:
• Using an ndb_restore binary from NDB 8.0, perform a parallel restore. See the section called “Restoring a parallel backup in parallel”.
• Restore the backups serially; in this case, a later version of ndb_restore is not required. See the section called “Restoring a parallel backup serially”.
Encrypted backups. Encrypted backups created in NDB 8.0.22 and later cannot be restored using ndb_restore from NDB 8.0.21 or earlier.
NDB_STORED_USER privilege. The NDB_STORED_USER privilege is supported only in NDB 8.0.
Maximum number of data nodes. NDB Cluster 8.0 supports up to 144 data nodes, while earlier versions support a maximum of only 48 data nodes. See the section called “Restoring to Fewer Nodes Than the Original”, for information with situations in which this incompatibility causes an issue.
Restoring an NDB backup to a later version of NDB Cluster
In general, it should be possible to restore a backup created using the ndb_mgm client START BACKUP command in an older version of NDB to a newer version, provided that you use the ndb_restore binary that comes with the newer version. (It may be possible to use the older version of ndb_restore, but this is not recommended.) Additional potential issues are listed here:
• When restoring the metadata from a backup (−−restore−meta option), ndb_restore normally attempts to reproduce the captured table schema exactly as it was when the backup was taken.
Tables created in versions of NDB prior to 8.0 use .frm files for their metadata. These files can be read by the mysqld in NDB 8.0, which can use the information contained therein to create the .sdi files used by the MySQL data dictionary in later versions.
• When restoring an older backup to a newer version of NDB, it may not be possible to take advantage of newer features such as hashmap partitioning, greater number of hashmap buckets, read backup, and different partitioning layouts. For this reason, it may be preferable to restore older schemas using mysqldump and the mysql client, which allows NDB to make use of the new schema features.
• Tables using the old temporal types which did not support fractional seconds (used prior to MySQL 5.6.4 and NDB 7.3.31) cannot be restored to NDB 8.0 using ndb_restore. You can check such tables using CHECK TABLE, and then upgrade them to the newer temporal column format, if necessary, using REPAIR TABLE in the mysql client; this must be done prior to taking the backup. See Section 2.11.5, “Preparing Your Installation for Upgrade”, for more information.
You also also restore such tables using a dump created with mysqldump.
• Distributed grant tables created in NDB 7.6 and earlier are not supported in NDB 8.0. Such tables can be restored to an NDB 8.0 cluster, but they have no effect on access control.
to a different number of data nodes
It is possible to restore from an NDB backup to a cluster having a different number of data nodes than the original from which the backup was taken. The following two sections discuss, respectively, the cases where the target cluster has a lesser or greater number of data nodes than the source of the backup.
Restoring to Fewer Nodes Than the Original
You can restore to a cluster having fewer data nodes than the original provided that the larger number of nodes is an even multiple of the smaller number. In the following example, we use a backup taken on a cluster having four data nodes to a cluster having two data nodes.
1. The management server for the original cluster is on host host10. The original cluster has four data nodes, with the node IDs and host names shown in the following extract from the management server's config.ini file:
We assume that each data node was originally started with ndbmtd −−ndb−connectstring=host10 or the equivalent.
2. Perform a backup in the normal manner. See Section 22.214.171.124, “Using The NDB Cluster Management Client to Create a Backup”, for information about how to do this.
3. The files created by the backup on each data node are listed here, where N is the node ID and B is the backup ID.
These files are found under BackupDataDir/BACKUP/BACKUP−B, on each data node. For the rest of this example, we assume that the backup ID is 1.
Have all of these files available for later copying to the new data nodes (where they can be accessed on the data node's local file system by ndb_restore). It is simplest to copy them all to a single location; we assume that this is what you have done.
4. The management server for the target cluster is on host host20, and the target has two data nodes, with the node IDs and host names shown, from the management server config.ini file on host20:
Each of the data node processes on host3 and host5 should be started with ndbmtd −c host20 −−initial or the equivalent, so that the new (target) cluster starts with clean data node file systems.
5. Copy two different sets of two backup files to each of the target data nodes. For this example, copy the backup files from nodes 2 and 4 from the original cluster to node 3 in the target cluster. These files are listed here:
Then copy the backup files from nodes 6 and 8 to node 5; these files are shown in the following list:
For the remainder of this example, we assume that the respective backup files have been saved to the directory /BACKUP−1 on each of nodes 3 and 5.
6. On each of the two target data nodes, you must restore from both sets of backups. First, restore the backups from nodes 2 and 4 to node 3 by invoking ndb_restore on host3 as shown here:
ndb_restore −c host20 −−nodeid=2
$> ndb_restore −c host20 −−nodeid=4 −−backupid=1 −−restore−data −−backup−path=/BACKUP−1
Then restore the backups from nodes 6 and 8 to node 5 by invoking ndb_restore on host5, like this:
ndb_restore −c host20 −−nodeid=6
$> ndb_restore −c host20 −−nodeid=8 −−backupid=1 −−restore−data −−backup−path=/BACKUP−1
Restoring to More Nodes Than the Original
The node ID specified for a given ndb_restore command is that of the node in the original backup and not that of the data node to restore it to. When performing a backup using the method described in this section, ndb_restore connects to the management server and obtains a list of data nodes in the cluster the backup is being restored to. The restored data is distributed accordingly, so that the number of nodes in the target cluster does not need to be to be known or calculated when performing the backup.
When changing the total number of LCP threads or LQH threads per node group, you should recreate the schema from backup created using mysqldump.
1. Create the backup of the data. You can do this by invoking the ndb_mgm client START BACKUP command from the system shell, like this:
$> ndb_mgm −e "START BACKUP 1"
This assumes that the desired backup ID is 1.
2. Create a backup of the schema. This step is necessary only if the total number of LCP threads or LQH threads per node group is changed.
$> mysqldump −−no−data −−routines −−events −−triggers −−databases > myschema.sql
Once you have created the NDB native backup using ndb_mgm, you must not make any schema changes before creating the backup of the schema, if you do so.
3. Copy the backup directory to the new cluster. For example if the backup you want to restore has ID 1 and BackupDataDir = /backups/node_nodeid, then the path to the backup on this node is /backups/node_1/BACKUP/BACKUP−1. Inside this directory there are three files, listed here:
You should copy the entire directory to the new node.
If you needed to create a schema file, copy this to a location on an SQL node where it can be read by mysqld.
There is no requirement for the backup to be restored from a specific node or nodes.
To restore from the backup just created, perform the following steps:
1. Restore the schema.
• If you created a separate schema backup file using mysqldump, import this file using the mysql client, similar to what is shown here:
$> mysql < myschema.sql
When importing the schema file, you may need to specify the −−user and −−password options (and possibly others) in addition to what is shown, in order for the mysql client to be able to connect to the MySQL server.
• If you did not need to create a schema file, you can re−create the schema using ndb_restore −−restore−meta (short form −m), similar to what is shown here:
$> ndb_restore −−nodeid=1 −−backupid=1 −−restore−meta −−backup−path=/backups/node_1/BACKUP/BACKUP−1
ndb_restore must be able to contact the management server; add the −−ndb−connectstring option if and as needed to make this possible.
2. Restore the data. This needs to be done once for each data node in the original cluster, each time using that data node's node ID. Assuming that there were 4 data nodes originally, the set of commands required would look something like this:
ndb_restore −−nodeid=2 −−backupid=1 −−restore−data −−backup−path=/backups/node_2/BACKUP/BACKUP−1 −−disable−indexes
ndb_restore −−nodeid=3 −−backupid=1 −−restore−data −−backup−path=/backups/node_3/BACKUP/BACKUP−1 −−disable−indexes
ndb_restore −−nodeid=4 −−backupid=1 −−restore−data −−backup−path=/backups/node_4/BACKUP/BACKUP−1 −−disable−indexes
These can be run in parallel.
Be sure to add the −−ndb−connectstring option as needed.
3. Rebuild the indexes. These were disabled by the −−disable−indexes option used in the commands just shown. Recreating the indexes avoids errors due to the restore not being consistent at all points. Rebuilding the indexes can also improve performance in some cases. To rebuild the indexes, execute the following command once, on a single node:
$> ndb_restore −−nodeid=1 −−backupid=1 −−backup−path=/backups/node_1/BACKUP/BACKUP−1 −−rebuild−indexes
As mentioned previously, you may need to add the −−ndb−connectstring option, so that ndb_restore can contact the management server.
from a backup taken in parallel
NDB Cluster 8.0 supports parallel backups on each data node using ndbmtd with multiple LDMs (see Section 126.96.36.199, “Taking an NDB Backup with Parallel Data Nodes”). The next two sections describe how to restore backups that were taken in this fashion.
Restoring a parallel backup in parallel
Restoring a parallel backup in parallel requires an ndb_restore binary from an NDB 8.0 distribution. The process is not substantially different from that outlined in the general usage section under the description of the ndb_restore program, and consists of executing ndb_restore twice, similarly to what is shown here:
ndb_restore −n 1 −b 1 −m
$> ndb_restore −n 1 −b 1 −r −−backup−path=path/to/backup_dir/BACKUP/BACKUP−backup_id
backup_id is the ID of the backup to be restored. In the general case, no additional special arguments are required; ndb_restore always checks for the existence of parallel subdirectories under the directory indicated by the −−backup−path option and restores the metadata (serially) and then the table data (in parallel).
Restoring a parallel backup serially
It is possible to restore a backup that was made using parallelism on the data nodes in serial fashion. To do this, invoke ndb_restore with −−backup−path pointing to the subdirectories created by each LDM under the main backup directory, once to any one of the subdirectories to restore the metadata (it does not matter which one, since each subdirectory contains a complete copy of the metadata), then to each of the subdirectories in turn to restore the data. Suppose that we want to restore the backup having backup ID 100 that was taken with four LDMs, and that the BackupDataDir is /opt. To restore the metadata in this case, we can invoke ndb_restore like this:
$> ndb_restore −n 1 −b 1 −m −−backup−path=opt/BACKUP/BACKUP−100/BACKUP−100−PART−1−OF−4
To restore the table data, execute ndb_restore four times, each time using one of the subdirectories in turn, as shown here:
ndb_restore −n 1 −b 1 −r
$> ndb_restore −n 1 −b 1 −r −−backup−path=opt/BACKUP/BACKUP−100/BACKUP−100−PART−2−OF−4
$> ndb_restore −n 1 −b 1 −r −−backup−path=opt/BACKUP/BACKUP−100/BACKUP−100−PART−3−OF−4
$> ndb_restore −n 1 −b 1 −r −−backup−path=opt/BACKUP/BACKUP−100/BACKUP−100−PART−4−OF−4
You can employ the same technique to restore a parallel backup to an older version of NDB Cluster (7.6 or earlier) that does not support parallel backups, using the ndb_restore binary supplied with the older version of the NDB Cluster software.
Copyright © 1997, 2021, Oracle and/or its affiliates.
This documentation is free software; you can redistribute it and/or modify it only under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License.
This documentation is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with the program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or see http://www.gnu.org/licenses/.
For more information, please refer to the MySQL Reference Manual, which may already be installed locally and which is also available online at http://dev.mysql.com/doc/.
Oracle Corporation (http://dev.mysql.com/).