用drbd模拟盘阵镜像进行oracle备份测试(三):数据库备份

2738阅读 0评论2009-01-09 blue_stone
分类:Oracle

用drbd模拟盘阵镜像进行oracle备份测试(三):数据库备份
       作者:blue_stone(blue_stone@xinhuanet.com)
       转载请注明出处: http://bluestone.cublog.cn

在开始之前, 我们需要在oem2上启动数据库, 在recovery catalog 中注册数据库, 并检查磁盘状态为UpToDate/UptoDate, 连接状态为Connected, 状态为Primary/Secondary.

一 分裂镜像

在oem2上将数据库置于备份状态

RMAN>  sql 'alter database begin backup';

在oem2上断开r0的连接

[root@oem2 ~]# drbdadm disconnect r0
[root@oem2 ~]# drbdadm cstate r0
StandAlone                      
[root@oem2 ~]# ls /u02/
lost+found/   o102db1admin/ o102db1data/

在oem3上断开r0的连接, 并挂载/u02

[root@oem3 ~]# drbdadm disconnect r0
[root@oem3 ~]# drbdadm cstate r0
StandAlone                      
[root@oem3 ~]# drbdadm primary r0
[root@oem3 ~]# mount /dev/drbd0 /u02
[root@oem3 ~]# ls /u02              
lost+found  o102db1admin  o102db1data
[root@oem3 ~]#

在oem2上备份控制文件

RMAN> sql ' alter system archive log current';
sql statement:  alter system archive log current
RMAN> Copy current controlfile to '/u03/control_start';

Starting backup at 19-DEC-08
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=139 devtype=DISK
channel ORA_DISK_1: starting datafile copy
copying current control file
output filename=/u03/control_start tag=TAG20081219T012016 recid=1 stamp=673838421
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:07
Finished backup at 19-DEC-08

RMAN> Copy current controlfile to '/u03/control_backup';

Starting backup at 19-DEC-08
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile copy
copying current control file
output filename=/u03/control_backup tag=TAG20081219T012049 recid=2 stamp=673838455
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:07
Finished backup at 19-DEC-08

RMAN> resync catalog;

starting full resync of recovery catalog
full resync complete

控制文件共备份了2次, 其中/u03/control_backup用来启动用于备份的数据库实例到mount状态, /u03/control_start会被备份到磁带或磁盘, 将来用于恢复数据库. 如果使用/u03/control_start启动数据库, 将无法备份/u03/control_backup备份到磁盘或磁带.

在oem2上断开r1的连接

[root@oem2 ~]# drbdadm disconnect r1
[root@oem2 ~]# drbdadm cstate r1
StandAlone

在oem3上断开r1的连接, 并挂载/u03

[root@oem3 ~]# drbdadm disconnect r1
[root@oem3 ~]# drbdadm cstate r1
StandAlone                      
[root@oem3 ~]# drbdadm primary r1
[root@oem3 ~]# mount /dev/drbd1 /u03/
[root@oem3 ~]#

二 备份数据库

在oem3上以oracle用户登录, 将数据库启动到备份状态后, 备份数据库

[oracle@oem3 dbs]$ rman target / catalog rman/rman@rman

Recovery Manager: Release 10.2.0.1.0 - Production on Fri Dec 19 01:48:26 2008

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

connected to target database (not started)
connected to recovery catalog database    

RMAN> startup mount

Oracle instance started
database mounted       

Total System Global Area     285212672 bytes

Fixed Size                     1218992 bytes
Variable Size                 92276304 bytes
Database Buffers             188743680 bytes
Redo Buffers                   2973696 bytes

RMAN> BACKUP FORMAT '/u01/app/oracle/backup/ctl%d_%s_%p_%t' controlfilecopy '/u03/control_start';

Starting backup at 19-DEC-08
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=157 devtype=DISK
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input control file copy name=/u03/control_start        
channel ORA_DISK_1: starting piece 1 at 19-DEC-08      
channel ORA_DISK_1: finished piece 1 at 19-DEC-08      
piece handle=/u01/app/oracle/backup/ctlO102DB1_6_1_673840141 tag=TAG20081219T014901 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:04                                 
Finished backup at 19-DEC-08                                                                    

RMAN-06497: WARNING: control file is not current, control file autobackup skipped

RMAN> backup incremental level 0 format '/u01/app/oracle/backup/db%d_%s_%p_%t' (datafile '/u01/app/oracle/oradata/o102db1/testbk01.dbf' );

