diff --git a/IBM/DB2/cl207-u7.html b/IBM/DB2/cl207-u7.html new file mode 100644 index 0000000..9243e38 --- /dev/null +++ b/IBM/DB2/cl207-u7.html @@ -0,0 +1,379 @@ + + + + + + Unit 7: Backup and Recovery - Demonstration + + + +
+

Unit 7: Backup and Recovery

+

Demonstration 1: Backup and recovery tasks using the Db2 database.

+
+ +
+
Introduction
+
+
+

This demonstration provides a comprehensive guide to performing backup and recovery tasks in the Db2 database. You will learn to configure log space, enable archive logging, create a backup image, and recover the database to a selected point in time.

+
+
+

Backup and recovery are critical tasks in database administration to ensure data integrity and availability in case of failures.

+
+
+
+ +
+
Task 1: Configure the available log space for a database
+
+
+

In this task, you will configure the database log space to handle applications with large transactions.

+
+
    +
  1. + Logon to the Linux system: +

    Logon to the Linux system using the user id inst23, with a password of ibm2blue.

    +
    ssh inst23@<hostname>
    +
  2. +
  3. + Open a Terminal Session: +

    Right-click the empty Linux desktop and select Open in Terminal.

    +
  4. +
  5. + Change to the DDL Directory: +

    Change to the directory $HOME/ddl to access the necessary files.

    +
    cd $HOME/ddl
    +
  6. +
  7. + Configure the Log Space: +

    Use the following commands to configure the log space.

    +
    db2 connect to musicdb
    +
    db2 update db cfg using logprimary 3 logsecond 1 logfilsiz 6
    +
  8. +
  9. + Check Current and Deferred Configuration: +

    Use the db2pd command to check the current and deferred configuration settings.

    +
    db2pd -db musicdb -dbcfg | grep LOG
    +
  10. +
  11. + Run SQL Command Files: +

    Run the SQL command files to simulate changes and observe the effects on the log space.

    +
    db2 force application all
    +
    db2 terminate
    +
    db2 connect to musicdb
    +
    db2 -tvf create_temp_stock.sql
    +
    db2 +C -tvf stock_insert.sql
    +
    db2 commit
    +
    db2 terminate
    +
  12. +
+
+

If the log space is insufficient, database changes will fail with the SQL0964 message indicating that the transaction log is full. Use the increase_logs.ddl file to allocate sufficient log space.

+
+
+

By completing this task, you have successfully configured the log space for the database to handle large transactions.

+
+
+
+ +
+
Task 2: Database Recovery Support with Archive Logging
+
+
+

In this task, you will configure the database for archive logging to enable more comprehensive recovery options.

+
+
    +
  1. + Configure Archive Logging: +

    Use the following commands to configure archive logging and set the appropriate log paths.

    +
    cd $HOME/ddl
    +
    db2 connect to musicdb
    +
    db2 UPDATE DATABASE CONFIGURATION USING logarchmeth1 "DISK:$HOME/archive" logprimary 3 logsecond 10 logfilsiz 1000
    +
    db2 connect reset
    +
    db2 force application all
    +
    db2 terminate
    +
    db2 deactivate database musicdb
    +
    db2 BACKUP DATABASE MUSICDB TO $HOME/backups encrypt
    +
  2. +
+
+

Switching from circular logging to archive logging requires an offline database backup to establish the starting point for archival logging.

+
+
+

By completing this task, you have successfully configured the database for archive logging, allowing for more comprehensive recovery options.

+
+
+
+ +
+
Task 3: Generate multiple sets of table changes noting the point in time for each change
+
+
+

In this task, you will perform multiple sets of changes to the database and record the time for each set to facilitate point-in-time recovery.

+
+

Option 1: Use the Db2 command line processor

+
    +
  1. + Run the SQL Script: +

    Execute the stock_insert2.sql script to make changes and note the current time.

    +
    cd $HOME/ddl
    +
    db2 connect to musicdb
    +
    db2 -tvf stock_insert2.sql
    +
  2. +
  3. + Record Results: +

    Record the current table size and the local date and time from the SQL result.

    +
      +
    • Current Table size: ____________ (result 1)
    • +
    • Local date: _____________ (result 1)
    • +
    • Local time: _____________ (result 1)
    • +
    +
  4. +
  5. + Run the Script Again: +

    Execute the script a second time to generate another set of logged changes.

    +
    db2 -tvf stock_insert2.sql
    +
  6. +
  7. + Record Results: +

    Record the current table size and the local date and time from the SQL result.

    +
      +
    • Current Table size: ____________ (result 2)
    • +
    • Local date: _____________ (result 2)
    • +
    • Local time: _____________ (result 2)
    • +
    +
  8. +
+

Option 2: Use the Data Server Manager tool

+
    +
  1. + Run the SQL Script: +

    Use DSM to execute the stock_insert2.sql script and note the results.

    +
    Script > Open from Client > Browse > stock_insert2.sql
    +
  2. +
  3. + Record Results: +

    Record the current table size and the local date and time from the SQL result.

    +
      +
    • Current Table size: ____________ (result 1)
    • +
    • Local date: _____________ (result 1)
    • +
    • Local time: _____________ (result 1)
    • +
    +
  4. +
  5. + Run the Script Again: +

    Execute the script a second time to generate another set of logged changes.

    +
    Run SQL > Run All
    +
  6. +
  7. + Record Results: +

    Record the current table size and the local date and time from the SQL result.

    +
      +
    • Current Table size: ____________ (result 2)
    • +
    • Local date: _____________ (result 2)
    • +
    • Local time: _____________ (result 2)
    • +
    +
  8. +
+
+

Accurate recording of times and results is crucial for successful point-in-time recovery.

+
+
+

By completing this task, you have successfully generated multiple sets of table changes and recorded the times for each set.

+
+
+
+ +
+
Task 4: Recover the database to a specific point in time
+
+
+

In this task, you will use the RECOVER DATABASE command to restore the database to a specific point in time based on the recorded times from the previous task.

+
+
    +
  1. + Prepare for Recovery: +

    Terminate active sessions and prepare the database for recovery.

    +
    db2 terminate
    +
    db2 force application all
    +

    Wait about 1 minute before performing the recover command to allow the database to shut down.

    +
  2. +
  3. + Recover the Database: +

    Use the RECOVER DATABASE command to restore the database to the recorded time of the first execution of the SQL script.

    +
    db2 recover database musicdb to yyyy-mm-dd-hh.mm.ss
    +
  4. +
  5. + Verify Recovery: +

    Connect to the database and check the row count in the TEMP_STOCK table to verify recovery.

    +
    db2 connect to musicdb
    +
    db2 "select count(*) from music.temp_stock"
    +
    db2 terminate
    +
  6. +
+
+

Ensure that the recovery target time value is specified correctly in the format yyyy-mm-dd-hh.mm.ss.

+
+
+

By completing this task, you have successfully recovered the database to a specific point in time, verifying the recovery by checking the row count in the TEMP_STOCK table.

+
+
+
+ +
+
Conclusion
+
+
+

This demonstration has provided a comprehensive guide to performing backup and recovery tasks in the Db2 database. By following the tasks and best practices outlined, you have gained hands-on experience with configuring log space, enabling archive logging, creating a backup image, and performing point-in-time recovery, enhancing your database administration skills.

+
+
+
+ + + +