Restoring Db2 Warehouse by using commands

This process restores a database that was backed up by using the db2 backup command. The restored database starts back the same state that it was in when the backup was made.

Before you begin

  • You must have an existing Db2 Warehouse backup that is accessible on the Cloud Pak for Data system.
  • You must identify the Db2 Warehouse catalog node and data nodes and have an SSH connection open to each node.
Note: The following commands use the environment variable containing the default database name: ${DBNAME}.

About this task

Note: If your backup and restore strategy is based on full offline backup images, you can use a provided script for restoring instead of using the process in this topic. These commands are only applicable when you are restoring from a Db2 Warehouse backup in Cloud Pak for Data at a similar version. Otherwise, further commands are required, as detailed in Restoring data. For most restore operations, the best practice is to use the procedure in Restoring Db2 Warehouse from an offline backup using the restore script.

For a Db2 Warehouse deployment, the db2 restore command can be started only from the catalog node but each available multiple logical node (MLN) participates in the restore operation.

Restriction: A full database restore operation can be run only in offline mode.

Procedure

  1. From a bash shell on each of the nodes specified in the db2nodes.cfg file, switch to the database instance owner. Confirm that the directory that contains the database backup exists and is mounted. For example:
    su - db2inst1
    cd /backup_dir/backup_nnn
    Where backup_dir is the directory that you create to hold backup images and nnn is an incremental value that was used to put each backup in a separate subdirectory. The backups can be in any directory on the cluster that is shared by the container nodes and has sufficient space to hold the backups. If you restore a backup from a different directory location, alter these commands as necessary.
  2. Temporarily disable the built-in HA:
    sudo wvcli system disable -m "Disable HA before Db2 maintenance"
  3. Connect to the database:
    db2 connect to ${DBNAME}
  4. On the catalog node, find all the applications that are connected to Db2 Warehouse:
    db2 list applications
    This command returns a list of all currently connected applications. You can either stop all the connections by closing the applications, or you can enter the following command to disconnect all connections:
    db2 force application all
  5. Issue the terminate database command:
    db2 terminate
  6. Stop the database:
    db2stop force

    Ensure that the command completes on all nodes.

  7. Ensure that all Db2 interprocess communications are cleaned for the instance:
    ipclean -a
  8. Turn off all communications to the database by setting the value of the DB2COMM variable to null:
    db2set -null DB2COMM
  9. Restart the database in restricted access mode:
    db2start admin mode restricted access
  10. Run the restore operation:
    1. On the catalog node, run the following command:
      db2_all "<<+0<db2 RESTORE DATABASE ${DBNAME} FROM backup_dir TAKEN AT backup_image_timestamp INTO ${DBNAME} REPLACE EXISTING WITHOUT ROLLING FORWARD"

      Where backup_dir is the full path to the directory where your backup images are located, and backup_image_timestamp is the associated timestamp on those backup image files. The timestamp is displayed after successful completion of a backup operation, and is part of the path name for the backup image.

    2. If your database is deployed on two or more nodes, run the offline restore operation on each of the other data nodes with the command:
      db2_all "<<-0<db2 RESTORE DATABASE ${DBNAME} FROM backup_dir TAKEN AT backup_image_timestamp INTO ${DBNAME} REPLACE EXISTING WITHOUT PROMPTING"
  11. Stop the database:
    db2stop force

    Ensure that the command completes on all nodes.

  12. Ensure that all Db2 interprocess communications are cleaned for the instance:
    ipclean -a
  13. Reinitialize the Db2 Warehouse communication manager to accept database connections:
    db2set DB2COMM=TCPIP,SSL
  14. Restart the database for normal operation:
    db2start
    The offline database restore operation is complete.
  15. Activate the database:
    db2 activate db ${DBNAME}
  16. Re-enable the Wolverine high availability monitoring process:
    wvcli system enable -m "Enable HA after Db2 maintenance"
  17. Connect to the database:
    db2 connect to ${DBNAME}

What to do next

For more information about advanced command options, see the RESTORE DATABASE command