1.6 - DB2 Backup and Recovery - DWOP - v20120416

Published on October 2021 | Categories: Documents | Downloads: 1 | Comments: 0 | Views: 100
of 28
Download PDF   Embed   Report

Comments

Content

 

Information Management Technology Ecosystem

DB2 ®  Backup and Recovery

Information Management

 © 2012 IBM Corporation

 

Information Management Technology System

Agenda 

Why back up data



Basic backup and recovery concept



Logging Log file states Logging types Infinite logging db2cklog – – – –



Backup Backup modes Partitioned database Table spaces Incremental backup db2ckbkp – – – – –



Recovery Recovery types –



Restore Table space restore Incremental restore – – –

2

Redirected restore  © 2012 IBM Corporation

 

Information Management Technology System

Why Backup 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 –

• •



Transaction failure •



Users may inadvertently corrupt the database

Media failure •



Power failure Hardware failure

Disk drive becomes unusable

DB2

Disaster Database facility damaged by fire, flooding or •

other catastrophe 

3

DB2 backup and recovery methods are designed to help you keeping your information safe!  © 2012 IBM Corporation

 

Information Management Technology System

Basic Concept of Backup and Recovery 

Process of making copies of data and which may be used to restore the original in case of failure or loss of data –

E.g. At t1, a database backup operation is performed At t2, a problem that damages the database occurs At t3, all committed data is recovered • • •

logs

After restore, reapply the transactions committed between t1 and t2 using the log files.

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

4

time 

t1

t2

t3

Database backup was performed

Disaster strikes, database is damaged

Database recovery is performed

 © 2012 IBM Corporation

 

Information Management Technology System

DB2 Database Logging 

Keep track of changes made to database objects and data



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

Key element of any high availability strategy



Can be stored in files or on devices

 

Log records are written to disk when one of the following occurs: Log buffer is full; A transaction commits; A group of transactions commit, as defined by the  mincommit value – – – – –

Deprecated in DB2 10

5

 © 2012 IBM Corporation

 

Information Management Technology System

Log File States 

Active logs Contain at least 1 transaction that has not been committed or rolled back –



Online archive logs Contain committed and externalized transactions in the active log directory –



Offline archive logs Contain committed and externalized transactions in a separate repository –

Package Cache Update transaction

Buffer Pool Page Index

DB2 Memory     h  e   t     o   g   t   f  e  r   n   i   i  t   b  u  f      W  r  g    l  o

6

Offline archive logs

Update transaction

Old transactions

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

Disk for the database

Log Buffer

Disk for logs Active and online archive logs

 © 2012 IBM Corporation

6

 

Information Management Technology System

Key Logging Configuration Parameters ■

LOGPRIMARY

 – number of primary log log files to be pre-allo pre-allocated cated in the active logs directory ■

LOGSECOND

 – number of secondary secondary log files that are cre created ated and used for reco recovery very log files (only as needed). ■

LOGBUFSZ (Log Buffer Size)

 – amount of the database database heap (defined by DBHEAP parameter) to use as a buffer for log records before writing these records to disk ■

LOGFILSIZ (Log File Size)

 – size of each primary primary and seconda secondary ry log file in unit o off 4KB pages. ■

LOGPATH and NEWLOGPA  NEWLOGPATH TH

 – LOGPATH is the default active lo log g directory  – Changed to a user defined defined location using using NEWLOGPATH. ■

FAILARCHPATH (Failover log archive path)

 – Specifies a third third target to archive log log files if the primary primary and secondary archival paths fail 7

 © 2012 IBM Corporation

 

Information Management Technology System

Log Loggin ging g Typ Types es – Cir Circul cular ar 

  Ring  of online primary logs provide version recovery in case of failure Secondary logs used when next primary log is not available –



Default logging for DB2 –

DB configuration parameters logarchmeth1 and logarchmeth2 are set to OFF



Only full, offline database backups are allowed Only ensures integrity of current transactions –

transactions

database log path 1

2

primary logs

secondary logs

active logs

3

8

4

1

n

 © 2012 IBM Corporation

 

Information Management Technology System

Loggin Logg ing g Type Type – Ar Arch chiv ive e 

Maintain a history of log files –

