[Rman]Rman Level012备份实验

备份脚本参考:http://blog.csdn.net/u011364306/article/details/49994135

以下实验和结论都是基于Rman的差异备份

查询归档是否开启

SQL> archive log list
Database log mode	       Archive Mode
Automatic archival	       Enabled
Archive destination	       /u01/oracle/archive/
Oldest online log sequence     23
Next log sequence to archive   25
Current log sequence	       25

查询当前Rman配置

RMAN> show all;

using target database control file instead of recovery catalog
RMAN configuration parameters for database with db_unique_name NEAL are:
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;
CONFIGURE BACKUP OPTIMIZATION OFF; # default
CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/file/backup/rman/controlfile_%F';
CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET; # default
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE MAXSETSIZE TO UNLIMITED; # default
CONFIGURE ENCRYPTION FOR DATABASE OFF; # default
CONFIGURE ENCRYPTION ALGORITHM 'AES128'; # default
CONFIGURE COMPRESSION ALGORITHM 'BASIC' AS OF RELEASE 'DEFAULT' OPTIMIZE FOR LOAD TRUE ; # default
CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default
CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/u01/oracle/product/11.2.0/db_1/dbs/snapcf_neal.f'; # default
为了试验方便,将Rman中的备份清除
RMAN> list backup;

specification does not match any backup in the repository

修改系统时间到周日,进行模拟Level0备份

[root@cancer /]# date -s "2015-11-15 12:00:00"
Sun Nov 15 12:00:00 CST 2015
进入scott用户创建测试表和数据
SQL> conn scott/tiger;
Connected.

--创建测试表t
SQL> create table t(a int);

Table created.

--插入一条测试数据
SQL> insert into t values(1);

1 row created.

SQL> commit;

Commit complete
执行Level0级备份脚本
[oracle@cancer onlinelog]$ sh /server/scripts/rman_bak_level0.sh  --执行0级备份脚本

Recovery Manager: Release 11.2.0.4.0 - Production on Sun Nov 15 12:03:59 2015

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

connected to target database: NEAL (DBID=4033362200)

RMAN> 2> 3> 4> 5> 6> 7> 8> 9> 10> 11> 
using target database control file instead of recovery catalog     --没有指定catalog所以用的controlfile
allocated channel: d1                  --分配通道d1(脚本中指定)
channel d1: SID=22 device type=DISK

allocated channel: d2
channel d2: SID=32 device type=DISK    --分配通道d2(脚本中指定)

Starting backup at 15-NOV-15           --备份开始
channel d1: starting incremental level 0 datafile backup set
channel d1: specifying datafile(s) in backup set    --备份通道d1备份2个数据文件
input datafile file number=00001 name=/u01/oracle/oradata/neal/system01.dbf
input datafile file number=00004 name=/u01/oracle/oradata/neal/users01.dbf
channel d1: starting piece 1 at 15-NOV-15
channel d2: starting incremental level 0 datafile backup set
channel d2: specifying datafile(s) in backup set    --备份通道d2备份3个数据文件
input datafile file number=00002 name=/u01/oracle/oradata/neal/sysaux01.dbf
input datafile file number=00005 name=/u01/oracle/oradata/neal/test01.dbf
input datafile file number=00003 name=/u01/oracle/oradata/neal/undotbs01.dbf
channel d2: starting piece 1 at 15-NOV-15
channel d1: finished piece 1 at 15-NOV-15
piece handle=/file/backup/rman/level0_NEAL_136_1_48qmaqdh.bkp tag=TAG20151115T120400 comment=NONE  --备份集1路径
channel d1: backup set complete, elapsed time: 00:00:35
channel d2: finished piece 1 at 15-NOV-15
piece handle=/file/backup/rman/level0_NEAL_137_1_49qmaqdh.bkp tag=TAG20151115T120400 comment=NONE  --备份集2路径
channel d2: backup set complete, elapsed time: 00:00:55
Finished backup at 15-NOV-15

Starting Control File and SPFILE Autobackup at 15-NOV-15           --备份controlfile和spfile
piece handle=/file/backup/rman/controlfile_c-4033362200-20151115-00 comment=NONE   --备份集路径
Finished Control File and SPFILE Autobackup at 15-NOV-15

