Backing up the DB2® database

You should back up the database on a regular basis to protect your data. Each backup is the copy of the entire database that can be restored in the case of corruption or malfunction.

Before you begin

  • Users

    To perform the backup, log in as the database instance owner.

  • Space requirements

    Ensure that enough storage space is available in the target directory. The backup file size depends on the number of computers that report to BigFix Inventory, and the amount of historical data that is stored in the database. Therefore, you cannot estimate the exact size of the backup file.

    The backup file size can reach:
    • 2GB or more in the environments that consist of less than 100 computers.
    • 50GB for 30000 computers.
    • 75GB for 100000 computers.

    You can use compression to significantly reduce the backup size.

Creating offline backups

You should back up the database on a regular basis to protect your data. Each backup is the copy of the entire database that can be restored in the case of corruption or malfunction. Choose offline backups if you can afford to deactivate the database during each backup.

About this task

During an offline backup, the entire database is copied to a file. Since the database must be deactivated during each backup (no active transactions), the backup file contains all transactions performed on the database so far. Therefore, the backup file is not dependent on transaction logs, and the database can use the default circular logging, in which transaction logs are overwritten with new transactions, which saves the disk space. To restore the database, you only need the backup file.

Procedure

  1. Stop the BigFix Inventory server.
  2. Terminate the connections and deactivate the database.
    Note: TEMADB is the default database name. If you are unsure whether it applies to your database, see: Checking the database name.
    db2 terminate
    db2 deactivate db TEMADB
    
    DB20000I  The TERMINATE command completed successfully.
    DB20000I  The DEACTIVATE DATABASE command completed successfully.
  3. Make a full offline backup. The entire database is copied to a backup file in the specified location.
    db2 backup database TEMADB to <location>
    Backup successful. The timestamp for this backup image is : xxxxxxxxxxxx
  4. Verify that the backup file was correctly created.
    db2ckbkp <backup file>
    Image Verification Complete - successful.
  5. Activate the database and restart the BigFix Inventory server to restore its connection to the database.
    db2 activate db TEMADB
    /etc/init.d/BFIserver restart
  6. If DB2 is shared with the BigFix server, restart the BigFix server to restore its connection to the database.
    For more information, see: Starting and stopping the BigFix server.

Creating online backups

Choose online backups if you back up your database frequently and cannot afford to deactivate it for each backup. Online backups allow you to maintain all connections to the database, but they require more disk space to store the history of transaction logs.

About this task

During an online backup, the entire database is copied to a file, but it might not contain transactions that were being performed on the database while the backup was being created. Therefore, the backup file must always be complemented with transaction logs to restore the database to the consistent state. Transaction logs are backed up automatically after enabling archive logging, and must always be stored in a safe location together with the backup file. After you restore the database from the backup file, you add the archive logs, and the database is complete. Enabling the archive logging for the first time requires that you deactivate the database.

Procedure

  1. Set up archive logging.
    Note: TEMADB is the default database name. If you are unsure whether it applies to your database, see: Checking the database name.
    1. Check the status of archive logging in your database. If the first archive method contains a value other than OFF, you can omit the following steps and make an online backup.
      db2 get db cfg for TEMADB | grep LOGARCHMETH
      First log archive method                 (LOGARCHMETH1) = OFF
      Second log archive method                (LOGARCHMETH2) = OFF
    2. Create a backup directory that will be used to store archive logs and online backups, and give it proper permissions.
      mkdir /var/online_backup
      chown db2inst1:db2iadm1 /var/online_backup
    3. Update the database configuration to enable archive logging and point to the new directory.
      db2 update database configuration for TEMADB using LOGARCHMETH1 'disk:/var/online_backup'
      DB20000I  The UPDATE DATABASE CONFIGURATION command completed successfully.
      The status of archive logging settings also changed to a specific path:
      First log archive method                 (LOGARCHMETH1) = DISK:/var/online_backup/
    4. Terminate the connections and deactivate the database.
      db2 force application all
      db2 deactivate db TEMADB
      
    5. Make a full offline backup.
      db2 backup database TEMADB to <location>

      Creating an offline backup is a requirement after enabling the archive logging. Although you will not need to create offline backups later, it is a good practice to create them before major changes to the database. The archive logs can be applied in the same way both to offline and online backups to restore them to the most recent state. You can store this offline backup in a safe location as an extra precaution.

    6. Activate the database and restart the BigFix Inventory server to restore its connection to the database.
      db2 activate db TEMADB
      /etc/init.d/BFIserver restart
    7. If DB2 is shared with the BigFix server, restart the BigFix server to restore its connection to the database.
      For more information, see: Starting and stopping the BigFix server.
  2. Make an online backup.
    db2 backup database TEMADB online to /var/online_backup/ compress include logs
    Backup successful. The timestamp for this backup image is : xxxxxxxxxxxx
    Whenever you create an online backup, all archive logs created up to this point are no longer needed. To restore a complete database, you need a backup file and subsequent archive logs.
  3. Verify that the backup file was correctly created.
    db2ckbkp <online backup file>
    Image Verification Complete - successful.