Enable with LOGARCHMETH1 DB configuration parameter •







LOGRETAIN and USEREXIT have been discontinued in DB2 10. They have been replaced with LOGARCHMETH1.

Allows roll-forward recovery or online backup

Logs can be archived externally when no longer active to avoid exhaustion of log directory As of DB2 10.1, archived log files can be compressed

Active Log Directory

When all pre-allocated log files are filled, more log files are allocated and used.

New in DB2 10.1

Archive Log Directory

ONLINE ARCHIVE

Contains information for committed transactions. Stored in ACTIVE log subdirectory

ACTIVE – Conta Contains ins information for non-committed transactions. 9

© 2012 IBM Corporation

 © 2012 IBM Corporation

 

Information Management Technology System

Infinite Logging 

Issue with limited number of logs –



A long running transaction can exhaust logs allocation, even after secondary log files are allocated The number of primary and secondary log files must comply: •





If logsecond does not have a value of -1, (logprimary + logsecond  ) <= 256. 256.

Solution: Infinite Logging



No limit on the size or the number of in-flight transactions running



Enabled by setting logsecond to -1



Database must be configured to use archive logging –



Can hinder performance for rollback and crash recovery

Other control parameters •



10

If logsecond has a value of -1, logprimary <= 256. 256.

num_log_span: number of log files an active transaction can span  max_log: percentage of the primary log space that a transaction can consume

 © 2012 IBM Corporation

 

Information Management Technology System

DB2CKLOG DB2CKL OG - DB2 CHE CHECK CK LOG LOG ■

Check the validity of archive log files  – Determine whether the log log files can be used used during roll-forward recovery recovery  – A single archive archive log file or a range of archive log file files s can be checked DB2CKLOG log_num  ARCHLOGPATH  ARCHLOGPATH  path DB2CKLOG log_num  to log_num2

Validating a range of logs: $ db2cklog 3 to 5

Successful Validation

11

 © 2012 IBM Corporation

 

Information Management Technology System

Recovery History File 

Purpose In addition to recovery log files, files, the recovery history file is also created automatically when a database is created. Used to recover all or part of a database to a point in time using the summarized backup information in this file View To see the entries in the recovery history file: –







LIST HISTORY



OR 

SELECT * FROM TABLE(DB_HISTORY() TABLE(DB_HISTORY()) ) AS LIST_HISTORY

Pruning Recovery history file cannot be directly modified, but entries that are no –

longer relevant can be pruned from the file using command PRUNE HISTORY

12

 © 2012 IBM Corporation

 

Information Management Technology System

Database Backup ■

Copy of a database or table space  –User  – User data  –DB2  – DB2 catalogs  –All  – All control files, e.g. buffer pool ffiles, iles, table space file, database configuration file



Backup modes: Offline Backup  – Offline • Does not al allow low othe otherr applica applications tions o orr proces processes ses to ac access cess th the e database • Only option when using circul circular ar llogging ogging  – Online Online Backup • Allow Allows s other a applicat pplications ions or p proces rocesses ses to a access ccess the database • Ava Availa ilable ble tto o user users s dur during ing b back ackup up • Can back backup up to di disk, sk, ta tape, pe, TS TSM M and oth other er sto storage rage ve vendors ndors

13

 © 2012 IBM Corporation

 

Information Management Technology System

Database Backup 

Command-line:



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



Online backup example

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

Offline backup example



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



IBM Data Studio: 1. 2. 3.

Connect to target database Right click on database Select “B “Back Up and Restore” re” then “Back Up”

14

 © 2012 IBM Corporation

 

Information Management Technology System

Database Backup Database Backup – File Nami Naming ng Conve Convention ntion

Alias

Instance

Year

Day Minute Sequence

SAMPLE.0.DB2INST.DBPART000.20120 SAMPLE.0.DB2IN ST.DBPART000.20120114131259.001 114131259.001

Type

Partition

Backup Type: 0 = Full Backup 3 = Tables Tablespac pace e Backup Backup 4 = backup image generated by the LOAD COPY TO command

Month

Hour Second

15

 © 2012 IBM Corporation

 

Information Management Technology System

Backing Up Partitioned Databases 

There are four possible ways: –



