db2 Backup Restore

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 8

[db2inst1@TCS-PCM-183 ~]$ db2 create db TESTDB

DB20000I The CREATE DATABASE command completed successfully.


[db2inst1@TCS-PCM-183 ~]$ db2 connect to TESTDB

Database Connection Information

Database server = DB2/LINUXX8664 11.1.3.3


SQL authorization ID = DB2INST1
Local database alias = TESTDB

[db2inst1@TCS-PCM-183 ~]$ db2 get db cfg |grep -i log


Log retain for recovery status = NO
User exit for logging status = NO
Catalog cache size (4KB) (CATALOGCACHE_SZ) = 300
Log buffer size (4KB) (LOGBUFSZ) = 2149
Log file size (4KB) (LOGFILSIZ) = 1024
Number of primary log files (LOGPRIMARY) = 13
Number of secondary log files (LOGSECOND) = 12
Changed path to log files (NEWLOGPATH) =
Path to log files =
/db2home/db2inst1/db2inst1/NODE0000/SQL00064/LOGSTREAM0000/
Overflow log path (OVERFLOWLOGPATH) =
Mirror log path (MIRRORLOGPATH) =
First active log file =
Block log on disk full (BLK_LOG_DSK_FUL) = NO
Block non logged operations (BLOCKNONLOGGED) = NO
Percent max primary log space by transaction (MAX_LOG) = 0
Num. of active log files for 1 active UOW(NUM_LOG_SPAN) = 0
Percent log file reclaimed before soft chckpt (SOFTMAX) = 0
HADR log write synchronization mode (HADR_SYNCMODE) = NEARSYNC
HADR spool log data limit (4KB) (HADR_SPOOL_LIMIT) = AUTOMATIC(0)
HADR log replay delay (seconds) (HADR_REPLAY_DELAY) = 0
First log archive method (LOGARCHMETH1) = OFF
Archive compression for logarchmeth1 (LOGARCHCOMPR1) = OFF
Options for logarchmeth1 (LOGARCHOPT1) =
Second log archive method (LOGARCHMETH2) = OFF
Archive compression for logarchmeth2 (LOGARCHCOMPR2) = OFF
Options for logarchmeth2 (LOGARCHOPT2) =
Failover log archive path (FAILARCHPATH) =
Number of log archive retries on error (NUMARCHRETRY) = 5
Log archive retry Delay (secs) (ARCHRETRYDELAY) = 20
Log pages during index build (LOGINDEXBUILD) = OFF
Log DDL Statements (LOG_DDL_STMTS) = NO
Log Application Information (LOG_APPL_INFO) = NO

db2 update db cfg using LOGSECOND 20


DB20000I The UPDATE DATABASE CONFIGURATION command completed successfully.

db2 update db cfg using LOGPRIMARY 20


DB20000I The UPDATE DATABASE CONFIGURATION command completed successfully.
SQL1363W One or more of the parameters submitted for immediate modification
were not changed dynamically. For these configuration parameters, the database
must be shutdown and reactivated before the configuration parameter changes
become effective.

[db2inst1@TCS-PCM-183 ~]$ db2 get db cfg show detail |grep -i log


Log retain for recovery status = NO
User exit for logging status = NO
Catalog cache size (4KB) (CATALOGCACHE_SZ) = 300
300
Log buffer size (4KB) (LOGBUFSZ) = 2149
2149
Log file size (4KB) (LOGFILSIZ) = 1024
1024
Number of primary log files (LOGPRIMARY) = 13
20
Number of secondary log files (LOGSECOND) = 20
20

[db2inst1@TCS-PCM-183 ~]$ db2 deactivate db TESTDB


DB20000I The DEACTIVATE DATABASE command completed successfully.
[db2inst1@TCS-PCM-183 ~]$ db2 get db cfg show detail |grep -i log
[db2inst1@TCS-PCM-183 ~]$ db2 connect to TESTDB

Database Connection Information

Database server = DB2/LINUXX8664 11.1.3.3


SQL authorization ID = DB2INST1
Local database alias = TESTDB

