DB2的备份与恢复

说明:在线增量备份前提:
1、更改数据库参数 logretain, userexit, trackmod 为 on
2、更改参数之后完全离线备份数据库一次
3、之后就可以进行在线、在线增量备份了
最重要的一点是数据库归档日志必须按时备份至另一个地方,本例中为 C:\db2backup\db2log (该日志是增量备份的日志)

现在就数据库 :TestDB做具体说明
1 db2 rollforward db TestDB end of logs and  complete over flower log path (c:\db2logs)
2 db2 restore db TestDB from c:\db2backup  taken at 20090102151513  without rolling forward
3 直接拷贝logs 替换恢复的数据库


db2 create database TestDB

db2 update db cfg for TestDB using logretain on trackmod on userexit on

db2 backup db TestDB to c:\db2backup

db2 connect to TestDB

db2 create table student (KeyID int not null,name varchar(20))

db2 insert into student values(1.'John')

db2 backup db TestDB online incremental automatic c:\db2backup

--模拟灾难,删除数据库!(注意,此前一定要将归档日志文件备份至另一个路径,保存好)
db2 drop db TestDB

db2 restore db TestDB incremental automatic from "c:" taken at 2007041914511 (这个时间戳是第一次备份的时间戳)


--前滚数据库,并指定归档日志位置,重要!
C:\>db2 ROLLFORWARD DATABASE TESTDB TO END OF LOGS AND COMPLETE OVERFLOW LOG PATH

(c:\db2backup\db2log)

db2 select * from student   返回一条结果

create database testdb
connect to testdb
list tables
create table students (id integer, name varchar(20))
select * from students
insert into students values (1,'A')
insert into students values (2,'B')
insert into students values (3,'C')
insert into students values (4,'D')
insert into students values (5,'E')
insert into students values (6,'F')
insert into students values (7,'G')
insert into students values (8,'H')
insert into students values (9,'I')
insert into students values (0,'J')

select * from students

force application all

backup db testdb to D:\Jeff_Server_DB_Backup

connect to testdb

update db cfg for testdb using userexit on

update db cfg for testdb using logretain on

update db cfg for testdb using trackmod on

insert into students values (10,'A')
insert into students values (12,'B')
insert into students values (13,'C')
insert into students values (14,'D')
insert into students values (15,'E')
insert into students values (16,'F')
insert into students values (17,'G')
insert into students values (18,'H')
insert into students values (19,'I')
insert into students values (20,'J')

backup db testdb online incremental to D:\Jeff_Server_DB_Backup

restore db testdb from D:\Jeff_Server_DB_Backup taken at 20110325174907

restore db testdb incremental automatic from D:\Jeff_Server_DB_Backup taken at 20110325175712

rollforward db testdb to end of logs and complete overflow log path ("D:\Jeff_Server_DB_Backup\SQLOGDIR")

你可能感兴趣的:(C++,c,C#,F#,db2)