You are on page 1of 21

Information Management Ecosystem Partnerships

IBM Canada Lab


Summer/Fall 2010

DB2 Backup and Recovery

Information Management

2010 IBM Corporation

Information Management

Why Backup my Data?

Backing up data is vital for businesses


Lost information can cause a major crisis or
worse, lead to business failure.

Common problems:
System outage
Power failure
Hardware failure
Transaction failure
Users may inadvertently corrupt the database
Media failure
Disk drive becomes unusable
Disaster
Database facility damaged by fire, flooding
or other catastrophe

DB2 backup and recovery methods are designed to


help you keeping your information safe!

2010 IBM Corporation

Information Management

Basic Concept of Database Backup and Recovery

At t1, a database backup operation is performed

At t2, a problem that damages the database occurs

At t3, all committed data is recovered

Database
at
t1

Database
at

logs

t1

Database continues to
process transactions.
Transactions are
recorded in log files

t1
Perform a
database
backup

database
Backup

After restore, reapply the


transactions committed
between t1 and t2 using the
log files.

t2
Disaster strikes, Database
is damaged

t3
Perform a database restore
using the backup image. The
restored database is
identical to the database at
t1

Image

2010 IBM Corporation

Information Management

DB2 Transaction Logs

Keep track of changes made to database objects and their data

During the recovery process, DB2 examines these logs and decides which
changes to redo or undo

Can be stored in files or on raw devices


DB2 Memory (in RAM)

The transactions in the log


buffer are recorded in the
log device upon one of the
following events:
Log buffer is full
Number of commits
reach MINCOMMIT value
One second has lapsed

Package cache
Update
transaction

Log Buffer
Update
transaction

Bufferpool
Page indexes

Old
transactions

Information to be
updated is retrieved from
disk (if needed)

Disk for the


database

Disk for 2010 IBM Corporation


logs

Information Management

Log File States

Active logs
Transactions that have not been committed or rolled back

Online archive logs


Committed and externalized logs in the active log directory

Offline archive logs


Committed and externalized logs in a separate repository
DB2 Memory (in RAM)
Package cache
Update
transaction

Log Buffer
Update
transaction

OFFLINE Archive Logs

Bufferpool
Page
indexesto be
Information

Old
transactions

updated is retrieved
from disk (if needed)

Disk for
the
database

Active
Log
Directory

2010 IBM Corporation

Information Management

Circular Logging

Primary log files used to record all transactions; reused when transactions are
committed

Secondary log files allocated when next primary log file is not available due to active
transactions

If both primary and secondary log limit are full and can not be reused, a log full
condition occurs and SQL0964C error message is returned

Only full, offline backups of the database are allowed

Cannot have roll-forward recovery

Transactions

DB2 Server

Active log path

1
2

Active log
file
6

Primary
logs

3
4

Secondary logs
2010 IBM Corporation

Information Management

Archival Logging

Enable with LOGARCHMETH1 database configuration parameter

History of log files is maintained, in order to allow roll forward recovery


and online backup

Logs can be optionally archived to an archive location when no longer


active to avoid exhaustion of log directory

When all preallocated log files are


filled,more log files are allocated
and used.
Filled log files may be moved to a
different storage location
ONLINE ARCHIVE
Contains information for
committed transactions.
Stored in the ACTIVE
log subdirectory.

ACTIVE Contains information


for non-committed transactions.

Archive Log Directory


7

Active Log Directory


2010 IBM Corporation

Information Management

Infinite Logging

Infinite logging provides infinite active log space


Enabled by setting LOGSECOND to -1

Secondary log files are allocated until the unit of work commits or
storage is exhausted

Archived logs can hinder performance for rollback and crash


recovery

Database must be configured to use archival logging

Up to 256 log files (primary + secondary)

Control parameters
NUM_LOG_SPAN number of log files an active transaction can
span
MAX_LOG Percentage of active primary log file space that a
single transaction could consume

2010 IBM Corporation

Information Management

Database Backup

Copy of a database or table space


User data
DB2 catalogs
All control files, e.g. buffer pool files,
table space file, database configuration
file

Backup modes:
Offline Backup
Does not allow other applications or processes to access
the database
Only option when using circular logging
Online Backup
Allows other applications or processes to access the
database
Available to users during backup
Can backup to disk, tape, TSM and other storage vendors
2010 IBM Corporation

Information Management

Database Backup Syntax


db2 backup database <db_name> <online> to <dest_path>

Online backup example


db2 backup database mydb online to /home/db2inst1/backups

Offline backup example


db2 backup database mydb to /home/db2inst1/backups

10

2010 IBM Corporation

Information Management

Database Backup File Naming Convention

Alias

Instance

Catalog Node

Year

Day Minute Sequence

SAMPLE.0.DB2INST.NODE0000.CATN0000.20100314131259.001
Type

Node

Month

Hour Second