sql statement: alter system archive log current       --当前日志进行归档

Starting backup at 15-NOV-15
current log archived                        
channel d1: starting archived log backup set          --开始备份归档日志
channel d1: specifying archived log(s) in backup set
input archived log thread=1 sequence=23 RECID=92 STAMP=896618744
input archived log thread=1 sequence=24 RECID=93 STAMP=896620892
channel d1: starting piece 1 at 15-NOV-15
channel d2: starting archived log backup set
channel d2: specifying archived log(s) in backup set
input archived log thread=1 sequence=25 RECID=94 STAMP=895838703
input archived log thread=1 sequence=26 RECID=95 STAMP=895838703
channel d2: starting piece 1 at 15-NOV-15
channel d1: finished piece 1 at 15-NOV-15
piece handle=/file/backup/rman/log_NEAL_139_1_4bqmaqff.bkp tag=TAG20151115T120503 comment=NONE
channel d1: backup set complete, elapsed time: 00:00:03
channel d1: deleting archived log(s)                  --删除已备份的输入归档日志
archived log file name=/u01/oracle/archive/1_23_896142292.dbf RECID=92 STAMP=896618744
archived log file name=/u01/oracle/archive/1_24_896142292.dbf RECID=93 STAMP=896620892
channel d2: finished piece 1 at 15-NOV-15
piece handle=/file/backup/rman/log_NEAL_140_1_4cqmaqff.bkp tag=TAG20151115T120503 comment=NONE
channel d2: backup set complete, elapsed time: 00:00:03
channel d2: deleting archived log(s)
archived log file name=/u01/oracle/archive/1_25_896142292.dbf RECID=94 STAMP=895838703
archived log file name=/u01/oracle/archive/1_26_896142292.dbf RECID=95 STAMP=895838703
Finished backup at 15-NOV-15

Starting Control File and SPFILE Autobackup at 15-NOV-15
piece handle=/file/backup/rman/controlfile_c-4033362200-20151115-01 comment=NONE
Finished Control File and SPFILE Autobackup at 15-NOV-15

crosschecked backup piece: found to be 'AVAILABLE'              --crosscheck备份文件
backup piece handle=/file/backup/rman/level0_NEAL_136_1_48qmaqdh.bkp RECID=126 STAMP=895838641
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/file/backup/rman/level0_NEAL_137_1_49qmaqdh.bkp RECID=127 STAMP=895838671
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/file/backup/rman/controlfile_c-4033362200-20151115-00 RECID=128 STAMP=895838696
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/file/backup/rman/log_NEAL_140_1_4cqmaqff.bkp RECID=129 STAMP=895838703
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/file/backup/rman/log_NEAL_139_1_4bqmaqff.bkp RECID=130 STAMP=895838703
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/file/backup/rman/controlfile_c-4033362200-20151115-01 RECID=131 STAMP=895838707
Crosschecked 6 objects


RMAN retention policy will be applied to the command
RMAN retention policy is set to recovery window of 7 days
no obsolete backups found

released channel: d1                        --释放通道

released channel: d2

RMAN> 

Recovery Manager complete.

更改系统时间到周一,进行模拟Level2备份

[root@cancer rman]# date -s "2015-11-16 12:00:00"
Mon Nov 16 12:00:00 CST 2015
scott用户继续插入实验数据
SQL> insert into t values(2);

1 row created.

SQL> commit;

Commit complete.
执行Level2备份脚本
[oracle@cancer onlinelog]$ sh /server/scripts/rman_bak_level2.sh 

Recovery Manager: Release 11.2.0.4.0 - Production on Mon Nov 16 12:01:05 2015

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

connected to target database: NEAL (DBID=4033362200)

RMAN> 2> 3> 4> 5> 6> 7> 8> 9> 10> 11> 
using target database control file instead of recovery catalog
allocated channel: d1
channel d1: SID=43 device type=DISK

allocated channel: d2
channel d2: SID=38 device type=DISK