Back up each database partition one at a time Use the db2_all command • Back Backup up spec specif ifie ied d part partit itio ions ns



Run a single single syste system m view – SSV (Rec (Recommen ommended) ded) • • • • •

Some Some or all all of the data databas base e partit partition ions s simult simultane aneou ously sly Data Databa base se can can be be onl onlin ine e or or off offlin line e Use the ON DBPARTITIONNUMS parameter to specify the partitions Log Log file files s are are incl includ uded ed by defa defaul ultt Ol Old d bac backu kup p ima image ges s can can be dele delete ted d

 – Use backup task assistant in IBM Data Studio db2 backup database mydb1 ON ALL DBPARTITIONNUMS db2 backup database mydb1 ON DBPARTITIONNUMS (2,4)

16

 © 2012 IBM Corporation

 

Information Management Technology System

Table Space Backup 













Enables user to backup a subset of database Multiple table spaces can be specified ve log loggin ging g Database must be using archi archive 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 Supporte Sup ported d in DB2 pureSca pureScale le environ environment ment db2 backup database mydb1 TABLESPACE (TBSP1) ONLINE to /home/db2inst1/backup

17

 © 2012 IBM Corporation

 

Information Management Technology System

Incremental Backups







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 ha s changed since the last successful backup (full, incremental, or delta) d elta) operation. Requires TRACKMOD database configuration parameter set to ON Supports both database and table space backups. b ackups. –



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

18

 © 2012 IBM Corporation

 

Information Management Technology System

Dat Databa abase se Backu Backup p – Com Compre pressi ssion on 

DB2 backups can 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

E.g. –

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

19

 © 2012 IBM Corporation

 

Information Management Technology System

Automatic Database Backup 

Simplifies database backup management tasks for the DBA



Ensures that the database is backed up both properly and regularly



To configure automatic backup  –  DB configuration parameters • AU AUTO TO_D _DB_ B_BA BACK CKUP UP • AU AUTO TO_ _MA MAIN INT T

Graphical  – G raphical user interface tools • Dat Data a St Studi udio’s o’s ““Ba Backu ckup p Tas Task k • Assistant”

System  – S ystem stored procedure

• AUT AUTOMA OMAINT INT_SE _SET_P T_POLI OLICY CY

20

 © 2012 IBM Corporation

 

Information Management Technology System

Optimizing Backup Performance 







During a backup operation, DB2 automatically chooses an optimal value for:  – PARALLELISM n • Numb Number er of ta table ble sp spaces aces back backed ed up in pa paralle rallell  WITH num_buffers BUFFERS  –  • Nu Numb mber er o off bu buffe ffers rs u use sed d • Us Use e at le leas astt twi wic ce as many buff ffe ers as backup targets (or sessions) to ensure that the backup target devices do not have to wait for data.  – Buffer   buffer-size • Ba Back ckup up bu buff ffer er s siz ize e 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 backups  – Incremental backups backups iple e ta targ rget et devices Use mult multipl

21

 © 2012 IBM Corporation

 

Information Management Technology System

DB DB2C 2CKB KBKP KP – Ch Chec eck k Backu Backup p 

This utility can be used to test the integrity of a backup image  – display determine thestored image imageincan restored.  – thewhether meta-data meta-data thebe ba backup ckup header. $ db2ckbkp -h SAMPLE.0.moba.NODE0000.CATN0000.2004 SAMPLE.0.moba.NODE0000.CATN0000.20041008013428.001 1008013428.001 ===================== MEDIA HEADER REACHED: ===================== Server Server Databas Database e Name Server Server Databas Database e Alia Alias s Client Client Databas Database e Alia Alias s Timesta Timestamp mp Databas Database e Partiti Partition on Number Number Inst Instanc ance e Sequenc Sequence e Number Number

--------

Rele Release ase ID -Databas Database e Seed Seed -DB Comment's Codepage (Volume)-DB Comment (Volume) -DB Comment's Codepage (System)-DB Comment (System) -Authent Authentica ication tion Value Value -Back Backup up Mode Mode -Incl Include udes s Logs Logs Compres Compressio sion n ・・・(略)・・・

SAMPLE SAMPLE SAMPLE SAMPLE SAMPLE SAMPLE 2004100 2004100801 8013428 3428 0 moba moba 1 A00 A00 92DBF20 92DBF20F F 0

