You are on page 1of 26

DB2 9.

7 LUW
Full Online Backups
Experiments and considerations
(Jul 2!"2#
Jos Ral Barn Rodrguez
DB2 9 LUW DBA
CALCULO S.A.(Sa!n"
Au#$or%
Table of contents
Onl!ne Ba&'us....................................................................................................................................(
)rel!*!nar+ &on&e#s........................................................................................................................(
Re&o,er!ng droed #a-les................................................................................................................../
0o #a'e !n#o a&&oun# ......................................................................................................................22
Su**ar+ ............................................................................................................................................2(
A))12D34 A 5 -o*-ardea.re66 sour&e &ode....................................................................................27
DB2 9.8 LUW 9ull Onl!ne Ba&'us 5 16er!*en#s and Cons!dera#!ons 2 : 2/
Online Backups
Preliminary concepts
Online backups are those database backups that can be taken at the same time the
database is doing its job. In order to make Online Backups, the database must be
configured for linear logging. Same as it happens in circular logging, in linear
logging the log buffer records (i.e. Log records that are still kept in memory)
are taken to the primary log files B! unlike the circular logging, the primary
log files are "O! reusable under a linear logging configuration and once created
#ill ne$er be used again unless a restore % rollfor#ard is needed.
Log files containing records associated to transactions not yet committed nor
rolled back (aka In flight, unfinished) or log files not yet released into a
complete log file are called &'!I() LO* +IL)S and reside on the acti$e O"LI")
&,'-I() LO* directory % de$ice. Once completed they become O++LI") &,'-I() LO*
+IL)S and can be mo$ed automatically to another directory specific for them
assigned to db cfg parameter LO*&,'-.)!-/ or LO*&,'-.)!-0.
One of the first things to do #hen preparing a database for Online Backups
(besides creating it) is to configure primary and secondary log files in si1e
and number, as #ell as to configure the route for archi$ed log files. +or the
e2periments contained in this document #e #ill use the sample database 3B0
creates through the db0sampl command.
db2start
db2sampl
'reating database 4S&.5L)4...
'onnecting to database 4S&.5L)4...
'reating tables and data in schema 43B0I"S!/4...
6db0sampl6 processing complete.
"o# #e #ill modify the db cfg log related parameters to our con$enience7
db2 get db cfg | grep -i log
Log retain for reco$ery status 8 "O
ser e2it for logging status 8 "O
'atalog cache si1e (9:B) ('&!&LO*'&'-);S<) 8 (.&=&55LS>?)
Log buffer si1e (9:B) (LO*B+S<) 8 0?@
Log file si1e (9:B) (LO*+ILSI<) 8 1000
"umber of primary log files (LO*5,I.&,A) 8 3
"umber of secondary log files (LO*S)'O"3) 8 2
'hanged path to log files (")BLO*5&!-) 8
5ath to log files 8 %home%db0inst/%db0inst/%"O3)CCCC%SDLCCCC/%SDLO*3I,%
O$erflo# log path (O(),+LOBLO*5&!-) 8
.irror log path (.I,,O,LO*5&!-) 8
+irst acti$e log file 8
. . .
mkdir /experiment/backups/archived_logs
db2 update db cfg using logfilsiz 000 logprimar! 0 logsecond 10 logarchmeth1
disk"/experiment/backups/archived_logs trackmod on
3B0CCCCI !he 53&!) 3&!&B&S) 'O"+I*,&!IO" command completed successfully.
SDL/E@EB One or more of the parameters submitted for immediate modification
#ere not changed dynamically. +or these configuration parameters, the database
must be shutdo#n and reacti$ated before the configuration parameter changes
become effecti$e.
DB2 9.8 LUW 9ull Onl!ne Ba&'us 5 16er!*en#s and Cons!dera#!ons ( : 2/
!he db cfg !,&':.O3 parameter specifies #ether or not 3B0 should keep track of
modifications to the database so that database backups may detect #hich data
pages must be taken into account for an incremental or delta backup and
potentially be or not included in the backup itself. !his parameter should be
acti$ated.
db2 connect reset
db2stop
db2start
!he first connection trial #ill fail because #e need a backup start point for
the ne# configuration. +or this e2periment a backup to %de$%null #ill suffice.
db2 connect to sample
SDL///@" & connection to or acti$ation of database 4S&.5L)4
cannot be made because of B&':5 5)"3I"*. SDLS!&!)8?FC/G
db2 backup db sample to /dev/null
Backup successful. !he timestamp for this backup image is 7 0C/0CF/H//09E/
db2 connect to sample
3atabase 'onnection Information
3atabase ser$er 8 3B0%LI"= G.F.@
SDL authori1ation I3 8 3B0I"S!/
Local database alias 8 S&.5L)
Be can no# start changing data and, thus, generating log files. !o keep an
easier control of our transactions #e #ill create the follo#ing control table7
create table dropme
(
id bigint
generated al#ays as identity
(start #ith / increment by / no ma2$alue),
fecha timestamp
generated al#ays
+O, )&'- ,OB O" 53&!) &S ,OB '-&"*) !I.)S!&.5 not null,
literal $archar(?C),
numero integer default C
)I
Be ha$e #ritten a ,)== program #hich code can be found here, #ith #hich #e
6bomb6 our control table #ith intensi$e inserts, updates and deletions. &fter
some minutes the follo#ing log files can be seen7
alias l#$ls -la$
l /experiment/backups/archived_logs/db2inst1/%&'()*/+,-*0000/.0000000/
total 09CHC
dr#2rJ2JJJ 0 db0inst/ db0iadm/ 9CG@ Kul /E CF70/ .
dr#2rJ2JJJ E db0inst/ db0iadm/ 9CG@ Kul /0 CG7C0 ..
Jr#JrJJJJJ / db0inst/ db0iadm/ 9/C9/G0 Kul /0 /C79@ SCCCCCCC.LO*
Jr#JrJJJJJ / db0inst/ db0iadm/ 9/C9/G0 Kul /0 //7?G SCCCCCC/.LO*
Jr#JrJJJJJ / db0inst/ db0iadm/ 9/C9/G0 Kul /0 /E7?? SCCCCCC0.LO*
Jr#JrJJJJJ / db0inst/ db0iadm/ 9/C9/G0 Kul /0 /@70C SCCCCCCE.LO*
Jr#JrJJJJJ / db0inst/ db0iadm/ 9/C9/G0 Kul /0 /G79/ SCCCCCC9.LO*
Jr#JrJJJJJ / db0inst/ db0iadm/ 9/C9/G0 Kul /E C07/F SCCCCCC?.LO*
DB2 9.8 LUW 9ull Onl!ne Ba&'us 5 16er!*en#s and Cons!dera#!ons ; : 2/
9!rs# #r!al <a!ls
0r!al a<#er !n!#!al
-a&'u su&&eeds
Without stopping our 'bombing' scripts (e$en running them from se$eral putty
sessions simultaneously or as background processes) #e perform an online backup7
time db2 /&.01( -&2&/&%* %&'()* ,+)3+* 2, 4/experiment/backups4 5326 2 /177*8%
/177*8 1029 (&8&))*)3%' 1 .,'(8*%% 5326,12 (8,'(23+:
Backup successful. !he timestamp for this backup image is 7 0C/0CF/ECHC/00
real Cm/E.?H0s
user CmC.C/?s
sys CmC.CEGs
l /experiment/backups
total E0HE@
dr#2rJ2rJ2 E db0inst/ db0iadm/ 9CG@ Kul /E CH7C/ .
dr#2rJ2JJJ 9 db0inst/ db0iadm/ 9CG@ .ay G /?7E9 ..
dr#2rJ2rJ2 E db0inst/ db0iadm/ 9CG@ Kul /0 CG7C0 archi$ed;logs
Jr#JJJJJJJ / db0inst/ db0iadm/ 33;9<12 Kul /E CH7C/
%&'()*=0=db2inst1=+,-*0000=.&2+0000=20120;130>0122=001
l /experiment/backups/archived_logs/db2inst1/%&'()*/+,-*0000/.0000000/
total 0FE9C
dr#2rJ2JJJ 0 db0inst/ db0iadm/ 9CG@ Kul /E CH7C/ .
dr#2rJ2JJJ E db0inst/ db0iadm/ 9CG@ Kul /0 CG7C0 ..
Jr#JrJJJJJ / db0inst/ db0iadm/ 9/C9/G0 Kul /0 /C79@ SCCCCCCC.LO*
Jr#JrJJJJJ / db0inst/ db0iadm/ 9/C9/G0 Kul /0 //7?G SCCCCCC/.LO*
Jr#JrJJJJJ / db0inst/ db0iadm/ 9/C9/G0 Kul /0 /E7?? SCCCCCC0.LO*
Jr#JrJJJJJ / db0inst/ db0iadm/ 9/C9/G0 Kul /0 /@70C SCCCCCCE.LO*
Jr#JrJJJJJ / db0inst/ db0iadm/ 9/C9/G0 Kul /0 /G79/ SCCCCCC9.LO*
Jr#JrJJJJJ / db0inst/ db0iadm/ 9/C9/G0 Kul /E C07/F SCCCCCC?.LO*
Jr#JrJJJJJ / db0inst/ db0iadm/ 3339199 Kul /E CH7C/ %000000?=),:
date
+ri Kul /E CH7C07/9 ')S! 0C/0
!he database keeps on #orking. !he scripts that #ere changing the data in the
database didn6t stop their acti$ity but on the contrary, carried on #ithout e$er
suspecting a backup #as being performed at the same time, #hich means7
&t backup time, all the changes done so far #ere e2ternali1ed to a ne# log
file (i.e. %000000?=),:@ that6s #hy it6s some#hat smaller)
changes taking place on the database right after the backup starts are
being registered in the ne2t log file at the same time the backup itself
is progressing.
&nd all this is happening in a non disrupti$e fashion.
DB2 9.8 LUW 9ull Onl!ne Ba&'us 5 16er!*en#s and Cons!dera#!ons 7 : 2/
If #e repeat the backup command but this time using the I"'L3) LO*S clause,
this is the result7
time db2 /&.01( -&2&/&%* %&'()* ,+)3+* 2, 4/experiment/backups4 5326 2 /177*8%
/177*8 1029 (&8&))*)3%' 1 .,'(8*%% INCLUDE LOGS 5326,12 (8,'(23+:
Backup successful. !he timestamp for this backup image is 7 0C/0CF/ECHEG9C
real Cm/C.G?0s
user CmC.C/Hs
sys CmC.CE/s
l /experiment/backups/
total @?@@C
dr#2rJ2rJ2 E db0inst/ db0iadm/ 9CG@ Kul /E CH7EG .
dr#2rJ2JJJ 9 db0inst/ db0iadm/ 9CG@ .ay G /?7E9 ..
dr#2rJ2rJ2 E db0inst/ db0iadm/ 9CG@ Kul /0 CG7C0 archi$ed;logs
Jr#JJJJJJJ / db0inst/ db0iadm/ 33;9<12 Kul /E CH7C/
%&'()*=0=db2inst1=+,-*0000=.&2+0000=20120;130>0122=001
Jr#JJJJJJJ / db0inst/ db0iadm/ 33;9<12 Kul /E CH7EG
%&'()*=0=db2inst1=+,-*0000=.&2+0000=20120;130>3<90=001
Ldb0inst/Mraul pjbrNO
l /experiment/backups/archived_logs/db2inst1/%&'()*/+,-*0000/.0000000/
total 0F@F0
dr#2rJ2JJJ 0 db0inst/ db0iadm/ 9CG@ Kul /E CH7EG .
dr#2rJ2JJJ E db0inst/ db0iadm/ 9CG@ Kul /0 CG7C0 ..
Jr#JrJJJJJ / db0inst/ db0iadm/ 9/C9/G0 Kul /0 /C79@ SCCCCCCC.LO*
Jr#JrJJJJJ / db0inst/ db0iadm/ 9/C9/G0 Kul /0 //7?G SCCCCCC/.LO*
Jr#JrJJJJJ / db0inst/ db0iadm/ 9/C9/G0 Kul /0 /E7?? SCCCCCC0.LO*
Jr#JrJJJJJ / db0inst/ db0iadm/ 9/C9/G0 Kul /0 /@70C SCCCCCCE.LO*
Jr#JrJJJJJ / db0inst/ db0iadm/ 9/C9/G0 Kul /0 /G79/ SCCCCCC9.LO*
Jr#JrJJJJJ / db0inst/ db0iadm/ 9/C9/G0 Kul /E C07/F SCCCCCC?.LO*
Jr#JrJJJJJ / db0inst/ db0iadm/ EEE9/99 Kul /E CH7C/ SCCCCCC@.LO*
Jr#JrJJJJJ / db0inst/ db0iadm/ 33>;2 Kul /E CH7EG %000000;=),:
Be just generated a ne# full backup file, but since less time has elapsed and
less changes ha$e occurred, the truncated log file (%000000;=),:) is e$en
smaller in si1e than SCCCCCC@.LO*. By using I"'L3) LO*S, log files
SCCCCCC@.LO* and SCCCCCCF.LO* are included in the backup.
!o generate more log files faster and easier, #e ha$e created a del te2t file
containing data like this7
datos=del
,,hola,0E
,,hola,0E
,,hola,0E
,,hola,0E
... (?C.CCC identical lines.)
and #e import this data into the dropme table #ith7
db2 import from datos=del of del insert into dropme
#hich generates some 0JE complete log files on each import operation.
DB2 9.8 LUW 9ull Onl!ne Ba&'us 5 16er!*en#s and Cons!dera#!ons / : 2/
If #e repeat the backup no# #e #ill see7
time db2 /&.01( -&2&/&%* %&'()* ,+)3+* 2, 4/experiment/backups4 5326 2 /177*8%
/177*8 1029 (&8&))*)3%' 1 .,'(8*%% 3+.)1-* ),:% 5326,12 (8,'(23+:
Backup successful. !he timestamp for this backup image is 7 0C/0CF/ECG9GE@
real Cm/E.0@Cs
user CmC.C0Cs
sys CmC.CE/s
l /experiment/backups/
total GH9H9
dr#2rJ2rJ2 E db0inst/ db0iadm/ 9CG@ Kul /E CG79G .
dr#2rJ2JJJ 9 db0inst/ db0iadm/ 9CG@ .ay G /?7E9 ..
dr#2rJ2rJ2 E db0inst/ db0iadm/ 9CG@ Kul /0 CG7C0 archi$ed;logs
Jr#JJJJJJJ / db0inst/ db0iadm/ EE?F9G/0 Kul /E CH7C/ S&.5L).C.db0inst/."O3)CCCC.'&!"CCCC.0C/0CF/ECHC/00.CC/
Jr#JJJJJJJ / db0inst/ db0iadm/ EE?F9G/0 Kul /E CH7EG S&.5L).C.db0inst/."O3)CCCC.'&!"CCCC.0C/0CF/ECHEG9C.CC/
Jr#JJJJJJJ / db0inst/ db0iadm/ EE?F9G/0 Kul /E 0<"9< %&'()*=0=db2inst1=+,-*0000=.&2+0000=20120;130<9<3?=001
l /experiment/backups/archived_logs/db2inst1/%&'()*/+,-*0000/.0000000
total ?0C/0
dr#2rJ2JJJ 0 db0inst/ db0iadm/ 9CG@ Kul /E CG79G .
dr#2rJ2JJJ E db0inst/ db0iadm/ 9CG@ Kul /0 CG7C0 ..
Jr#JrJJJJJ / db0inst/ db0iadm/ 9/C9/G0 Kul /0 /C79@ SCCCCCCC.LO*
Jr#JrJJJJJ / db0inst/ db0iadm/ 9/C9/G0 Kul /0 //7?G SCCCCCC/.LO*
Jr#JrJJJJJ / db0inst/ db0iadm/ 9/C9/G0 Kul /0 /E7?? SCCCCCC0.LO*
Jr#JrJJJJJ / db0inst/ db0iadm/ 9/C9/G0 Kul /0 /@70C SCCCCCCE.LO*
Jr#JrJJJJJ / db0inst/ db0iadm/ 9/C9/G0 Kul /0 /G79/ SCCCCCC9.LO*
Jr#JrJJJJJ / db0inst/ db0iadm/ 9/C9/G0 Kul /E C07/F SCCCCCC?.LO*
Jr#JrJJJJJ / db0inst/ db0iadm/ EEE9/99 Kul /E CH7C/ SCCCCCC@.LO*
Jr#JrJJJJJ / db0inst/ db0iadm/ EE?HF0 Kul /E CH7EG SCCCCCCF.LO*
-rA-r----- 1 db2inst1 db2iadm1 91091<2 Bul 13 0<"31 %000000>=),:
-rA-r----- 1 db2inst1 db2iadm1 91091<2 Bul 13 0<"31 %000000<=),:
-rA-r----- 1 db2inst1 db2iadm1 91091<2 Bul 13 0<"31 %0000010=),:
-rA-r----- 1 db2inst1 db2iadm1 91091<2 Bul 13 0<"31 %0000011=),:
-rA-r----- 1 db2inst1 db2iadm1 91091<2 Bul 13 0<"9; %0000012=),:
-rA-r----- 1 db2inst1 db2iadm1 91091<2 Bul 13 0<"9; %0000013=),:
-rA-r----- 1 db2inst1 db2iadm1 2;033? Bul 13 0<"9< %0000019=),:
(Be ha$e done a couple data imports at the same time the bombing scripts #ere
doing their job uninterrupted and simultaneously all the time, that6s #hy there
are logfiles from G6E/ and G69F)
!he ne2t thing to do is7 Let6s restore the database at the situation it #as at
G69H, for e2ample. !o achie$e this #e ha$e7
One +ull backup taken at H6C/ #ithout logs included.
One +ull backup taken at H6EG BI!- logs included. (Be #ill use this one)
One +ull backup taken at G69G BI!- logs included.
!he log files.
&nd this is #hat #e6ll do7
'opy the log files to a different location to simulate a restore from tape
de$ice.
,estore the full backup taken at H6EG
,ollfor#ard the restored backup to G69H
DB2 9.8 LUW 9ull Onl!ne Ba&'us 5 16er!*en#s and Cons!dera#!ons 8 : 2/
mkdir /experiment/backups/pepe
mkdir /experiment/backups/aux
cd /experiment/backups/archived_logs/db2inst1/%&'()*/+,-*0000/.0000000
tar -cvzf logs=tar=gz C
SCCCCCCC.LO*
SCCCCCC/.LO*
SCCCCCC0.LO*
SCCCCCCE.LO*
SCCCCCC9.LO*
SCCCCCC?.LO*
SCCCCCC@.LO*
SCCCCCCF.LO*
SCCCCCCH.LO*
SCCCCCCG.LO*
SCCCCC/C.LO*
SCCCCC//.LO*
SCCCCC/0.LO*
SCCCCC/E.LO*
SCCCCC/9.LO*
mv logs=tar=gz /experiment/backups/pepe/
cd /experiment/backups/pepe/
tar -xvzf logs=tar=gz
SCCCCCCC.LO*
SCCCCCC/.LO*
SCCCCCC0.LO*
SCCCCCCE.LO*
SCCCCCC9.LO*
SCCCCCC?.LO*
SCCCCCC@.LO*
SCCCCCCF.LO*
SCCCCCCH.LO*
SCCCCCCG.LO*
SCCCCC/C.LO*
SCCCCC//.LO*
SCCCCC/0.LO*
SCCCCC/E.LO*
SCCCCC/9.LO*
rm logs=tar=gz
l
total ?0C/0
dr#2rJ2rJ2 0 db0inst/ db0iadm/ 9CG@ Kul /E /C7/0 .
dr#2rJ2rJ2 9 db0inst/ db0iadm/ 9CG@ Kul /E /C7CG ..
Jr#JrJJJJJ / db0inst/ db0iadm/ 9/C9/G0 Kul /0 /C79@ SCCCCCCC.LO*
Jr#JrJJJJJ / db0inst/ db0iadm/ 9/C9/G0 Kul /0 //7?G SCCCCCC/.LO*
Jr#JrJJJJJ / db0inst/ db0iadm/ 9/C9/G0 Kul /0 /E7?? SCCCCCC0.LO*
Jr#JrJJJJJ / db0inst/ db0iadm/ 9/C9/G0 Kul /0 /@70C SCCCCCCE.LO*
Jr#JrJJJJJ / db0inst/ db0iadm/ 9/C9/G0 Kul /0 /G79/ SCCCCCC9.LO*
Jr#JrJJJJJ / db0inst/ db0iadm/ 9/C9/G0 Kul /E C07/F SCCCCCC?.LO*
Jr#JrJJJJJ / db0inst/ db0iadm/ EEE9/99 Kul /E CH7C/ %000000?=),:
Jr#JrJJJJJ / db0inst/ db0iadm/ EE?HF0 Kul /E CH7EG %000000;=),:
Jr#JrJJJJJ / db0inst/ db0iadm/ 9/C9/G0 Kul /E CG7E/ SCCCCCCH.LO*
Jr#JrJJJJJ / db0inst/ db0iadm/ 9/C9/G0 Kul /E CG7E/ SCCCCCCG.LO*
Jr#JrJJJJJ / db0inst/ db0iadm/ 9/C9/G0 Kul /E CG7E/ SCCCCC/C.LO*
Jr#JrJJJJJ / db0inst/ db0iadm/ 9/C9/G0 Kul /E CG7E/ SCCCCC//.LO*
Jr#JrJJJJJ / db0inst/ db0iadm/ 9/C9/G0 Kul /E CG79F SCCCCC/0.LO*
Jr#JrJJJJJ / db0inst/ db0iadm/ 9/C9/G0 Kul /E CG79F SCCCCC/E.LO*
Jr#JrJJJJJ / db0inst/ db0iadm/ 0FCEE@ Kul /E CG79G SCCCCC/9.LO*
DB2 9.8 LUW 9ull Onl!ne Ba&'us 5 16er!*en#s and Cons!dera#!ons = : 2/
Be restore then the database using the +ull online backup from
%e2periment%backups. Be can do this restore either #ith or #ithout the logtarget
clause since this option simply e2tracts the log files included in the full
backup ($ia the I"'L3) LO*S option) to the directory #e specify but these
files, number @ and F respecti$ely, are already in the %e2periment%backups%pepe
directory.
db2 restore db sample from /experiment/backups taken at 20120;130>3<90 logtarget
4/experiment/backups/aux4
SDL0?EGB BarningP ,estoring to an e2isting database that is the same as the
backup image database. !he database files #ill be deleted.
3o you #ant to continue Q (y%n) !
3B0CCCCI !he ,)S!O,) 3&!&B&S) command completed successfully.
l /experiment/backups/aux
total E@CC
dr#2rJ2rJ2 0 db0inst/ db0iadm/ 9CG@ Kul /E /07/G .
dr#2rJ2rJ2 ? db0inst/ db0iadm/ 9CG@ Kul /E /07CC ..
-rA------- 1 db2inst1 db2iadm1 3339199 Bul 13 12"1< %000000?=),:
-rA------- 1 db2inst1 db2iadm1 33>;2 Bul 13 12"1< %000000;=),:
"o# #e roll for#ard to the desired 5oint In !ime indicating 3B0 #here he must
go search the log files needed. Since files %000000?=),: and %000000;=),: are
both in %e2periment%backups%au2 as #ell as in %e2periment%backups%pepe, #e only
need to indicate the last one, since it contains all the log files necessary to
mo$e until G69H.
db2 4rollforAard db sample to 2012-0;-13-0<=9>=00 using local time and stop
overfloA log path D/experiment/backups/pepeE4
,ollfor#ard Status
Input database alias 8 sample
"umber of nodes ha$e returned status 8 /
"ode number 8 C
,ollfor#ard status 8 not pending
"e2t log file to be read 8
Log files processed 8 %000000?=),: - %0000019=),:
Last committed transaction 8 0C/0JCFJ/EJ0<=9>=00.CCCCCC Local
3B0CCCCI !he ,OLL+O,B&,3 command completed successfully.
Ldb0inst/Mraul au2NO
db2 connect to sample
3atabase 'onnection Information
3atabase ser$er 8 3B0%LI"= G.F.@
SDL authori1ation I3 8 3B0I"S!/
Local database alias 8 S&.5L)
db2 select $maxDfechaE$ from dropme
/
JJJJJJJJJJJJJJJJJJJJJJJJJJ
0C/0JCFJ/EJ0<=9>=00.F0GH/9
/ record(s) selected.
"o#, #hat #ould ha$e happened in the case of %000000?=),: and %000000;=),:
DB2 9.8 LUW 9ull Onl!ne Ba&'us 5 16er!*en#s and Cons!dera#!ons 9 : 2/
missing Q (that is, log files containing inJflight transactions #hile the backup
#as being taken)
Let6s suppose these log files actually do not e2ist any more7
cd pepe
Ldb0inst/Mraul pepeNO l
total ?0C/0
dr#2rJ2rJ2 0 db0inst/ db0iadm/ 9CG@ Kul /E /C7/0 .
dr#2rJ2rJ2 ? db0inst/ db0iadm/ 9CG@ Kul /E /07CC ..
Jr#JrJJJJJ / db0inst/ db0iadm/ 9/C9/G0 Kul /0 /C79@ SCCCCCCC.LO*
Jr#JrJJJJJ / db0inst/ db0iadm/ 9/C9/G0 Kul /0 //7?G SCCCCCC/.LO*
Jr#JrJJJJJ / db0inst/ db0iadm/ 9/C9/G0 Kul /0 /E7?? SCCCCCC0.LO*
Jr#JrJJJJJ / db0inst/ db0iadm/ 9/C9/G0 Kul /0 /@70C SCCCCCCE.LO*
Jr#JrJJJJJ / db0inst/ db0iadm/ 9/C9/G0 Kul /0 /G79/ SCCCCCC9.LO*
Jr#JrJJJJJ / db0inst/ db0iadm/ 9/C9/G0 Kul /E C07/F SCCCCCC?.LO*
-rA-r----- 1 db2inst1 db2iadm1 3339199 Bul 13 0>"01 %000000?=),:
-rA-r----- 1 db2inst1 db2iadm1 33>;2 Bul 13 0>"3< %000000;=),:
Jr#JrJJJJJ / db0inst/ db0iadm/ 9/C9/G0 Kul /E CG7E/ SCCCCCCH.LO*
Jr#JrJJJJJ / db0inst/ db0iadm/ 9/C9/G0 Kul /E CG7E/ SCCCCCCG.LO*
Jr#JrJJJJJ / db0inst/ db0iadm/ 9/C9/G0 Kul /E CG7E/ SCCCCC/C.LO*
Jr#JrJJJJJ / db0inst/ db0iadm/ 9/C9/G0 Kul /E CG7E/ SCCCCC//.LO*
Jr#JrJJJJJ / db0inst/ db0iadm/ 9/C9/G0 Kul /E CG79F SCCCCC/0.LO*
Jr#JrJJJJJ / db0inst/ db0iadm/ 9/C9/G0 Kul /E CG79F SCCCCC/E.LO*
Jr#JrJJJJJ / db0inst/ db0iadm/ 0FCEE@ Kul /E CG79G SCCCCC/9.LO*
Ldb0inst/Mraul pepeNO rm %000000?=),: %000000;=),:
Ldb0inst/Mraul pepeNO l
total 9H90C
dr#2rJ2rJ2 0 db0inst/ db0iadm/ 9CG@ Kul /E /07EE .
dr#2rJ2rJ2 ? db0inst/ db0iadm/ 9CG@ Kul /E /07CC ..
Jr#JrJJJJJ / db0inst/ db0iadm/ 9/C9/G0 Kul /0 /C79@ SCCCCCCC.LO*
Jr#JrJJJJJ / db0inst/ db0iadm/ 9/C9/G0 Kul /0 //7?G SCCCCCC/.LO*
Jr#JrJJJJJ / db0inst/ db0iadm/ 9/C9/G0 Kul /0 /E7?? SCCCCCC0.LO*
Jr#JrJJJJJ / db0inst/ db0iadm/ 9/C9/G0 Kul /0 /@70C SCCCCCCE.LO*
Jr#JrJJJJJ / db0inst/ db0iadm/ 9/C9/G0 Kul /0 /G79/ SCCCCCC9.LO*
Jr#JrJJJJJ / db0inst/ db0iadm/ 9/C9/G0 Kul /E C07/F SCCCCCC?.LO*
Jr#JrJJJJJ / db0inst/ db0iadm/ 9/C9/G0 Kul /E CG7E/ SCCCCCCH.LO*
Jr#JrJJJJJ / db0inst/ db0iadm/ 9/C9/G0 Kul /E CG7E/ SCCCCCCG.LO*
Jr#JrJJJJJ / db0inst/ db0iadm/ 9/C9/G0 Kul /E CG7E/ SCCCCC/C.LO*
Jr#JrJJJJJ / db0inst/ db0iadm/ 9/C9/G0 Kul /E CG7E/ SCCCCC//.LO*
Jr#JrJJJJJ / db0inst/ db0iadm/ 9/C9/G0 Kul /E CG79F SCCCCC/0.LO*
Jr#JrJJJJJ / db0inst/ db0iadm/ 9/C9/G0 Kul /E CG79F SCCCCC/E.LO*
Jr#JrJJJJJ / db0inst/ db0iadm/ 0FCEE@ Kul /E CG79G SCCCCC/9.LO*
"o# #e retry the database restore7
db2 restore db sample from /experiment/backups taken at 20120;130>3<90
SDL0?EGB BarningP ,estoring to an e2isting database that is the same as the
backup image database. !he database files #ill be deleted.
3o you #ant to continue Q (y%n) !
3B0CCCCI !he ,)S!O,) 3&!&B&S) command completed successfully.
&s e2pected, #e cannot get connected to the database yet since it is in
,OLL+O,B&,3 5)"3I"* state7
Ldb0inst/Mraul pepeNO db2 connect to sample
SDL///F" & connection to or acti$ation of database 4S&.5L)4 cannot be made
because of ,OLLJ+O,B&,3 5)"3I"*. SDLS!&!)8?FC/G
Ldb0inst/Mraul pepeNO db2 4rollforAard db sample to 2012-0;-13-0<=9>=00 using
local time and stop overfloA log path D/experiment/backups/pepeE4
DB2 9.8 LUW 9ull Onl!ne Ba&'us 5 16er!*en#s and Cons!dera#!ons .> : 2/
,ollfor#ard Status
Input database alias 8 sample
"umber of nodes ha$e returned status 8 /
"ode number 8 C
,ollfor#ard status 8 not pending
"e2t log file to be read 8
Log files processed 8 %000000?=),: - %0000019=),:
Last committed transaction 8 0C/0JCFJ/EJ0<=9>=00.CCCCCC Local
3B0CCCCI !he ,OLL+O,B&,3 command completed successfully.
Ldb0inst/Mraul au2NO db2 connect to sample
3atabase 'onnection Information
3atabase ser$er 8 3B0%LI"= G.F.@
SDL authori1ation I3 8 3B0I"S!/
Local database alias 8 S&.5L)
Ldb0inst/Mraul au2NO db2 select $maxDfechaE$ from dropme
/
JJJJJJJJJJJJJJJJJJJJJJJJJJ
0C/0JCFJ/EJ0<=9>=00.F0GH/9
/ record(s) selected.
One remarkable thing is the fact that files %000000?=),: and %000000;=),: do not
e2ist any#here since #e had erased them too from %e2periment%backups%au2
Ldb0inst/Mraul au2NO l
total H
dr#2rJ2rJ2 0 db0inst/ db0iadm/ 9CG@ Kul /E /070/ .
dr#2rJ2rJ2 ? db0inst/ db0iadm/ 9CG@ Kul /E /07CC ..
Ldb0inst/Mraul au2NO
Bith that said, #e might suppose 3B0 is looking for them on db cfg LO*&,'-.)!-/,
#hich contains the path to the archi$ed log files. Let6s pro$e it by dropping
log files @ and F from this path7
db2 get db cfg grep -i logarchmeth1
+irst log archi$e method (LO*&,'-.)!-/) 8
3IS:7%e2periment%backups%archi$ed;logs%
cd /experiment/backups/archived_logs/db2inst1/%&'()*/+,-*0000/.0000000
rm %000000?=),: %000000;=),:
cd /experiment
Ldb0inst/Mraul e2perimentNO find | grep -i %000000?=),:
Ldb0inst/Mraul e2perimentNO find | grep -i %000000;=),:
Ldb0inst/Mraul e2perimentNO find | grep -i %000000>=),:
.%backups%pepe%SCCCCCCH.LO*
.%backups%archi$ed;logs%db0inst/%S&.5L)%"O3)CCCC%'CCCCCCC%SCCCCCCH.LO*
Ldb0inst/Mraul e2perimentNO
&s #e can see, files SCCCCCC@.LO* and SCCCCCCF.LO* do not e2ist but
SCCCCCCH.LO* does e2ist, for e2ample. I am doing this to pro$e my search method
is $alid and these t#o files simply don6t e2ist any#here in the reRuired path.
DB2 9.8 LUW 9ull Onl!ne Ba&'us 5 16er!*en#s and Cons!dera#!ons .. : 2/
Be #ill no# retry the restore to see #hat happens7
db2 restore db sample from /experiment/backups taken at 20120;130>3<90
SDL0?EGB BarningP ,estoring to an e2isting database that is the same as the
backup image database. !he database files #ill be deleted.
3o you #ant to continue Q (y%n) !
3B0CCCCI !he ,)S!O,) 3&!&B&S) command completed successfully.
db2 4rollforAard db sample to 2012-0;-13-0<=9>=00 using local time and stop
overfloA log path D/experiment/backups/pepeE4
SDL9GFC" ,ollJfor#ard reco$ery on database 4S&.5L)4 cannot reach the
specified stop point (endJofJlog or pointJinJtime) on database partition(s)
4C4. 8oll-forAard recover! processing has halted on log file 4%000000?=),:4.
Ldb0inst/Mraul e2perimentNO
So #e finally achie$ed #hat #e #anted to pro$e7 that the rollfor#ard process
#ill fail because the database cannot find the reRuired .LO* files. "o# ho#
shall #e fi2 itQ 'ertainly by reJgenerating files %000000?=),: and %000000;=),:.
db2 restore db sample from /experiment/backups taken at 20120;130>3<90 logtarget
/experiment/backups/aux
SDL0?EGB BarningP ,estoring to an e2isting database that is the same as the
backup image database. !he database files #ill be deleted.
3o you #ant to continue Q (y%n) !
3B0CCCCI !he ,)S!O,) 3&!&B&S) command completed successfully.
l /experiment/backups/aux
total E@CC
dr#2rJ2rJ2 0 db0inst/ db0iadm/ 9CG@ Kul /E /07?0 .
dr#2rJ2rJ2 ? db0inst/ db0iadm/ 9CG@ Kul /E /07CC ..
-rA------- 1 db2inst1 db2iadm1 3339199 Bul 13 12"2 %000000?=),:
-rA------- 1 db2inst1 db2iadm1 33>;2 Bul 13 12"2 %000000;=),:
db2 4rollforAard db sample to 2012-0;-13-0<=9>=00 using local time and stop
overfloA log path D/experiment/backups/auxE4
,ollfor#ard Status
Input database alias 8 sample
"umber of nodes ha$e returned status 8 /
"ode number 8 C
,ollfor#ard status 8 not pending
"e2t log file to be read 8
Log files processed 8 %000000?=),: - %0000019=),:
Last committed transaction 8 0C/0JCFJ/EJ0<=9>=00.CCCCCC Local
3B0CCCCI !he ,OLL+O,B&,3 command completed successfully.
Ldb0inst/Mraul au2NO
&nd that6s it. "o#, #ith files SCCCCCC@ and SCCCCCCF from the o$erflo# log path
added to files under folder 'CCCCCCC, #e can successfully finish the rollfor#ard
process (note #e only ha$e files @ and F on the au2 directory but the restore
process #ill use @ through /9, i.e. +iles H and higher #ill be searched on the
'CCCCCCC directory).
DB2 9.8 LUW 9ull Onl!ne Ba&'us 5 16er!*en#s and Cons!dera#!ons .2 : 2/
One curious thing7 for some reason file %000000?=),: disappears once the
rollfor#ard is done.
Ldb0inst/Mraul au2NO l
total E9C
dr#2rJ2rJ2 0 db0inst/ db0iadm/ 9CG@ Kul /E /E7/C .
dr#2rJ2rJ2 ? db0inst/ db0iadm/ 9CG@ Kul /E /07CC ..
Jr#JJJJJJJ / db0inst/ db0iadm/ EE?HF0 Kul /E /E7/C SCCCCCCF.LO*
Be #ill no# completely drop the directory7
%e2periment%backups%archi$ed;logs%db0inst/%S&.5L)%"O3)CCCC%'CCCCCCC
to make sure that only the log files #e ha$e restored from tape are a$ailable7
rm -rf /experiment/backups/archived_logs/db2inst1/%&'()*/+,-*0000/.0000000
rm /experiment/backups/aux/C
db2 restore db sample from /experiment/backups taken at 20120;130>3<90 logtarget
/experiment/backups/aux
SDL0?EGB BarningP ,estoring to an e2isting database that is the same as the
backup image database. !he database files #ill be deleted.
3o you #ant to continue Q (y%n) !
3B0CCCCI !he ,)S!O,) 3&!&B&S) command completed successfully.
mv /experiment/backups/aux/%000000C=),: /experiment/backups/pepe
db2 4rollforAard db sample to 2012-0;-13-0<=9>=00 using local time and stop
overfloA log path D/experiment/backups/pepeE4
,ollfor#ard Status
Input database alias 8 sample
"umber of nodes ha$e returned status 8 /
"ode number 8 C
,ollfor#ard status 8 not pending
"e2t log file to be read 8
Log files processed 8 %000000?=),: - %0000019=),:
Last committed transaction 8 0C/0JCFJ/EJ0<=9>=00.CCCCCC Local
3B0CCCCI !he ,OLL+O,B&,3 command completed successfully.
Since the log files are no longer on directory 'CCCCCCC the location on #hich
all the log files reRuired for the rollfor#ard process are must be specified on
3B '+* parm overflow log path. Once the rollfor#ard is done, there remains our
information untouched7
db2 connect to sample
3atabase 'onnection Information
3atabase ser$er 8 3B0%LI"= G.F.@
SDL authori1ation I3 8 3B0I"S!/
Local database alias 8 S&.5L)
DB2 9.8 LUW 9ull Onl!ne Ba&'us 5 16er!*en#s and Cons!dera#!ons .( : 2/
db2 select $maxDfechaE$ from dropme
/
JJJJJJJJJJJJJJJJJJJJJJJJJJ
0C/0JCFJ/EJ0<=9>=00.F0GH/9
/ record(s) selected.
#hich demonstrates directory .0000000 is not really necessary on a restore
process. It should suffice backing it up e$eryday using the tar command and
later erase its content (but not the directory itself).
&nother important consideration7 )$erytime #e ,)S!O,) a database, 3B0 creates
another directory generically named 'CCCCCCn that #ill become the ne# archi$ed
log files directory from no# on.
Ldb0inst/Mraul au2NO cd ==/archived_logs/db2inst1/%&'()*/+,-*0000/
Ldb0inst/Mraul "O3)CCCCNO l
total E@
dr#2rJ2JJJ G db0inst/ db0iadm/ 9CG@ Kul /E /E7/@ .
dr#2rJ2JJJ E db0inst/ db0iadm/ 9CG@ Kul /0 CG7C0 ..
dr#2rJ2JJJ 0 db0inst/ db0iadm/ 9CG@ Kul /E /07/G 'CCCCCC/
dr#2rJ2JJJ 0 db0inst/ db0iadm/ 9CG@ Kul /E /0700 'CCCCCC0
dr#2rJ2JJJ 0 db0inst/ db0iadm/ 9CG@ Kul /E /070@ 'CCCCCCE
dr#2rJ2JJJ 0 db0inst/ db0iadm/ 9CG@ Kul /E /07EF 'CCCCCC9
dr#2rJ2JJJ 0 db0inst/ db0iadm/ 9CG@ Kul /E /07?E 'CCCCCC?
dr#2rJ2JJJ 0 db0inst/ db0iadm/ 9CG@ Kul /E /E7/C 'CCCCCC@
dr#2rJ2JJJ 0 db0inst/ db0iadm/ 9CG@ Kul /E /E7/@ .000000;
in such a #ay that the ne2t log file to be created #on6t be created on just any
other directory but in the most recent one7
db2 get db cfg | grep -i log
...
O$erflo# log path (,F*87),5),:(&26) 8
.irror log path (.I,,O,LO*5&!-) 8
+irst acti$e log file 8 %000001=),:
Block log on disk full (BL:;LO*;3S:;+L) 8 "O
Block non logged operations (BLO':"O"LO**)3) 8 "O
5ercent ma2 primary log space by transaction (.&=;LO*) 8 C
...
"ote7 3B '+* parm O(),+LOBLO*5&!- pre$ents us from ha$ing the need to specify on
e$ery rollfor#ard operation #here the reRuired log files are located. Be6ll
simply lea$e them on the directory specified by this parameter and e$er since
the clause overfloA log path on the rollfor#ard command #on6t be necessary any
longer.

DB2 9.8 LUW 9ull Onl!ne Ba&'us 5 16er!*en#s and Cons!dera#!ons .; : 2/
If #e no# create the ne2t archi$ed log, it #ill be created on 'CCCCCCF7
db2 import from datos=del of del insert into dropme
SDLE/CG" !he utility is beginning to load data from file 4datos.del4.
SDLE//C" !he utility has completed processing. 4?CC9/4 ro#s #ere read from
the input file.
SDLE00/B ...Begin 'O..I! BO,:. Input ,ecord 'ount 8 4?CC9/4.
SDLE000B ...'O..I! of any database changes #as successful.
SDLE/9G" 4?CC9/4 ro#s #ere processed from the input file. 4?CC9/4 ro#s #ere
successfully inserted into the table. 4C4 ro#s #ere rejected.
"umber of ro#s read 8 ?CC9/
"umber of ro#s skipped 8 C
"umber of ro#s inserted 8 ?CC9/
"umber of ro#s updated 8 C
"umber of ro#s rejected 8 C
"umber of ro#s committed 8 ?CC9/
cd ==/archived_logs/db2inst1/%&'()*/+,-*0000/
Ldb0inst/Mraul "O3)CCCCNO l
total E@
dr#2rJ2JJJ G db0inst/ db0iadm/ 9CG@ Kul /E /E7/@ .
dr#2rJ2JJJ E db0inst/ db0iadm/ 9CG@ Kul /0 CG7C0 ..
drAxr-x--- 2 db2inst1 db2iadm1 90<? Bul 13 12"1< .0000001
drAxr-x--- 2 db2inst1 db2iadm1 90<? Bul 13 12"22 .0000002
drAxr-x--- 2 db2inst1 db2iadm1 90<? Bul 13 12"2? .0000003
drAxr-x--- 2 db2inst1 db2iadm1 90<? Bul 13 12"3; .0000009
drAxr-x--- 2 db2inst1 db2iadm1 90<? Bul 13 12"3 .000000
drAxr-x--- 2 db2inst1 db2iadm1 90<? Bul 13 13"10 .000000?
drAxr-x--- 2 db2inst1 db2iadm1 90<? Bul 13 13"29 .000000;
Ldb0inst/Mraul "O3)CCCCNO cd .000000;
Ldb0inst/Mraul 'CCCCCCFNO l
total 9C0C
dr#2rJ2JJJ 0 db0inst/ db0iadm/ 9CG@ Kul /E /E709 .
dr#2rJ2JJJ G db0inst/ db0iadm/ 9CG@ Kul /E /E7/@ ..
Jr#JrJJJJJ / db0inst/ db0iadm/ 9/C9/G0 Kul /E /E709 %000001=),:
DB2 9.8 LUW 9ull Onl!ne Ba&'us 5 16er!*en#s and Cons!dera#!ons .7 : 2/
D!re&#or!es
&rea#ed
a<#er ea&$
Res#ore
Recovering dropped tables
Be #ill no# take a further step7 Bhen #e configure a linear log strategy
(instead of circular) there are se$eral interesting functional benefits #e may
achie$e, among #hich #e ha$e the possibility to reco$er tables dropped
accidentally or not.
Let6s suppose #e dropped a table yesterday at /H6CCh and today #e #ant to
restore the database including our dropped table. +rom a classical point of
$ie#, #e might restore the database to a point in time of, say, /F6?Gh losing
all the transactions comitted e$er since (and thus, ha$ing to remake them #ith
all it implies).
+or such cases, ho#e$er, there e2ists one function pro$ided by the database
history file since it keeps track of the acti$ity Jnot only about backups and
restores but also about tables that ha$e been droppedJ and #ill allo# us to
restore the database to the current situation plus to create and populate the
table as it #as prior to being dropped. Let6s see ho#7
+or this scenario #e #ill ha$e a control table containing the timestamp of e$ery
record inserted and a ne# table that #ill be our victim to illustrate the
e2periment.
Be #ill create a victim table ($ictima)
Be #ill load records in the control table (dropme). Be #ill also generate
more log files. !his is not strictly necessary but #e ha$e done it like
this for ha$ing a logsJdroppingJlogs situation.
Be shall drop the victim table.
Be #ill load some more records in the control table (dropme), #hich #ill
generate more log files.
Be shall restore the database to the current, most recent situation.
!he victim table shouldn6t e2ist.
Be #ill no# restore the database #ith the ,)'O(), 3,O55)3 !&BL) clause at
,OLL+O,B&,3 time.
Let6s sail outP
Kust as #e said, #e create our victim table and insert some fe# $alues in it7
db2 $create table victima Dc1 integerE$
db2 $insert into victima values D1E@D2E@D3E@D9E$
db2 select $C$ from victima
'/
JJJJJJJJJJJ
/
0
E
9
9 record(s) selected.
DB2 9.8 LUW 9ull Onl!ne Ba&'us 5 16er!*en#s and Cons!dera#!ons ./ : 2/
Be #ill no# load some more ro#s in our control table dropme and, ob$iously, #e
#ill generate some log files as a result of it.
db2 import from datos=del of del insert into dropme
Be can see one ne# log file has been generated7
l /experiment/backups/archived_logs/db2inst1/%&'()*/+,-*0000/
total 9C
dr#2rJ2JJJ /C db0inst/ db0iadm/ 9CG@ Kul /E /E7?9 .
dr#2rJ2JJJ E db0inst/ db0iadm/ 9CG@ Kul /0 CG7C0 ..
dr#2rJ2JJJ 0 db0inst/ db0iadm/ 9CG@ Kul /E /07/G 'CCCCCC/
dr#2rJ2JJJ 0 db0inst/ db0iadm/ 9CG@ Kul /E /0700 'CCCCCC0
dr#2rJ2JJJ 0 db0inst/ db0iadm/ 9CG@ Kul /E /070@ 'CCCCCCE
dr#2rJ2JJJ 0 db0inst/ db0iadm/ 9CG@ Kul /E /07EF 'CCCCCC9
dr#2rJ2JJJ 0 db0inst/ db0iadm/ 9CG@ Kul /E /07?E 'CCCCCC?
dr#2rJ2JJJ 0 db0inst/ db0iadm/ 9CG@ Kul /E /E7/C 'CCCCCC@
dr#2rJ2JJJ 0 db0inst/ db0iadm/ 9CG@ Kul /E /E7?0 'CCCCCCF
drAxr-x--- 2 db2inst1 db2iadm1 90<? Bul 1> 0>"32 .000000>
l /experiment/backups/archived_logs/db2inst1/%&'()*/+,-*0000/.000000>/
total 9C0C
dr#2rJ2JJJ 0 db0inst/ db0iadm/ 9CG@ Kul /H CH7E0 .
dr#2rJ2JJJ /C db0inst/ db0iadm/ 9CG@ Kul /E /E7?9 ..
Jr#JrJJJJJ / db0inst/ db0iadm/ 9/C9/G0 Kul /H CH7E0 %000000>=),:
Be drop our victim table7
db2 drop table victima
and #e load some more data to generate e$en more log files7
db2 import from datos=del of del insert into dropme
l /experiment/backups/archived_logs/db2inst1/%&'()*/+,-*0000/.000000>/
total HCE0
dr#2rJ2JJJ 0 db0inst/ db0iadm/ 9CG@ Kul /H CG7CC .
dr#2rJ2JJJ /C db0inst/ db0iadm/ 9CG@ Kul /E /E7?9 ..
Jr#JrJJJJJ / db0inst/ db0iadm/ 9/C9/G0 Kul /H CH7E0 SCCCCCCH.LO*
Jr#JrJJJJJ / db0inst/ db0iadm/ 9/C9/G0 Kul /H CG7CC %000000<=),:
DB2 9.8 LUW 9ull Onl!ne Ba&'us 5 16er!*en#s and Cons!dera#!ons .8 : 2/
Let6s Ruery no# the database history file for information regarding dropped
tables7
db2 list histor! dropped table all for db sample
List -istory +ile for sample
"umber of matching file entries 8 /
Op Obj !imestampSSeRuence !ype 3e$ )arliest Log 'urrent Log Backup I3
JJ JJJ JJJJJJJJJJJJJJJJJJ JJJJ JJJ JJJJJJJJJJJJ JJJJJJJJJJJJ JJJJJJJJJJJJJJ
3 ! 0C/0CF/HCHE?E0 00000000000a0e30003000;
JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ
43B0I"S!/4.4F3.23'&4 resides in / tablespace(s)7
CCCC/ IB.3B0S&.5L),)L
JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ
'omment7 3,O5 !&BL)
Start !ime7 0C/0CF/HCHE?E0
)nd !ime7 0C/0CF/HCHE?E0
Status7 &
JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ
)I37 @H
33L7 ',)&!) !&BL) 43B0I"S!/4.4(I'!I.&4 ( 4'/4 I"!)*), ) I" 4IB.3B0S&.5L),)L4 G
JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ
&s #e can see, it sho#s info about the timestamp at #hich the table #as dropped
as #ell as the 33L sentence #e should e2ecute to recreate the empty table (no
data, only the structure).
Let6s see no# #hich is the last ro# on table dropme7
db2 select $maxDfechaE from dropme$
/
JJJJJJJJJJJJJJJJJJJJJJJJJJ
0C/0JCFJ/HJ0<=00=9>.0/E?F@
/ record(s) selected.
Be shall no# terminate our database to restore the online full backup #e had
plus the archi$ed log files ("O!)7 B-)" 'LOSI"* !-) 3B, &" &33I!IO"&L LO* +IL)
SCCCCC/C.LO* BILL B) ',)&!)3)
db2 restore db sample from /experiment/backups taken at 20120;130>3<90 logtarget
/experiment/backups/aux
SDL0?EGB BarningP ,estoring to an e2isting database that is the same as the
backup image database. !he database files #ill be deleted.
3o you #ant to continue Q (y%n) !
3B0CCCCI !he ,)S!O,) 3&!&B&S) command completed successfully.
!his command restores the database and creates log files %000000?=),: and
%000000;=),: in the au2 directory. Be must copy them to path
%e2periment%backups%pepe but the rollfor#ard to end of logs #ill fail. BhyQ
DB2 9.8 LUW 9ull Onl!ne Ba&'us 5 16er!*en#s and Cons!dera#!ons .= : 2/
cd aux
Ldb0inst/Mraul au2NO l
total E@CC
dr#2rJ2rJ2 0 db0inst/ db0iadm/ 9CG@ Kul /H CG70C .
dr#2rJ2rJ2 ? db0inst/ db0iadm/ 9CG@ Kul /E /07CC ..
-rA------- 1 db2inst1 db2iadm1 3339199 Bul 1> 0<"20 %000000?=),:
-rA------- 1 db2inst1 db2iadm1 33>;2 Bul 1> 0<"20 %000000;=),:
Ldb0inst/Mraul au2NO mv C ==/pepe
db2 4rollforAard db sample to end of logs and stop overfloA log path
D/experiment/backups/pepeE4
SDL/0@?" !he archi$e log file 4%000000<=),:4 is not associated #ith the
current log seRuence for database 4S&.5L)4 on node 4C4.
Ldb0inst/Mraul backupsNO
Because (let6s recall #hen #e added more ro#s #e also generated log files
SCCCCCCH.LO* and SCCCCCCG.LO*) #e need no# files H and G in order to rollfor#ard
the database to end of logs.
So #e must copy these t#o files to path %e2periment%backups%pepe and repeat the
,OLL+O,B&,3 command.
cd /experiment/backups/archived_logs/db2inst1/%&'()*/+,-*0000/.000000>/
cp C /experiment/backups/pepe
l /experiment/backups/pepe
total 9?@HC
dr#2rJ2rJ2 0 db0inst/ db0iadm/ 9CG@ Kul /H CG70G .
dr#2rJ2rJ2 ? db0inst/ db0iadm/ 9CG@ Kul /E /07CC ..
Jr#JrJJJJJ / db0inst/ db0iadm/ 9/C9/G0 Kul /0 /C79@ SCCCCCCC.LO*
Jr#JrJJJJJ / db0inst/ db0iadm/ 9/C9/G0 Kul /0 //7?G SCCCCCC/.LO*
Jr#JrJJJJJ / db0inst/ db0iadm/ 9/C9/G0 Kul /0 /E7?? SCCCCCC0.LO*
Jr#JrJJJJJ / db0inst/ db0iadm/ 9/C9/G0 Kul /0 /@70C SCCCCCCE.LO*
Jr#JrJJJJJ / db0inst/ db0iadm/ 9/C9/G0 Kul /0 /G79/ SCCCCCC9.LO*
Jr#JrJJJJJ / db0inst/ db0iadm/ 9/C9/G0 Kul /E C07/F SCCCCCC?.LO*
Jr#JJJJJJJ / db0inst/ db0iadm/ EE?HF0 Kul /H CG70C SCCCCCCF.LO*
-rA-r----- 1 db2inst1 db2iadm1 91091<2 Bul 1> 0<"3? %000000>=),:
-rA-r----- 1 db2inst1 db2iadm1 91091<2 Bul 1> 0<"3? %000000<=),:
-rA-r----- 1 db2inst1 db2iadm1 <>9?9 Bul 1> 0<"3? %0000010=),:
Jr#JrJJJJJ / db0inst/ db0iadm/ 9/C9/G0 Kul /E CG7E/ SCCCCC//.LO*
Jr#JrJJJJJ / db0inst/ db0iadm/ 9/C9/G0 Kul /E CG79F SCCCCC/0.LO*
Jr#JrJJJJJ / db0inst/ db0iadm/ 9/C9/G0 Kul /E CG79F SCCCCC/E.LO*
Jr#JrJJJJJ / db0inst/ db0iadm/ 0FCEE@ Kul /E CG79G SCCCCC/9.LO*
db2 4rollforAard db sample to end of logs and stop overfloA log path
D/experiment/backups/pepeE4
,ollfor#ard Status
Input database alias 8 sample
"umber of nodes ha$e returned status 8 /
"ode number 8 C
,ollfor#ard status 8 not pending
"e2t log file to be read 8
Log files processed 8 %000000?=),: - %0000010=),:
Last committed transaction 8 0C/0JCFJ/HJ0;=19=21.CCCCCC 12.
3B0CCCCI !he ,OLL+O,B&,3 command completed successfully.
DB2 9.8 LUW 9ull Onl!ne Ba&'us 5 16er!*en#s and Cons!dera#!ons .9 : 2/
2O03C1% UTC
#!*e &orresonds
#o C1S0 52
(&orresonds #o lo&al
#!*e 9?.;"
db2 connect to sample
db2 select $maxDfechaE from dropme$
/
JJJJJJJJJJJJJJJJJJJJJJJJJJ
0C/0JCFJ/HJ0<=00=9>.0/E?F@
/ record(s) selected.
&nd here comes an important hit7 our victim table doesn6t e2ist (as e2pected, on
the other hand)
db2 select $C$ from victima
SDLC0C9" 43B0I"S!/.(I'!I.&4 is an undefined name. SDLS!&!)890FC9
Be #ill no# repeat the process B! this time #e #ill use the ,)'O(), 3,O55)3
!&BL) clause #hen rolling for#ard.
db2 restore db sample from /experiment/backups taken at 20120;130>3<90 logtarget
/experiment/backups/aux
SDL0?EGB BarningP ,estoring to an e2isting database that is the same as the
backup image database. !he database files #ill be deleted.
3o you #ant to continue Q (y%n) !
3B0CCCCI !he ,)S!O,) 3&!&B&S) command completed successfully.
mv /experiment/backups/aux/%000000C ==/pepe
db2 4rollforAard db sample to end of logs and stop overfloA log path
D/experiment/backups/pepeE recover dropped table 00000000000a0e30003000; to
/experiment/backups/aux4
(),A I.5O,!&"! "O!I')7 3o not eliminate left hand 1eroes or the operation #ill
fail. !he backup I3 of the table must be specified exactly as it appears
pro$ided by the LIS! -IS!O,A 3,O55)3 !&BL) command
,ollfor#ard Status
Input database alias 8 sample
"umber of nodes ha$e returned status 8 /
"ode number 8 C
,ollfor#ard status 8 not pending
"e2t log file to be read 8
Log files processed 8 %000000?=),: - %0000010=),:
Last committed transaction 8 0C/0JCFJ/HJ0;=19=21.CCCCCC 12.
3B0CCCCI !he ,OLL+O,B&,3 command completed successfully.
!he $ictim table still doesn6t e2ist PP
db2 connect to sample
db2 select $C$ from victima
SDLC0C9" 43B0I"S!/.(I'!I.&4 is an undefined name. SDLS!&!)890FC9
DB2 9.8 LUW 9ull Onl!ne Ba&'us 5 16er!*en#s and Cons!dera#!ons 2> : 2/
B! this time, #hen rolling for#ard #ith ,)'O(), 3,O55)3 !&BL) the follo#ing has
been created on path %e2periment%backups%au2
L... au2NO l
total /0
dr#2rJ2rJ2 E db0inst/ db0iadm/ 9CG@ Kul /H /C7/@ .
dr#2rJ2rJ2 ? db0inst/ db0iadm/ 9CG@ Kul /E /07CC ..
dr#2rJ2JJJ 0 db0inst/ db0iadm/ 9CG@ Kul /H /C7/@ +,-*0000
and under "O3)CCCC there is a file7
l +,-*0000/
total /0
dr#2rJ2JJJ 0 db0inst/ db0iadm/ 9CG@ Kul /H /C7/@ .
dr#2rJ2rJ2 E db0inst/ db0iadm/ 9CG@ Kul /H /C7/@ ..
Jr#JrJJJJJ / db0inst/ db0iadm/ H Kul /H /C7/@ data
It is a simple, plain &S'II te2t file #hose content #e may $ie#%edit7
file +,-*0000/data
"O3)CCCC%data7 &S'II te2t
cat +,-*0000/data
/
0
E
9
&t this point #e ha$e all the ingredients reRuired to create the table just as
it #as at its remo$al time7
db2 $.8*&2* 2&/)* 4-/23+%214=4F3.23'&4 D 4.14 3+2*:*8 E$
3B0CCCCI !he SDL command completed successfully.
L... au2NO db2 import from +,-*0000/data of del insert into victima
SDLE/CG" !he utility is beginning to load data from file 4"O3)CCCC%data4.
SDLE//C" !he utility has completed processing. 494 ro#s #ere read from the
input file.
SDLE00/B ...Begin 'O..I! BO,:. Input ,ecord 'ount 8 494.
SDLE000B ...'O..I! of any database changes #as successful.
SDLE/9G" 494 ro#s #ere processed from the input file. 494 ro#s #ere
successfully inserted into the table. 4C4 ro#s #ere rejected.
"umber of ro#s read 8 9
"umber of ro#s skipped 8 C
"umber of ro#s inserted 8 9
"umber of ro#s updated 8 C
"umber of ro#s rejected 8 C
"umber of ro#s committed 8 9
DB2 9.8 LUW 9ull Onl!ne Ba&'us 5 16er!*en#s and Cons!dera#!ons 2. : 2/
In this case, using
tbsp IB.3B0S&.5L),)L
is optional.
db2 select $C$ from victima
'/
JJJJJJJJJJJ
/
0
E
9
9 record(s) selected.
To take into account
+or a table to be reco$erable, the tablespace it resides in must ha$e the
option 3,O55)3 !&BL) ,)'O(),A O" enabled. !his can be done at the
tablespace creation time (by default this option is O") but also through
the &L!), !&BL)S5&') command.
Only ,)*L&, tablespaces are reco$erable. !o check if a tablespace is
reco$erable, the follo#ing Ruery on column 3,O5;,)'O(),A from the catalog
$ie# SAS'&!.!&BL)S5&')S #ill suffice7
db2 select tbspace from s!scat=tables Ahere 4tabname#$F3.23'&$4
!BS5&')
JJJJJJJJJJJJJJJJJJJJJ
IB.3B0S&.5L),)L
/ record(s) selected.
db2 select drop_recover! from s!scat=tablespaces Ahere
4tbspace#$3/'-/2%&'()*8*)$4
3,O5;,)'O(),A
JJJJJJJJJJJJJ
A
/ record(s) selected.
If the table #as in ,)O,* 5)"3I"* state at the time it #as dropped (e.g.
because #e added, altered or deleted a column) it might be necessary to
modify the ',)&!) !&BL) command so that the 33L matches the data of the
data file.
Inde2es #on6t be reco$ered as the result of a table reco$ery operation. Be
#ill need to recreate them, so keeping their 33L definitions #ell kept and
centrali1ed some#here in a safe place #ould be a good thing to do.
DB2 9.8 LUW 9ull Onl!ne Ba&'us 5 16er!*en#s and Cons!dera#!ons 22 : 2/
$oil%& 'ere (e 'a)e our victim ta*le as i+ it 'ad
ne)er *een dropped.
Summary
Be may sa$e to cartridge and delete e$ery file located on the current
'CCCCCCn directory on a daily basis. &n alternati$e is to compress all the
files into a tar file and +!5 it to a backup ser$er or similar using a
descripti$e name for an easier later reco$ery #hen !ime calls for it.
&s more log files are created, they #ill be created in the current
'CCCCCCn directory that should (this is an ad$ice) be sa$ed on a dailyJ
#eeklyJmonthly basis (tar Jc$1f command) and erased after#ards using
ascending numbers and timestamps.
It might be ad$iceable (this must be e$aluated in terms of si1e and
duration) to include the log files as part of the full backups so that
e$ery inJflight transaction be preser$ed #hile a full backup is being
taken, i.e. the +ull Backup taken #ith the I"'L3) LO*S clause is
commpletely restoreable into a consistent situation to the point in time
#hen it #as finished since it contains all the reRuired log files in
itself, as #e demonstrate ne2t7
db2 restore db sample from /experiment/backups taken at 20120;130>3<90
logtarget /experiment/backups/aux
SDL0?EGB BarningP ,estoring to an e2isting database that is the same as
the
backup image database. !he database files #ill be deleted.
3o you #ant to continue Q (y%n) !
3B0CCCCI !he ,)S!O,) 3&!&B&S) command completed successfully.
db2 4rollforAard db sample to end of logs and stop overfloA log path
D/experiment/backups/auxE4
,ollfor#ard Status
Input database alias 8 sample
"umber of nodes ha$e returned status 8 /
"ode number 8 C
,ollfor#ard status 8 not pending
"e2t log file to be read 8
Log files processed 8 %000000?=),: - %000000;=),:
Last committed transaction 8 0C/0JCFJ/EJ0?=3<=0.CCCCCC 12.
3B0CCCCI !he ,OLL+O,B&,3 command completed successfully.
Bhen performing a database restore, there #ill ha$e to search, locate,
copy and decompress all the reRuired log files in order to get to a
certain pointJinJtime (5I!) after restoring a full backup and once this is
done, e2ecute the restore in t#o steps7
/. 3atabase restore, as such, e2tracting the included log files
if the I"'L3) LO*S clause had been used during the backup.
0. ,ollfor#ard the database to a certain 5I!, ha$ing copied the
pre$iously e2tracted log files to the directory #here the rest
of the reRuired log files reside so that #e can apply them by
pointing to this directory #ith the overflow log path clause.
Once the restore is done, a ne# 'CCCCCCn directory #ill be created in the
path #here 3B0 stores its log files. -ence, any other directory preJ
e2isting is no longer necessary and can be erased.
B&,"I"*7 & database backup process is usually a huge #orkload to add to
the ser$er on #hich the database runs, specially in terms of '5 and I%O.
DB2 9.8 LUW 9ull Onl!ne Ba&'us 5 16er!*en#s and Cons!dera#!ons 2( : 2/
Including logs inside the backups might increase the o$erhead in an
already '5 and%or I%O constrained system #ith the additional side effect
of a likely longer completion time and huger si1ed backup files. !his
should be carefully considered.
Backup resource consumption can be controlled (at the e2pense of taking
longer or shorter to complete) through the %*2 123)_3'(&.2_(83,832H
command.
DB2 9.8 LUW 9ull Onl!ne Ba&'us 5 16er!*en#s and Cons!dera#!ons 2; : 2/
1nd O< Do&u*en#
APPEND! A " bombardea#re$$ source code
%>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>%
%> 5rogram that keeps the dropme table being updated, deleted and inserted.>%
%> !his generates concurrency and log files. >%
%> >%
%> J ,eRuires to install the ,)== language >%
%> J It is more fun to e2ecute it from se$eral open putty #indo#s. >%
%> J 3oesn6t generate e2tremely big tables since it sooner or later deleJ >%
%> tes records pre$iously created (,)== ,&"3O. function is not so random >%
%> after all) >%
%>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>%
6clear6
alfabeto86abcdefg hijklm nopRr stu$ #2y1 J;6
comilla8464
call 3)'L&,&;&''IO"
call S)L)'!;'&.5OS
call 'L&SL&;B-),)
call 'L&SL&;O,3),
6db0 connect to sample6
do 0CCCC
interpret 6comando8accion.6random(/,9)
select
#hen comando86S)L)'! 6 then do
interpret 4comando8comandoTTc.4random(/,H)TT4 from dropme 4
interpret 4comando8comandoTT#.4random(/,9)
interpret 4comando8comandoTTo.4random(/,?)
end
#hen comando86I"S),! 6 then do
call *)"),&;'&3)"&
comando8comandoTT4into dropme(literal,numero) $alues(4
interpret 4comando8comandoTT46cadena64TT6,64random(/,GGGGG)4TT6)64
end
#hen comando863)L)!) 6 then do
comando8comandoTT4from dropme 4
interpret 4comando8comandoTT#.4random(/,9)
end
#hen comando8653&!) 6 then do
call *)"),&;'&3)"&
call 53&!);'&.5OS
comando8comandoTT4dropme set 4
interpret 4comando8comandoTTu.4random(/,0)
end
other#ise nop
end
6db0 46comando646
end
return
3)'L&,&;&''IO"7
accion./86S)L)'! 6
accion.086I"S),! 6
accion.E8653&!) 6
accion.9863)L)!) 6
return
DB2 9.8 LUW 9ull Onl!ne Ba&'us 5 16er!*en#s and Cons!dera#!ons 27 : 2/
S)L)'!;'&.5OS7
c./86id6
c.086fecha6
c.E86literal6
c.986numero6
c.?86>6
c.@86count(>)6
c.F86substr(literal,/,/C)6
c.H86ma2(numero)6
return
'L&SL&;B-),)7
interpret 4#./ 8 6 6TT 6#here id 8 64random(/,GGGGG)TT6 6
#.0 8 4 #here fecha 8 current date 4
#.E 8 4 #here length(rtrim(ltrim(literal)))80C 4
#.9 8 4 #here numero bet#een /CCC and /CCCC 4
return
'L&SL&;O,3),7
o./86 order by id 6
o.086 order by fecha 6
o.E86 order by literal 6
o.986 order by numero 6
o.?86 order by id desc6
o.@86 order by fecha desc 6
o.F86 order by literal desc 6
o.H86 order by numero desc 6
o.G86 order by substr(literal,?,0C) 6
return
*)"),&;'&3)"&7
numcar8random(/,?C)
cadena866
do i8/ to numcar
cadena8cadenaTTsubstr(alfabeto,random(/,length(alfabeto)),/)
end
cadena8comillaTTcadenaTTcomilla
return
53&!);'&.5OS7
u./84literal 84cadena
u.084numero 84TTrandom(/,GGGGG)
return
!his program can be e2ecuted #ith the command7 rexx bombardea=rexx
DB2 9.8 LUW 9ull Onl!ne Ba&'us 5 16er!*en#s and Cons!dera#!ons 2/ : 2/

You might also like