Starting backup at 16-NOV-15
channel d1: starting incremental level 2 datafile backup set
channel d1: specifying datafile(s) in backup set
input datafile file number=00001 name=/u01/oracle/oradata/neal/system01.dbf
input datafile file number=00004 name=/u01/oracle/oradata/neal/users01.dbf
channel d1: starting piece 1 at 16-NOV-15
channel d2: starting incremental level 2 datafile backup set
channel d2: specifying datafile(s) in backup set
input datafile file number=00002 name=/u01/oracle/oradata/neal/sysaux01.dbf
input datafile file number=00005 name=/u01/oracle/oradata/neal/test01.dbf
input datafile file number=00003 name=/u01/oracle/oradata/neal/undotbs01.dbf
channel d2: starting piece 1 at 16-NOV-15
channel d1: finished piece 1 at 16-NOV-15
piece handle=/file/backup/rman/level2_NEAL_142_1_4eqmdek2.bkp tag=TAG20151116T120106 comment=NONE
channel d1: backup set complete, elapsed time: 00:00:35
channel d2: finished piece 1 at 16-NOV-15
piece handle=/file/backup/rman/level2_NEAL_143_1_4fqmdek2.bkp tag=TAG20151116T120106 comment=NONE
channel d2: backup set complete, elapsed time: 00:00:35
Finished backup at 16-NOV-15

sql statement: alter system archive log current

Starting backup at 16-NOV-15

......

crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/file/backup/rman/level0_NEAL_136_1_48qmaqdh.bkp RECID=126 STAMP=895838641
......

RMAN> 

更改系统时间到周三,进行模拟Level1备份

[root@cancer rman]# date -s "2015-11-18 12:00:00"
Wed Nov 16 12:00:00 CST 2015
scott用户继续插入实验数据
SQL> insert into t values(3);

1 row created.

SQL> commit;

Commit complete.
执行Level1备份脚本
[oracle@cancer onlinelog]$ sh /server/scripts/rman_bak_level1.sh

Recovery Manager: Release 11.2.0.4.0 - Production on Tue Nov 17 12:00:05 2015

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

connected to target database: NEAL (DBID=4033362200)

RMAN> 2> 3> 4> 5> 6> 7> 8> 9> 10> 11> 
using target database control file instead of recovery catalog
allocated channel: d1
channel d1: SID=22 device type=DISK

allocated channel: d2
channel d2: SID=32 device type=DISK

Starting backup at 17-NOV-15
channel d1: starting incremental level 1 datafile backup set
channel d1: specifying datafile(s) in backup set
input datafile file number=00001 name=/u01/oracle/oradata/neal/system01.dbf
input datafile file number=00004 name=/u01/oracle/oradata/neal/users01.dbf
channel d1: starting piece 1 at 17-NOV-15
channel d2: starting incremental level 1 datafile backup set
channel d2: specifying datafile(s) in backup set
input datafile file number=00002 name=/u01/oracle/oradata/neal/sysaux01.dbf
input datafile file number=00005 name=/u01/oracle/oradata/neal/test01.dbf
input datafile file number=00003 name=/u01/oracle/oradata/neal/undotbs01.dbf
channel d2: starting piece 1 at 17-NOV-15
channel d1: finished piece 1 at 17-NOV-15
piece handle=/file/backup/rman/level1_NEAL_148_1_4kqmg2u6.bkp tag=TAG20151117T120006 comment=NONE
channel d1: backup set complete, elapsed time: 00:00:35
channel d2: finished piece 1 at 17-NOV-15
piece handle=/file/backup/rman/level1_NEAL_149_1_4lqmg2u6.bkp tag=TAG20151117T120006 comment=NONE
channel d2: backup set complete, elapsed time: 00:00:35
Finished backup at 17-NOV-15

Starting Control File and SPFILE Autobackup at 17-NOV-15
piece handle=/file/backup/rman/controlfile_c-4033362200-20151117-00 comment=NONE
Finished Control File and SPFILE Autobackup at 17-NOV-15

sql statement: alter system archive log current

