首页  :: 新随笔  :: 管理

DB2 pureScale之在线备份及恢复

Posted on 2022-09-19 12:03  高&玉  阅读(164)  评论(5编辑  收藏  举报

查看DB2 pureScale集群实例信息,我的DB2 pureScale环境包含2个CF和2个MEMBER

[db2inst1@member1 ~]$ db2instance -list
ID	  TYPE	           STATE		HOME_HOST		CURRENT_HOST		ALERT	PARTITION_NUMBER	LOGICAL_PORT	NETNAME
--	  ----	           -----		---------		------------		-----	----------------	------------	-------
0	MEMBER	         STARTED		  member1		     member1		   NO	               0	           0	member1
1	MEMBER	         STARTED		  member2		     member2		   NO	               0	           0	member2
128	CF	         PRIMARY		      cf1		         cf1		   NO	               -	           0	    cf1
129	CF	            PEER		      cf2		         cf2		   NO	               -	           0	    cf2

HOSTNAME		   STATE		INSTANCE_STOPPED	ALERT
--------		   -----		----------------	-----
     cf2		  ACTIVE		              NO	   NO
     cf1		  ACTIVE		              NO	   NO
 member2		  ACTIVE		              NO	   NO
 member1		  ACTIVE		              NO	   NO

 

DB2 pureScale开启归档模式+离线备份,在member1节点操作

创建归档路径
[db2inst1@member1 ~]$ mkdir arch_log

配置归档目录
[db2inst1@member1 ~]$ db2 update db cfg for db01 using LOGARCHMETH1 "disk:/home/db2inst1/arch_log"
DB20000I  The UPDATE DATABASE CONFIGURATION command completed successfully.

此时不能正常连接数据库,需要先做一次离线备份
[db2inst1@member1 ~]$ db2 connect to db01
SQL1116N  A connection to or activation of database "DB01" failed because the 
database is in BACKUP PENDING state.  SQLSTATE=57019

离线备份数据库DB01
[db2inst1@member1 ~]$ db2 backup database db01

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

 

创建1条测试数据

[db2inst1@member1 ~]$ db2 connect to db01

   Database Connection Information

 Database server        = DB2/LINUXX8664 10.5.10
 SQL authorization ID   = DB2INST1
 Local database alias   = DB01

[db2inst1@member1 ~]$ db2 "create table t1(id int not null,name varchar(99),primary key(id))"
DB20000I  The SQL command completed successfully.

[db2inst1@member1 ~]$ db2 "insert into t1 values(1,'name1')"
DB20000I  The SQL command completed successfully.

 

在线备份数据库,此时备份中只包含1条数据

[db2inst1@member1 ~]$ db2 backup database db01 online 

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

 

在1条插入测试数据

[db2inst1@member1 ~]$ db2 "insert into t1 values(2,'name2')"
DB20000I  The SQL command completed successfully.

 

此时测试表中共有2条数据

[db2inst1@member1 ~]$ db2 "select count(*) as ROW_COUNT from t1"

ROW_COUNT  
-----------
          2

 

利用在线备份进行恢复+日志前滚

[db2inst1@member1 ~]$ db2 restore database db01 from /home/db2inst1/
SQL2539W  The specified name of the backup image to restore is the same as the 
name of the target database.  Restoring to an existing database that is the 
same as the backup image database will cause the current database to be 
overwritten by the backup version.
Do you want to continue ? (y/n) y
DB20000I  The RESTORE DATABASE command completed successfully.
[db2inst1@member1 ~]$ db2 "rollforward database db01 to end of logs and complete"

                                 Rollforward Status

 Input database alias                   = db01
 Number of members have returned status = 2

 Member ID    Rollforward                 Next log             Log files processed        Last committed transaction
              status                      to be read
 -----------  --------------------------  -------------------  -------------------------  --------------------------
           0  not pending                                      S0000000.LOG-S0000001.LOG  2022-09-19-03.27.45.000000 UTC
           1  not pending                                      S0000000.LOG-S0000000.LOG  2022-09-19-03.33.17.000000 UTC

DB20000I  The ROLLFORWARD command completed successfully.

 

 再次查看测试表中的数据

[db2inst1@member1 ~]$ db2 "select count(*) as ROW_COUNT from t1"

ROW_COUNT  
-----------
          2

  1 record(s) selected.

 

DB2 pureScale架构的数据库备份与单机备份无区别。