Starting backup at 19-DEC-08
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=157 devtype=DISK
RMAN-06554: WARNING: file 7 is in backup mode
channel ORA_DISK_1: starting incremental level 0 datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset           
input datafile fno=00007 name=/u01/app/oracle/oradata/o102db1/testbk01.dbf
channel ORA_DISK_1: starting piece 1 at 19-DEC-08                        
channel ORA_DISK_1: finished piece 1 at 19-DEC-08                        
piece handle=/u01/app/oracle/backup/dbO102DB1_9_1_673844707 tag=TAG20081219T030506 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:15                               
Finished backup at 19-DEC-08                                                                  

RMAN-06497: WARNING: control file is not current, control file autobackup skipped


RMAN> backup format '/u01/app/oracle/backup/ar%d_%s_%p_%t' (archivelog all);

Starting backup at 19-DEC-08
using channel ORA_DISK_1    
channel ORA_DISK_1: starting archive log backupset
channel ORA_DISK_1: specifying archive log(s) in backup set
input archive log thread=1 sequence=16 recid=14 stamp=673838220
channel ORA_DISK_1: starting piece 1 at 19-DEC-08              
channel ORA_DISK_1: finished piece 1 at 19-DEC-08              
piece handle=/u01/app/oracle/backup/arO102DB1_8_1_673841029 tag=TAG20081219T020349 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:07                                
Finished backup at 19-DEC-08                                                                   

RMAN-06497: WARNING: control file is not current, control file autobackup skipped

RMAN> shutdown ;     

database dismounted
Oracle instance shut down

RMAN> exit


Recovery Manager complete.
[oracle@oem3 dbs]$

数据库应该启动到mount状态, 如果启动到open状态, 数据文件和控制文件都会发生改变, 这样的备份无法通过后滚日志的方式将数据库恢复到最新状态.

数据库备份可以是完全备份, 也可以是增量或差量备份.

数据库备份完成后, 需关闭数据库, 否则/u02和/u03将无法卸载.

三 恢复DRBD资源为同步状态.

在oem2上commect r0和r1

[root@oem2 o102db1data]# drbdadm connect r0
[root@oem2 o102db1data]# drbdadm connect r1

在oem3上connect r0和r1

[root@oem3 db_2]# umount /u02                                                                             
[root@oem3 db_2]# umount /u03
[root@oem3 db_2]# drbdadm standby r0
Unknown command 'standby'.          
[root@oem3 db_2]# drbdadm secondary r0
[root@oem3 db_2]# drbdadm secondary r1
[root@oem3 db_2]# drbdadm -- --discard-my-data connect r0
[root@oem3 db_2]# cat /proc/drbd
version: 8.2.6 (api:88/proto:86-88)
GIT-hash: 3e69822d3bb4920a8c1bfdf7d647169eba7d2eb4 build by buildsvn@c5-x8664-build, 2008-10-03 11:30:17
 0: cs:SyncTarget st:Secondary/Primary ds:Inconsistent/UpToDate C r---                                  
    ns:0 nr:812 dw:2803904 dr:899786 al:23 bm:116 lo:4 pe:2153 ua:3 ap:0 oos:47784                      
        [>...................] sync'ed:  8.4% (47784/48500)K                                            
        finish: 0:08:57 speed: 76 (76) K/sec                                                            
 1: cs:StandAlone st:Secondary/Unknown ds:UpToDate/DUnknown   r---                                      
    ns:0 nr:37432 dw:568272 dr:37982 al:12 bm:41 lo:0 pe:0 ua:0 ap:0 oos:2508                           
[root@oem3 db_2]# cat /proc/drbd                                                                        
version: 8.2.6 (api:88/proto:86-88)                                                                     
GIT-hash: 3e69822d3bb4920a8c1bfdf7d647169eba7d2eb4 build by buildsvn@c5-x8664-build, 2008-10-03 11:30:17
 0: cs:SyncTarget st:Secondary/Primary ds:Inconsistent/UpToDate C r---                                  
    ns:0 nr:25376 dw:2820396 dr:899786 al:23 bm:117 lo:259 pe:1324 ua:257 ap:0 oos:31300                
        [=======>............] sync'ed: 41.7% (31300/48500)K                                            
        finish: 0:00:26 speed: 1,176 (636) K/sec                                                        
 1: cs:StandAlone st:Secondary/Unknown ds:UpToDate/DUnknown   r---                                      
    ns:0 nr:37432 dw:568272 dr:37982 al:12 bm:41 lo:0 pe:0 ua:0 ap:0 oos:2508                           