Starting backup at 17-NOV-15
current log archived
channel d1: starting archived log backup set
channel d1: specifying archived log(s) in backup set
input archived log thread=1 sequence=29 RECID=98 STAMP=896011243
channel d1: starting piece 1 at 17-NOV-15
channel d2: starting archived log backup set
channel d2: specifying archived log(s) in backup set
input archived log thread=1 sequence=30 RECID=99 STAMP=896011243
channel d2: starting piece 1 at 17-NOV-15
channel d1: finished piece 1 at 17-NOV-15
piece handle=/file/backup/rman/log_NEAL_151_1_4nqmg2vb.bkp tag=TAG20151117T120043 comment=NONE
channel d1: backup set complete, elapsed time: 00:00:01
channel d1: deleting archived log(s)
archived log file name=/u01/oracle/archive/1_29_896142292.dbf RECID=98 STAMP=896011243
channel d2: finished piece 1 at 17-NOV-15
piece handle=/file/backup/rman/log_NEAL_152_1_4oqmg2vb.bkp tag=TAG20151117T120043 comment=NONE
channel d2: backup set complete, elapsed time: 00:00:01
channel d2: deleting archived log(s)
archived log file name=/u01/oracle/archive/1_30_896142292.dbf RECID=99 STAMP=896011243
Finished backup at 17-NOV-15
......

Recovery Manager complete.

执行完Level1脚本后,再次使用scott对表t插入values(4)实验数据,我这里直接再次执行了一遍Level0的备份脚本

[oracle@cancer onlinelog]$ sh /server/scripts/rman_bak_level0.sh 

Recovery Manager: Release 11.2.0.4.0 - Production on Tue Nov 17 12:01:39 2015

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

connected to target database: NEAL (DBID=4033362200)

RMAN> 2> 3> 4> 5> 6> 7> 8> 9> 10> 11> 
using target database control file instead of recovery catalog
allocated channel: d1
channel d1: SID=43 device type=DISK

allocated channel: d2
channel d2: SID=38 device type=DISK

Starting backup at 17-NOV-15
channel d1: starting incremental level 0 datafile backup set
channel d1: specifying datafile(s) in backup set
input datafile file number=00001 name=/u01/oracle/oradata/neal/system01.dbf
input datafile file number=00004 name=/u01/oracle/oradata/neal/users01.dbf
channel d1: starting piece 1 at 17-NOV-15
channel d2: starting incremental level 0 datafile backup set
channel d2: specifying datafile(s) in backup set
input datafile file number=00002 name=/u01/oracle/oradata/neal/sysaux01.dbf
input datafile file number=00005 name=/u01/oracle/oradata/neal/test01.dbf
input datafile file number=00003 name=/u01/oracle/oradata/neal/undotbs01.dbf
channel d2: starting piece 1 at 17-NOV-15
channel d1: finished piece 1 at 17-NOV-15
piece handle=/file/backup/rman/level0_NEAL_154_1_4qqmg315.bkp tag=TAG20151117T120141 comment=NONE
channel d1: backup set complete, elapsed time: 00:00:55
channel d2: finished piece 1 at 17-NOV-15
piece handle=/file/backup/rman/level0_NEAL_155_1_4rqmg315.bkp tag=TAG20151117T120141 comment=NONE
channel d2: backup set complete, elapsed time: 00:00:55
Finished backup at 17-NOV-15

Starting Control File and SPFILE Autobackup at 17-NOV-15
piece handle=/file/backup/rman/controlfile_c-4033362200-20151117-02 comment=NONE
Finished Control File and SPFILE Autobackup at 17-NOV-15

sql statement: alter system archive log current