Backup Type:
0 = Full Backup
3 = Tablespace Backup

11

2010 IBM Corporation

Information Management

Table space Backup

Enables user to backup a subset of database

Multiple table spaces can be specified

Table space backup can run in both online and offline backup

Table space can be restored from either a database backup or table


space backup of the given table space

Use the keyword TABLESPACE to specify table spaces

db2 backup database mydb1 TABLESPACE (TBSP1) ONLINE to


/home/db2inst1/backup

12

2010 IBM Corporation

Information Management

Incremental Backups
Sunday

Fu
ll

Fu
ll

13

Mon

Tue

Wed

Thu

Fri

Sat

Cumulative
Backups

Delta
Backups

Sunday

Fu
ll

Fu
ll

Incremental (a.k.a. cumulative) - Backup of all database data that has changed since the
most recent, successful, full backup operation

Incremental Delta - Backup of all database data that has changed since the last
successful backup (full, incremental, or delta) operation.

Need to have TRACKMOD database configuration parameter ON

Supports both database and table space backups.

Suitable for large databases, considerable savings by only backing up incremental


changes.
2010 IBM Corporation

Information Management

Database Backup Compression

DB2 backups can now be automatically compressed


Significantly reduce backup storage costs

Performance characteristics
CPU costs typically increased (due to compression computation)
Media I/O time typically decreased (due to decreased image size)
Overall backup/restore performance can increase or decrease; depending
on whether CPU or media I/O is a bottleneck

Example:
db2 backup database DS2 to /home/db2inst1/backups compress

14

2010 IBM Corporation

Information Management

Automatic Database Backup

Simplifies database backup management tasks for the DBA


by always ensuring that a recent full backup of the database
is performed as needed

To configure automatic backup


Graphical user interface tools
Configure Automatic Maintenance
wizard

Command line interface


auto_db_backup
auto_maint

Stored procedure
AUTOMAINT_SET_POLICY system stored procedure
15

2010 IBM Corporation

Information Management

Optimizing Backup Performance

16

DB2 automatically configures these parameters for performance


Parallelism
Number of table spaces backed up in parallel
num_buffers
Number of buffers used
Use at least twice as many buffers as backup targets (or
sessions) to ensure that the backup target devices do not have to
wait for data.
Buffer
Backup buffer size

Allocate more memory to backup utility by increasing utility heap size


(UTIL_HEAP_SZ) configuration parameter.

Backup subset of data where possible:


Table space backups
Incremental backups

Use multiple target devices

2010 IBM Corporation

Information Management

Database Recovery

Recovery is the rebuilding of a database or


table space after a problem such as media
or storage failure, power interruption, or
application failure.
Types of Recovery

Crash or restart recovery


Protects the database from being left inconsistent (power
failure)
Roll forward recovery
Extends recovery by using full database and table space
backup in conjunction with the database log files

17

2010 IBM Corporation

Information Management

DB2 Restore Utility

Restore utility is the complement of backup utility

Restores database or table space from a previously taken


backup

TAKEN AT - Specify the time stamp of the database backup


image. Backup image timestamp is displayed after
successful completion of a backup

Without prompting Overrides any warnings.


Example:
SAMPLE.0.DB2INST.NODE0000.CATN0000.20080718131210.001
RESTORE DATABASE dbalias FROM <db_path> TAKEN AT 20080718131210

18

2010 IBM Corporation

Information Management

Table space Restore Operation

19

Restored table space is in Roll Forward Pending state and can be either
rolled forward to End of Logs or a Point In Time.
In case of Point in Time roll forward, table space must be rolled forward to
at least the minimum Point in Time

Minimum recovery time can be checked using


db2 list tablespaces show detail

User table space must be in line with catalog table space


e.g if catalog indicates table T1 exists in table space TSP1, table T1 must
exist in the TSP1 table space, otherwise database becomes inconsistent

Every time there is a DDL changed, minimum recovery time for the table
space is revised to indicate the last DDL change.

Recommended to take a table space backup after a table space has been
restore to a point in time.

Transactions that came after the point in time are lost, therefore take a
table space backup as new point of reference for future recoveries.

2010 IBM Corporation

Information Management

Incremental Restore

20

Restore a database with incremental backup images

AUTOMATIC (recomended) - All required backup images will be applied


automatically by restore utility

MANUAL User applies the required backups manually


db2ckrst can provide the sequence for applying backups

ABORT - aborts an in-progress manual cumulative restore

RESTORE DATABASE sample INCREMENTAL AUTOMATIC FROM /db2backup/dir1;

ROLLFORWARD DATABASE sample TO END OF LOGS AND COMPLETE;

2010 IBM Corporation

Information Management Ecosystem Partnerships


IBM Canada Lab

Questions?

Summer/Fall 2010

E-mail: imschool@us.ibm.com
Subject: DB2 Academic Workshop

Information Management

2010 IBM Corporation

You might also like