This backup is an online backup with INCLUDE LOGS option 0: Not included in the log file 1: contains log file

0 255 1

-- 1 -- 0

Backup is not compressed 0: not compressed 1: compressed

22

 © 2012 IBM Corporation

 

Information Management Technology System

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 Crash or restart recovery • Protects Protects th the e datab database ase fr from om being lleft eft inc inconsis onsistent tent  – Version Version recovery • Restor Restores es a sna snapsh pshot ot of th the e data databas base e  – Roll Roll forward recovery • Extends Extends vers version ion recov recovery ery by usi using ng full dat database abase and ttable able 

space backup in conjunction with the database log files Crash recovery and Version recovery are enabled in DB2 by default

23

 © 2012 IBM Corporation

 

Information Management Technology System

DB2 Restore Utility 



Restores database or table space from a previously taken backup Invoked using:  – The Restore Database command  – The db2Restore API  – IBM Data Studio Restore task assistant



TAKEN AT - Specify the time stamp of the database backup image



Wi Witho thout ut pr prom ompti pting ng –  – Overrides Overrides any warnings

 – Example:  –  Example:

– SAMPLE.0.DB2INST.DBPART000. SAMPLE.0.DB2INST.DBPART000.20120114131259 20120114131259.001 .001



RESTOR RES TORE E DATA DATABAS BASE E dbal dbalias ias FRO FROM M <db_ <db_pat path> h> TAKEN TAKEN AT 20120114131259

24

 © 2012 IBM Corporation

 

Information Management Technology System

Table Space Restore Operation 

Table space restore occurs in offline and online mode Other table spaces can be used concurrently while restore in progress –







Restored table space is in Roll Forward Pending state  –can  – can be either rolled forward to End of Logs or a Point In Time. Minimum recovery time can be checked using  – db2 db2 list list tab table lesp spac aces es sh show ow det detai ail l User table space must be in line with catalog table space  –E.g:  – E.g: if catalog indicates table T1 exi exists sts in table space TSP1, table T1 must exist in the TSP1 table space, otherwise database becomes inconsistent



Recommended to take a table space backup after restore to a Point In Time Transactions that come after the point in time are lost backup required as new point of reference for future recoveries –



25

 © 2012 IBM Corporation

 

Information Management Technology System

Incremental Restore 







Restore a database with incremental backup images AUTOMATIC (recommended) - All required required bac backup kup imag images es will be ap applied plied automatically by restore utility MANUAL – backups manually MANUAL – User applies the required backups  – db2ckrst  –  db2ckrst can provide the sequence for applying backups aborts an in-progr in-progress ess manual manual cumulat cumulative ive resto restore re ABORT - aborts

RESTORE DATABASE sample INCREMENTAL AUTOMATIC FROM /db2backup/dir1; ROLLFORWARD DATABASE sample TO END OF LOGS AND COMPLETE; COMPLETE;

26

 © 2012 IBM Corporation

 

Information Management Technology System

Redirected Restore 

A redirected restore operation is performed when:  – Restore a backup image to a machine that that is different than the the source machine  – Restore table space containers into a different physical location  – One or more containers containers is inaccessible  – Redefine the paths paths of a defined storage storage group



Restrictions – – –



Cannot use a redirected restore to move data from one operating system to another Cannot create or drop a storage group during the restore process Cannot modify storage group paths during a table space restore process

Two-step database restore process with an intervening table space container definition step

1) Is Iss sue RESTORE DATABASE command with REDIRECT option 2) Take o one ne of the foll followin owing g steps steps::  –  SET TABLESPACES CONTAINERS  –  SET STOGROUP PATHS

3) Iss Issue RESTORE DATABASE command with CONTINUE option

27

 © 2012 IBM Corporation

 

Information Management Technology Ecosystem

Questions? E-mail: [email protected] Subject: “DB2 10 Workshop for Oracle Professionals”

Information Management

Sponsor Documents

Or use your account on DocShare.tips

Hide

Forgot your password?

Or register your new account on DocShare.tips

Hide

Lost your password? Please enter your email address. You will receive a link to create a new password.

Back to log-in

Close