Starting backup at 17-NOV-15
current log archived
channel d1: starting archived log backup set
channel d1: specifying archived log(s) in backup set
input archived log thread=1 sequence=31 RECID=100 STAMP=896011358
channel d1: starting piece 1 at 17-NOV-15
channel d2: starting archived log backup set
channel d2: specifying archived log(s) in backup set
input archived log thread=1 sequence=32 RECID=101 STAMP=896011358
channel d2: starting piece 1 at 17-NOV-15
channel d1: finished piece 1 at 17-NOV-15
piece handle=/file/backup/rman/log_NEAL_157_1_4tqmg32u.bkp tag=TAG20151117T120238 comment=NONE
channel d1: backup set complete, elapsed time: 00:00:01
channel d1: deleting archived log(s)
archived log file name=/u01/oracle/archive/1_31_896142292.dbf RECID=100 STAMP=896011358
channel d2: finished piece 1 at 17-NOV-15
piece handle=/file/backup/rman/log_NEAL_158_1_4uqmg32u.bkp tag=TAG20151117T120238 comment=NONE
channel d2: backup set complete, elapsed time: 00:00:01
channel d2: deleting archived log(s)
archived log file name=/u01/oracle/archive/1_32_896142292.dbf RECID=101 STAMP=896011358
Finished backup at 17-NOV-15

......
Recovery Manager complete.
以上为备份实验,基本上012备份就如此循环,接着我们进行故障模拟,进行rman的恢复

删除users01.dbf

SQL> conn / as sysdba
Connected.
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.

