DB2数据库回滚方法及回滚实例



1、还原数据库
db2 restore db dc from /db2_backup/dc taken at 20121102142900 with 1 buffers buffer 256

2、回滚数据库,1>和2>只执行其一。

1>、作用是将数据库回滚到最新日志时间
db2 rollforward db dc to end of logs and stop

2>、作用将数据库回滚到指定时间
db2 rollforward db dc to 2012-11-08-14.05.27 using local time


3、完成数据库回滚
db2 rollforward db dc stop


4、下面是一个还原数据库并进行回滚的一个例子。


$ db2stop force
SQL1064N  DB2STOP processing was successful.
$ db2start
SQL1063N  DB2START processing was successful.
$ db2 restore db dc from /db2_backup/dc taken at 20121102142900 with 1 buffers buffer 256
SQL2539W  Warning!  Restoring to an existing database that is the same as the backup image database.  The database files will be deleted.
Do you want to continue ? (y/n) y
DB20000I  The RESTORE DATABASE command completed successfully.
$ db2 connect to dc user admin using admin
SQL1117N  A connection to or activation of database "DC" cannot be made
because of ROLL-FORWARD PENDING.  SQLSTATE=57019
$ db2 rollforward db dc to 2012-11-08-19.09.27 using local time

                                 Rollforward Status

 Input database alias                   = dc
 Number of nodes have returned status   = 1

 Node number                            = 0
 Rollforward status                     = DB  working
 Next log file to be read               = S0000155.LOG
 Log files processed                    = S0000151.LOG - S0000153.LOG
 Last committed transaction             = 2012-11-08-19.03.39.000000

DB20000I  The ROLLFORWARD command completed successfully.
$ db2 rollforward db dc stop

                                 Rollforward Status

 Input database alias                   = dc
 Number of nodes have returned status   = 1

 Node number                            = 0
 Rollforward status                     = not pending
 Next log file to be read               =
 Log files processed                    = S0000151.LOG - S0000154.LOG
 Last committed transaction             = 2012-11-08-11.03.39.000000

DB20000I  The ROLLFORWARD command completed successfully.
$ db2 connect to dc user admin using admin
SQL2048N  An error occurred while accessing object "SQL PROCEDURE FILES". 
Reason code: "7".
# su - admin
$ ls
=2011-03-02 00.00.00.000000  das                          smit.script                  v5005-v5010_3.log
Mail                         nohup.out                    smit.transaction             –p
SYSTEM_CONFIG.ixf            smit.log                     sqllib
$ cd sqllib
$ ls
Readme            cfg               db2profile        infopop           log            
$ cd function
$ ls
db2clifn.a   db2dsproc    db2mq        db2rtsc      db2sg        db2stmg      libdb2u.a    routine      tblpd
db2dbappext  db2exsrv     db2msg       db2schema    db2soapudf   db2udp       put_line     src          unfenced
$ cd routine
$ ls
sqlproc   sr_cpath
$ cd sqlproc
$ ls
DC   SCC
$ cd DC
$ ls
ADMIN
$ cd ..
$ ls
DC     SCC
$ mv DC DC_bak
$ ls
DC_bak 
$ db2 connect to dc user admin using admin

   Database Connection Information

 Database server        = DB2/6000 8.1.6
 SQL authorization ID   = ADMIN
 Local database alias   = DC

$ db2 list tablespaces show detail

猜你喜欢

转载自blog.csdn.net/qq_42223218/article/details/80339786