[db2inst1@TCS-PCM-183 ~]$ db2 get db cfg show detail |grep -i log


Log retain for recovery status = NO
User exit for logging status = NO
Catalog cache size (4KB) (CATALOGCACHE_SZ) = 300
300
Log buffer size (4KB) (LOGBUFSZ) = 2149
2149
Log file size (4KB) (LOGFILSIZ) = 1024
1024
Number of primary log files (LOGPRIMARY) = 20
20
Number of secondary log files (LOGSECOND) = 20
20

####################################################################

Offline db2 backup

1) stop application server and kill existing db connections

db2 list applications

Auth Id Application Appl. Application Id


DB # of
Name Handle
Name Agents
-------- -------------- ----------
-------------------------------------------------------------- -------- -----
ROOT db2jcc_applica 37355 127.0.0.1.39630.210204041101
ENGDB2 1
ROOT db2jcc_applica 42591 127.0.0.1.45124.210204092559
ENGDB2 1
ROOT db2jcc_applica 36334 127.0.0.1.38968.210204031608
ENGDB2 1
ROOT db2jcc_applica 37406 127.0.0.1.44352.210204081604
ENGDB2 1

db2 "force application (37355,42591,36334,37406)"

or for single instance terminate all connections

db2 "force application all"

2) offline backup

db2 "backup db <DB NAME> compress"

db2 backup db TESTDB compress

3) offline restore

drop database

db2 drop db testdb

Note :- If you have multiple images for same db then use taken at parameter

[db2inst1@TCS-PCM-183 ~]$ db2 "restore db testdb "


SQL2522N More than one backup file matches the time stamp value provided for
the backed up database image.

source target name diff.

db2 "restore db FILHDB into TESTDB without prompting"

########## How to check backup ################


db2 list history backup all for testdb

List History File for testdb

Number of matching file entries = 2

Op Obj Timestamp+Sequence Type Dev Earliest Log Current Log Backup ID


-- --- ------------------ ---- --- ------------ ------------ --------------
B D 20210204122735001 F D S0000000.LOG S0000000.LOG
----------------------------------------------------------------------------
Contains 3 tablespace(s):

00001 SYSCATSPACE
00002 USERSPACE1
00003 SYSTOOLSPACE
----------------------------------------------------------------------------
Comment: DB2 BACKUP TESTDB OFFLINE
Start Time: 20210204122735
End Time: 20210204122736
Status: A
----------------------------------------------------------------------------
EID: 2 Location: /db2home/db2inst1
################## db2ckbkp TESTDB.0.db2inst1.DBPART000.20210204122735.001

[1] Buffers processed: ###########

Image Verification Complete - successful.

[db2inst1@TCS-PCM-183 ~]$ db2ckbkp -a


TESTDB.0.db2inst1.DBPART000.20210204122735.001 |more

=====================
MEDIA HEADER REACHED:
=====================
Server Database Name -- TESTDB
Server Database Alias -- TESTDB
Client Database Alias -- TESTDB
Timestamp -- 20210204122735
Database Partition Number -- 0
Instance -- db2inst1
Database Configuration Type -- 0 (Non-shared data)
Sequence Number -- 1
Database Member ID -- 0
Release ID -- 0x1400 (DB2 v11.1.3.3)
AL version -- V:11 R:1 M:3 F:3 I:0 SB:0
Database Seed -- 0x939564AA
DB Comment's Codepage (Volume) -- 0
DB Comment (Volume) --
DB Comment's Codepage (System) -- 0
DB Comment (System) --
Authentication Value -- 255 (Not specified)
Backup Mode -- 0 (Offline)
Includes Logs -- 0 (No)
Compression -- 0 (No Library Applied)
Backup Type -- 0 (Database-level)
Backup Granularity -- 0 (Non-incremental)
Merged Backup Image -- 0 (No)
Status Flags -- 0x1
Consistent on this member
System Catalogs in this image -- 1 (Yes)
Catalog Partition Number -- 0
DB Codeset -- UTF-8
DB Territory -- US
LogID -- 1612433494
LogPath --
/db2home/db2inst1/db2inst1/NODE0000/SQL00064/LOGSTREAM0000/
Backup Buffer Size -- 16781312 (4097 4K pages)
Number of Sessions -- 1
Platform -- 0x1E (Linux-x86-64)
Encrypt Info Flags -- 0x0