[root@oem3 db_2]# drbdadm -- --discard-my-data connect r1
[root@oem3 db_2]# cat /proc/drbd
version: 8.2.6 (api:88/proto:86-88)
GIT-hash: 3e69822d3bb4920a8c1bfdf7d647169eba7d2eb4 build by buildsvn@c5-x8664-build, 2008-10-03 11:30:17
 0: cs:SyncTarget st:Secondary/Primary ds:Inconsistent/UpToDate C r---                                  
    ns:0 nr:38432 dw:2839092 dr:899786 al:23 bm:119 lo:266 pe:668 ua:265 ap:0 oos:12608                 
        [==============>.....] sync'ed: 75.0% (12608/48500)K                                            
        finish: 0:00:12 speed: 940 (812) K/sec                                                          
 1: cs:WFBitMapT st:Secondary/Primary ds:UpToDate/UpToDate C r---                                       
    ns:0 nr:0 dw:568272 dr:37982 al:12 bm:41 lo:1 pe:0 ua:0 ap:0 oos:2508                               
[root@oem3 db_2]# cat /proc/drbd                                                                        
version: 8.2.6 (api:88/proto:86-88)                                                                     
GIT-hash: 3e69822d3bb4920a8c1bfdf7d647169eba7d2eb4 build by buildsvn@c5-x8664-build, 2008-10-03 11:30:17
 0: cs:SyncTarget st:Secondary/Primary ds:Inconsistent/UpToDate C r---                                  
    ns:0 nr:46968 dw:2842172 dr:899786 al:23 bm:120 lo:452 pe:137 ua:451 ap:0 oos:9528                  
        [===============>....] sync'ed: 83.4% (9528/48500)K                                             
        finish: 0:00:10 speed: 856 (792) K/sec                                                          
 1: cs:SyncTarget st:Secondary/Primary ds:Inconsistent/UpToDate C r---                                  
    ns:0 nr:0 dw:568272 dr:37982 al:12 bm:41 lo:2 pe:235 ua:0 ap:0 oos:2508                             
        [===================>] sync'ed:100.0% (2508/2508)K                                              
        finish: 0:00:18 speed: 0 (0) K/sec                                                                                                          
[root@oem3 db_2]# cat /proc/drbd                                                                        
version: 8.2.6 (api:88/proto:86-88)                                                                     
GIT-hash: 3e69822d3bb4920a8c1bfdf7d647169eba7d2eb4 build by buildsvn@c5-x8664-build, 2008-10-03 11:30:17
 0: cs:SyncTarget st:Secondary/Primary ds:Inconsistent/UpToDate C r---                                  
    ns:0 nr:48560 dw:2851580 dr:899786 al:23 bm:122 lo:28 pe:0 ua:27 ap:0 oos:148                       
        [===================>] sync'ed:100.0% (148/48500)K                                              
        finish: 0:00:00 speed: 1,852 (892) K/sec                                                        
 1: cs:SyncTarget st:Secondary/Primary ds:Inconsistent/UpToDate C r---                                  
    ns:0 nr:1848 dw:568276 dr:37982 al:12 bm:41 lo:171 pe:63 ua:171 ap:0 oos:2504                       
        [===================>] sync'ed:100.0% (2504/2508)K                                              
        finish: 0:00:50 speed: 0 (0) K/sec                                                              
[root@oem3 db_2]# cat /proc/drbd                                                                        
version: 8.2.6 (api:88/proto:86-88)                                                                     
GIT-hash: 3e69822d3bb4920a8c1bfdf7d647169eba7d2eb4 build by buildsvn@c5-x8664-build, 2008-10-03 11:30:17
 0: cs:Connected st:Secondary/Primary ds:UpToDate/UpToDate C r---                                       
    ns:0 nr:48588 dw:2851776 dr:899786 al:23 bm:123 lo:1 pe:0 ua:0 ap:0 oos:0                           
 1: cs:Connected st:Secondary/Primary ds:UpToDate/UpToDate C r---                                       
    ns:0 nr:2508 dw:570780 dr:37982 al:12 bm:44 lo:1 pe:0 ua:0 ap:0 oos:0                               
[root@oem3 db_2]#

四 未备份的内容

这次测试没有备份spfile, 生产环境中spfile也应该进行备份.

上一篇:用drbd模拟盘阵镜像进行oracle备份测试(二):DRBD安装及使用
下一篇:用drbd模拟盘阵镜像进行oracle备份测试(四):数据库恢复测试