[root@cancer neal]# cd /u01/oracle/oradata/neal/
[root@cancer neal]# rm users01.dbf
rm: remove regular file `users01.dbf'? y
启动数据库报错
SQL> startup
ORACLE instance started.

Total System Global Area  939495424 bytes
Fixed Size		    2258840 bytes
Variable Size		  599787624 bytes
Database Buffers	  331350016 bytes
Redo Buffers		    6098944 bytes
Database mounted.
ORA-01157: cannot identify/lock data file 4 - see DBWR trace file
ORA-01110: data file 4: '/u01/oracle/oradata/neal/users01.dbf'
查询当前数据库实例状态
SQL> select status from v$instance;

STATUS
------------
MOUNTED
使用Rman进行恢复数据库
[oracle@cancer onlinelog]$ rman target /

Recovery Manager: Release 11.2.0.4.0 - Production on Tue Nov 17 12:06:20 2015

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

connected to target database: NEAL (DBID=4033362200, not open)

RMAN> restore database; --先进行数据库的restore

Starting restore at 17-NOV-15
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=20 device type=DISK

channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00002 to /u01/oracle/oradata/neal/sysaux01.dbf
channel ORA_DISK_1: restoring datafile 00003 to /u01/oracle/oradata/neal/undotbs01.dbf
channel ORA_DISK_1: restoring datafile 00005 to /u01/oracle/oradata/neal/test01.dbf
--从下面一行可以看出,rman会使用最新的Level0备份进行restore
channel ORA_DISK_1: reading from backup piece /file/backup/rman/level0_NEAL_155_1_4rqmg315.bkp
channel ORA_DISK_1: piece handle=/file/backup/rman/level0_NEAL_155_1_4rqmg315.bkp tag=TAG20151117T120141
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:35
channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00001 to /u01/oracle/oradata/neal/system01.dbf
channel ORA_DISK_1: restoring datafile 00004 to /u01/oracle/oradata/neal/users01.dbf
channel ORA_DISK_1: reading from backup piece /file/backup/rman/level0_NEAL_154_1_4qqmg315.bkp
channel ORA_DISK_1: piece handle=/file/backup/rman/level0_NEAL_154_1_4qqmg315.bkp tag=TAG20151117T120141
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:45
Finished restore at 17-NOV-15

RMAN> recover database;  --对数据库进行recover,由于我这里实验插入数据库直接进行备份,关闭数据库,没有产生新的redo和archived日志,所以没有应用

Starting recover at 17-NOV-15
using channel ORA_DISK_1

starting media recovery
media recovery complete, elapsed time: 00:00:01

Finished recover at 17-NOV-15

SQL> alter database open;     --打开数据库

Database altered.

SQL> select * from scott.t;   --查询数据,发现未丢失

A
----------
1
2
3
4
 
接下来我们查询一下备份的文件 
[root@cancer rman]# ll -lrt
total 2505256
-rw-r----- 1 oracle oinstall 673488896 Nov 15 12:04 level0_NEAL_136_1_48qmaqdh.bkp
-rw-r----- 1 oracle oinstall 543481856 Nov 15 12:04 level0_NEAL_137_1_49qmaqdh.bkp
-rw-r----- 1 oracle oinstall  10223616 Nov 15 12:04 controlfile_c-4033362200-20151115-00
-rw-r----- 1 oracle oinstall   7707136 Nov 15 12:05 log_NEAL_140_1_4cqmaqff.bkp
-rw-r----- 1 oracle oinstall  41607680 Nov 15 12:05 log_NEAL_139_1_4bqmaqff.bkp
-rw-r----- 1 oracle oinstall  10223616 Nov 15 12:05 controlfile_c-4033362200-20151115-01
-rw-r----- 1 oracle oinstall     57344 Nov 16 12:01 level2_NEAL_142_1_4eqmdek2.bkp
-rw-r----- 1 oracle oinstall     73728 Nov 16 12:01 level2_NEAL_143_1_4fqmdek2.bkp
-rw-r----- 1 oracle oinstall  10223616 Nov 16 12:01 controlfile_c-4033362200-20151116-00
-rw-r----- 1 oracle oinstall      4608 Nov 16 12:01 log_NEAL_145_1_4hqmdel8.bkp
-rw-r----- 1 oracle oinstall      2560 Nov 16 12:01 log_NEAL_146_1_4iqmdel8.bkp
-rw-r----- 1 oracle oinstall  10223616 Nov 16 12:01 controlfile_c-4033362200-20151116-01
-rw-r----- 1 oracle oinstall     57344 Nov 17 12:00 level1_NEAL_148_1_4kqmg2u6.bkp
-rw-r----- 1 oracle oinstall     90112 Nov 17 12:00 level1_NEAL_149_1_4lqmg2u6.bkp
-rw-r----- 1 oracle oinstall  10223616 Nov 17 12:00 controlfile_c-4033362200-20151117-00
-rw-r----- 1 oracle oinstall      4608 Nov 17 12:00 log_NEAL_151_1_4nqmg2vb.bkp
-rw-r----- 1 oracle oinstall      2560 Nov 17 12:00 log_NEAL_152_1_4oqmg2vb.bkp
-rw-r----- 1 oracle oinstall  10223616 Nov 17 12:00 controlfile_c-4033362200-20151117-01
-rw-r----- 1 oracle oinstall 543481856 Nov 17 12:02 level0_NEAL_155_1_4rqmg315.bkp
-rw-r----- 1 oracle oinstall 673488896 Nov 17 12:02 level0_NEAL_154_1_4qqmg315.bkp
-rw-r----- 1 oracle oinstall  10223616 Nov 17 12:02 controlfile_c-4033362200-20151117-02
-rw-r----- 1 oracle oinstall      4608 Nov 17 12:02 log_NEAL_157_1_4tqmg32u.bkp
-rw-r----- 1 oracle oinstall      2560 Nov 17 12:02 log_NEAL_158_1_4uqmg32u.bkp
-rw-r----- 1 oracle oinstall  10223616 Nov 17 12:02 controlfile_c-4033362200-20151117-03
这里我将最新的一次Level0物理删除,重新查看备份文件
[root@cancer rman]# ll -lrt
total 2505256
-rw-r----- 1 oracle oinstall 673488896 Nov 15 12:04 level0_NEAL_136_1_48qmaqdh.bkp
-rw-r----- 1 oracle oinstall 543481856 Nov 15 12:04 level0_NEAL_137_1_49qmaqdh.bkp
-rw-r----- 1 oracle oinstall  10223616 Nov 15 12:04 controlfile_c-4033362200-20151115-00
-rw-r----- 1 oracle oinstall   7707136 Nov 15 12:05 log_NEAL_140_1_4cqmaqff.bkp
-rw-r----- 1 oracle oinstall  41607680 Nov 15 12:05 log_NEAL_139_1_4bqmaqff.bkp
-rw-r----- 1 oracle oinstall  10223616 Nov 15 12:05 controlfile_c-4033362200-20151115-01
-rw-r----- 1 oracle oinstall     57344 Nov 16 12:01 level2_NEAL_142_1_4eqmdek2.bkp
-rw-r----- 1 oracle oinstall     73728 Nov 16 12:01 level2_NEAL_143_1_4fqmdek2.bkp
-rw-r----- 1 oracle oinstall  10223616 Nov 16 12:01 controlfile_c-4033362200-20151116-00
-rw-r----- 1 oracle oinstall      4608 Nov 16 12:01 log_NEAL_145_1_4hqmdel8.bkp
-rw-r----- 1 oracle oinstall      2560 Nov 16 12:01 log_NEAL_146_1_4iqmdel8.bkp
-rw-r----- 1 oracle oinstall  10223616 Nov 16 12:01 controlfile_c-4033362200-20151116-01
-rw-r----- 1 oracle oinstall     57344 Nov 17 12:00 level1_NEAL_148_1_4kqmg2u6.bkp
-rw-r----- 1 oracle oinstall     90112 Nov 17 12:00 level1_NEAL_149_1_4lqmg2u6.bkp
-rw-r----- 1 oracle oinstall  10223616 Nov 17 12:00 controlfile_c-4033362200-20151117-00
-rw-r----- 1 oracle oinstall      4608 Nov 17 12:00 log_NEAL_151_1_4nqmg2vb.bkp
-rw-r----- 1 oracle oinstall      2560 Nov 17 12:00 log_NEAL_152_1_4oqmg2vb.bkp
-rw-r----- 1 oracle oinstall  10223616 Nov 17 12:00 controlfile_c-4033362200-20151117-01

Rman中删除该Level0的备份信息

[oracle@cancer onlinelog]$ rman target /

Recovery Manager: Release 11.2.0.4.0 - Production on Tue Nov 17 12:13:11 2015

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

connected to target database: NEAL (DBID=4033362200)

RMAN> crosscheck backup;

using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=18 device type=DISK
crosschecked backup piece: found to be 'AVAILABLE'
.....
Crosschecked 24 objects


RMAN> delete expired backup;

using channel ORA_DISK_1

List of Backup Pieces
BP Key  BS Key  Pc# Cp# Status      Device Type Piece Name
------- ------- --- --- ----------- ----------- ----------
144     144     1   1   EXPIRED     DISK        /file/backup/rman/level0_NEAL_155_1_4rqmg315.bkp
145     145     1   1   EXPIRED     DISK        /file/backup/rman/level0_NEAL_154_1_4qqmg315.bkp
146     146     1   1   EXPIRED     DISK        /file/backup/rman/controlfile_c-4033362200-20151117-02
147     147     1   1   EXPIRED     DISK        /file/backup/rman/log_NEAL_157_1_4tqmg32u.bkp
148     148     1   1   EXPIRED     DISK        /file/backup/rman/log_NEAL_158_1_4uqmg32u.bkp
149     149     1   1   EXPIRED     DISK        /file/backup/rman/controlfile_c-4033362200-20151117-03

Do you really want to delete the above objects (enter YES or NO)? yes
deleted backup piece
.....
Deleted 6 EXPIRED objects
按照上面操作,再次删除users01.dbf,重新使用rman恢复
[oracle@cancer onlinelog]$ rman target /

Recovery Manager: Release 11.2.0.4.0 - Production on Tue Nov 17 12:15:18 2015

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

connected to target database: NEAL (DBID=4033362200, not open)

RMAN> restore database;

Starting restore at 17-NOV-15
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=20 device type=DISK

channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00001 to /u01/oracle/oradata/neal/system01.dbf
channel ORA_DISK_1: restoring datafile 00004 to /u01/oracle/oradata/neal/users01.dbf
--从下面可以看出,rman使用第一次备份的Level0开始恢复,因此可以认为,Rman进行恢复时,总是从最近一次的可用Level0进行restore
channel ORA_DISK_1: reading from backup piece /file/backup/rman/level0_NEAL_136_1_48qmaqdh.bkp
channel ORA_DISK_1: piece handle=/file/backup/rman/level0_NEAL_136_1_48qmaqdh.bkp tag=TAG20151115T120400
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:35
channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00002 to /u01/oracle/oradata/neal/sysaux01.dbf
channel ORA_DISK_1: restoring datafile 00003 to /u01/oracle/oradata/neal/undotbs01.dbf
channel ORA_DISK_1: restoring datafile 00005 to /u01/oracle/oradata/neal/test01.dbf
channel ORA_DISK_1: reading from backup piece /file/backup/rman/level0_NEAL_137_1_49qmaqdh.bkp
channel ORA_DISK_1: piece handle=/file/backup/rman/level0_NEAL_137_1_49qmaqdh.bkp tag=TAG20151115T120400
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:25
Finished restore at 17-NOV-15

RMAN> recover database;

Starting recover at 17-NOV-15
using channel ORA_DISK_1
channel ORA_DISK_1: starting incremental datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
destination for restore of datafile 00001: /u01/oracle/oradata/neal/system01.dbf
destination for restore of datafile 00004: /u01/oracle/oradata/neal/users01.dbf
--从下面可以看出,rman使用上述Level0最近一次的Level1进行recover,再继续逐个使用Level2进行recover,最后使用归档日志和重做日志进行recover
channel ORA_DISK_1: reading from backup piece /file/backup/rman/level1_NEAL_148_1_4kqmg2u6.bkp
channel ORA_DISK_1: piece handle=/file/backup/rman/level1_NEAL_148_1_4kqmg2u6.bkp tag=TAG20151117T120006
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
channel ORA_DISK_1: starting incremental datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
destination for restore of datafile 00002: /u01/oracle/oradata/neal/sysaux01.dbf
destination for restore of datafile 00003: /u01/oracle/oradata/neal/undotbs01.dbf
destination for restore of datafile 00005: /u01/oracle/oradata/neal/test01.dbf
channel ORA_DISK_1: reading from backup piece /file/backup/rman/level1_NEAL_149_1_4lqmg2u6.bkp
channel ORA_DISK_1: piece handle=/file/backup/rman/level1_NEAL_149_1_4lqmg2u6.bkp tag=TAG20151117T120006
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01

starting media recovery           --这里报错是因为是我之前删除了Level0备份,但是控制文件记录的信息要比备份信息新,故报错,忽略

RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 11/17/2015 12:16:31
RMAN-06053: unable to perform media recovery because of missing log
RMAN-06025: no backup of archived log for thread 1 with sequence 32 and starting SCN of 1716223 found to restore
RMAN-06025: no backup of archived log for thread 1 with sequence 31 and starting SCN of 1716083 found to restore


RMAN> recover database until sequence 31;--使用不完全恢复

Starting recover at 17-NOV-15
using channel ORA_DISK_1

starting media recovery

channel ORA_DISK_1: starting archived log restore to default destination
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=29
channel ORA_DISK_1: reading from backup piece /file/backup/rman/log_NEAL_151_1_4nqmg2vb.bkp
channel ORA_DISK_1: piece handle=/file/backup/rman/log_NEAL_151_1_4nqmg2vb.bkp tag=TAG20151117T120043
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
archived log file name=/u01/oracle/archive/1_29_896142292.dbf thread=1 sequence=29
channel ORA_DISK_1: starting archived log restore to default destination
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=30
channel ORA_DISK_1: reading from backup piece /file/backup/rman/log_NEAL_152_1_4oqmg2vb.bkp
channel ORA_DISK_1: piece handle=/file/backup/rman/log_NEAL_152_1_4oqmg2vb.bkp tag=TAG20151117T120043
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
archived log file name=/u01/oracle/archive/1_30_896142292.dbf thread=1 sequence=30
media recovery complete, elapsed time: 00:00:01
Finished recover at 17-NOV-15
使用resetlogs进行打开数据库
SQL> alter database open resetlogs;

Database altered.
查看数据
SQL> select * from scott.t;

	 A
----------
	 1
	 2
	 3
发现values(4)丢失,不完全恢复导致

实验结论:Rman进行恢复时,首先使用最近一次可用的Level0备份进行restore数据库,接着根据最近一次可用的Level1-Level2-Leve2-...-Leve2-归档日志-重做日志进行recover数据库。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值