#### 23.7.9.2 Point-In-Time Recovery Using NDB Cluster Replication

[]()[]()[]()

Point-in-time recovery—that is, recovery of data changes made since a given point in time—is performed after restoring a full backup that returns the server to its state when the backup was made. Performing point-in-time recovery of NDB Cluster tables with NDB Cluster and NDB Cluster Replication can be accomplished using a native [`NDB`](mysql-cluster.html) data backup (taken by issuing [`CREATE BACKUP`](mysql-cluster-mgm-client-commands.html#ndbclient-create-nodegroup) in the [**ndb\_mgm**](mysql-cluster-programs-ndb-mgm.html) client) and restoring the `ndb_binlog_index` table (from a dump made using [**mysqldump**](mysqldump.html)).

 To perform point-in-time recovery of NDB Cluster, it is necessary to follow the steps shown here:

1. Back up all `NDB` databases in the cluster, using the [`START BACKUP`](mysql-cluster-backup-using-management-client.html) command in the [**ndb\_mgm**](mysql-cluster-programs-ndb-mgm.html) client (see [Section 23.6.8, “Online Backup of NDB Cluster”](mysql-cluster-backup.html)).

2. At some later point, prior to restoring the cluster, make a backup of the `mysql.ndb_binlog_index` table. It is probably simplest to use [**mysqldump**](mysqldump.html) for this task. Also back up the binary log files at this time.

    This backup should be updated regularly—perhaps even hourly—depending on your needs.

3. (*Catastrophic failure or error occurs*.)

4. Locate the last known good backup.

5. Clear the data node file systems (using [**ndbd**](mysql-cluster-programs-ndbd.html) [`--initial`](mysql-cluster-programs-ndbd.html#option_ndbd_initial) or [**ndbmtd**](mysql-cluster-programs-ndbmtd.html) [`--initial`](mysql-cluster-programs-ndbd.html#option_ndbd_initial)).

   Note

    Beginning with NDB 8.0.21, Disk Data tablespace and log files are removed by [`--initial`](mysql-cluster-programs-ndbd.html#option_ndbd_initial). Previously, it was necessary to delete these manually.

6. Use [`DROP TABLE`](drop-table.html) or [`TRUNCATE TABLE`](truncate-table.html) with the `mysql.ndb_binlog_index` table.

7. Execute [**ndb\_restore**](mysql-cluster-programs-ndb-restore.html), restoring all data. You must include the [`--restore-epoch`](mysql-cluster-programs-ndb-restore.html#option_ndb_restore_restore-epoch) option when you run [**ndb\_restore**](mysql-cluster-programs-ndb-restore.html), so that the `ndb_apply_status` table is populated correctly. (See [Section 23.5.23, “ndb\_restore — Restore an NDB Cluster Backup”](mysql-cluster-programs-ndb-restore.html), for more information.)

8. Restore the `ndb_binlog_index` table from the output of [**mysqldump**](mysqldump.html) and restore the binary log files from backup, if necessary.

9. Find the epoch applied most recently—that is, the maximum `epoch` column value in the `ndb_apply_status` table—as the user variable `@LATEST_EPOCH` (emphasized):

   ```
   SELECT @LATEST_EPOCH:=MAX(epoch)
       FROM mysql.ndb_apply_status;
   ```

10. Find the latest binary log file (`@FIRST_FILE`) and position (`Position` column value) within this file that correspond to `@LATEST_EPOCH` in the `ndb_binlog_index` table:

   ```
   SELECT Position, @FIRST_FILE:=File
       FROM mysql.ndb_binlog_index
       WHERE epoch > @LATEST_EPOCH ORDER BY epoch ASC LIMIT 1;
   ```

11. Using [**mysqlbinlog**](mysqlbinlog.html), replay the binary log events from the given file and position up to the point of the failure. (See [Section 4.6.9, “mysqlbinlog — Utility for Processing Binary Log Files”](mysqlbinlog.html).)

 See also [Section 7.5, “Point-in-Time (Incremental) Recovery”](point-in-time-recovery.html), for more information about the binary log, replication, and incremental recovery.