The proper image file name would be:


TESTDB.0.db2inst1.DBPART000.20210204122735.001

#################################################
db2 backup monitor

[db2inst1@TCS-PCM-183 ~]$ db2 list utilities

ID = 990599
Type = BACKUP
Database Name = TESTDB
Member Number = 0
Description = offline db
Start Time = 02/04/2021 12:40:25.735300
State = Executing
Invocation Type = User
Throttling:
Priority = Unthrottled
Progress Monitoring:
Estimated Percentage Complete = 36

db2top -d testdb ==> press small u

Hash # of Utility Utility Uti


Utility Invoker Completed Work Phase Progress
Value entries Start Time Type Pri State
Type Work Unit Prog% Start Time Description
---------- -------- --------------- --------------- ---
---------- ---------- ---------------- ------- ----- ---------------
--------------------
2122349 1 12:41:43.293106 Backup 0
Execute User 183.5M Bytes 19% 12:41:43.293119

###################################################################################
#######

incremental backup enable


db2 get db cfg |grep -i TRACK
Track modified pages (TRACKMOD) = NO

db2 update db cfg using TRACKMOD yes


DB20000I The UPDATE DATABASE CONFIGURATION command completed successfully.
SQL1363W One or more of the parameters submitted for immediate modification
were not changed dynamically. For these configuration parameters, the database
must be shutdown and reactivated before the configuration parameter changes
become effective.
[db2inst1@TCS-PCM-183 ~]$ db2 terminate
DB20000I The TERMINATE command completed successfully.
[db2inst1@TCS-PCM-183 ~]$ db2 deactivate db TESTDB
DB20000I The DEACTIVATE DATABASE command completed successfully.

[db2inst1@TCS-PCM-183 ~]$ db2 get db cfg |grep -i TRACK


Track modified pages (TRACKMOD) = YES

###################################################################################
########
db2 "update db cfg for testdb using LOGARCHMETH1
'DISK:/db2home/db2inst1/TEST_LOGS'"
DB20000I The UPDATE DATABASE CONFIGURATION command completed successfully.

[db2inst1@TCS-PCM-183 TEST_LOGS]$ db2 backup db testdb online incremental


SQL2413N Online backup is not allowed because the database is not recoverable
or a backup pending condition is in effect.

[db2inst1@TCS-PCM-183 TEST_LOGS]$ db2 backup db testdb online

Backup successful. The timestamp for this backup image is : 20210204125501

[db2inst1@TCS-PCM-183 TEST_LOGS]$
[db2inst1@TCS-PCM-183 TEST_LOGS]$
[db2inst1@TCS-PCM-183 TEST_LOGS]$ db2 backup db testdb online incremental

Backup successful. The timestamp for this backup image is : 20210204125516

[db2inst1@TCS-PCM-183 TEST_LOGS]$ db2 backup db testdb online incremental

Backup successful. The timestamp for this backup image is : 20210204125520

[db2inst1@TCS-PCM-183 TEST_LOGS]$
[db2inst1@TCS-PCM-183 TEST_LOGS]$
[db2inst1@TCS-PCM-183 TEST_LOGS]$ db2ckrst -d testdb -t 20210204125520 -r database

Suggested restore order of images using timestamp 20210204125520 for


database testdb.
====================================================================
restore db testdb incremental taken at 20210204125520
restore db testdb incremental taken at 20210204125501
restore db testdb incremental taken at 20210204125520
====================================================================

[db2inst1@TCS-PCM-183 TEST_LOGS]$ db2 "restore db testdb incremental taken at


2021020412552"^C
[db2inst1@TCS-PCM-183 TEST_LOGS]$
[db2inst1@TCS-PCM-183 TEST_LOGS]$ db2 drop db testdb
DB20000I The DROP DATABASE command completed successfully.
[db2inst1@TCS-PCM-183 TEST_LOGS]$ db2 "restore db testdb incremental taken at
20210204125520"
DB20000I The RESTORE DATABASE command completed successfully.
[db2inst1@TCS-PCM-183 TEST_LOGS]$
[db2inst1@TCS-PCM-183 TEST_LOGS]$
[db2inst1@TCS-PCM-183 TEST_LOGS]$ db2 "restore db testdb incremental taken at
20210204125501"
DB20000I The RESTORE DATABASE command completed successfully.
[db2inst1@TCS-PCM-183 TEST_LOGS]$ db2 " restore db testdb incremental taken at
20210204125520"
DB20000I The RESTORE DATABASE command completed successfully.
[db2inst1@TCS-PCM-183 TEST_LOGS]$ db2 connect to testdb
SQL1117N A connection to or activation of database "TESTDB" cannot be made
because of ROLL-FORWARD PENDING. SQLSTATE=57019
[db2inst1@TCS-PCM-183 TEST_LOGS]$
[db2inst1@TCS-PCM-183 TEST_LOGS]$
[db2inst1@TCS-PCM-183 TEST_LOGS]$ db2 "rollforward db testdb query status using
local time"
Rollforward Status

Input database alias = testdb


Number of members have returned status = 1

Member ID = 0
Rollforward status = DB pending
Next log file to be read = S0000004.LOG
Log files processed = -
Last committed transaction = 2021-02-04-12.55.19.000000 Local

[db2inst1@TCS-PCM-183 TEST_LOGS]$ db2 "rollforward db testdb to end of logs and


stop"

Rollforward Status

Input database alias = testdb


Number of members have returned status = 1

Member ID = 0
Rollforward status = not pending
Next log file to be read =
Log files processed = S0000000.LOG - S0000000.LOG
Last committed transaction = 2021-02-04-10.55.06.000000 UTC

DB20000I The ROLLFORWARD command completed successfully.

db2 backup db testdb online compress include logs

Backup successful. The timestamp for this backup image is : 20210204130903

[db2inst1@TCS-PCM-183 ~]$ db2 "rollforward db testdb query status using local time"

Rollforward Status

Input database alias = testdb


Number of members have returned status = 1

Member ID = 0
Rollforward status = DB pending
Next log file to be read = S0000002.LOG
Log files processed = -
Last committed transaction = 2021-02-04-13.09.15.000000 Local

db2 "backup db testdb online to /db2home/db2inst1/TEST_LOGS include logs"

Backup successful. The timestamp for this backup image is : 20210204132515

[db2inst1@TCS-PCM-183 TEST_LOGS]$ db2 "rollforward db testdb query status using


local time"

Rollforward Status

Input database alias = testdb


Number of members have returned status = 1
Member ID = 0
Rollforward status = DB pending
Next log file to be read = S0000002.LOG
Log files processed = -
Last committed transaction = 2021-02-04-13.25.16.000000 Local

[db2inst1@TCS-PCM-183 TEST_LOGS]$ db2 "rollforward db testdb TO END OF BACKup AND


COMPLETE"

Rollforward Status

Input database alias = testdb


Number of members have returned status = 1

Member ID = 0
Rollforward status = not pending
Next log file to be read =
Log files processed = S0000002.LOG - S0000002.LOG
Last committed transaction = 2021-02-04-11.25.16.000000 UTC

DB20000I The ROLLFORWARD command completed successfully.


[db2inst1@TCS-PCM-183 TEST_LOGS]$
[db2inst1@TCS-PCM-183 TEST_LOGS]$
[db2inst1@TCS-PCM-183 TEST_LOGS]$
[db2inst1@TCS-PCM-183 TEST_LOGS]$
[db2inst1@TCS-PCM-183 TEST_LOGS]$ db2 connect to testdb

Database Connection Information

Database server = DB2/LINUXX8664 11.1.3.3


SQL authorization ID = DB2INST1
Local database alias = TESTDB

#########################################################

You might also like