首页 > 代码库 > dbms_backup_restore Package
dbms_backup_restore Package
在数据库恢复的过程中如果有rman备份集,可以使用dbms_backup_restore包从备份集中还原文件,下面的例子说明所有控制文件损坏、某个数据文件丢失,有数据文件备份集的情况下如何恢复数据库:
DB:Oracle 11g 11.2.0.3.0 X86_64,OS RHEL 6.3 X86_64,未使用Recovery Catalog
1.关闭控制文件自动备份
RMAN> configure controlfile autobackup off;
new RMAN configuration parameters:
CONFIGURE CONTROLFILE AUTOBACKUP OFF;
new RMAN configuration parameters are successfully stored
2.创建测试表空间
SYS@orcl>create tablespace tstest datafile ‘/u01/app/oracle/oradata/orcl/tstest01.dbf‘ size 10m;
Tablespace created.
SYS@orcl>select file#,status,name from v$datafile;
FILE# STATUS NAME
---------- ------- ---------------------------------------------
1 SYSTEM /u01/app/oracle/oradata/orcl/system01.dbf
2 ONLINE /u01/app/oracle/oradata/orcl/sysaux01.dbf
3 ONLINE /u01/app/oracle/oradata/orcl/undotbs01.dbf
4 ONLINE /u01/app/oracle/oradata/orcl/users01.dbf
5 ONLINE /u01/app/oracle/oradata/orcl/example01.dbf
6 ONLINE /u01/app/oracle/oradata/orcl/tstest01.dbf
6 rows selected.
3.备份数据库
RMAN> backup database;
Starting backup at 06-JAN-13
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=15 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00001 name=/u01/app/oracle/oradata/orcl/system01.dbf
input datafile file number=00002 name=/u01/app/oracle/oradata/orcl/sysaux01.dbf
input datafile file number=00005 name=/u01/app/oracle/oradata/orcl/example01.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/orcl/undotbs01.dbf
input datafile file number=00006 name=/u01/app/oracle/oradata/orcl/tstest01.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/orcl/users01.dbf
channel ORA_DISK_1: starting piece 1 at 06-JAN-13
channel ORA_DISK_1: finished piece 1 at 06-JAN-13
piece handle=/u01/app/oracle/fast_recovery_area/ORCL/backupset/2013_01_06/o1_mf_nnndf_TAG20130106T190623_8glpokbm_.bkp tag=TAG20130106T190623 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:36
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
including current SPFILE in backup set
channel ORA_DISK_1: starting piece 1 at 06-JAN-13
channel ORA_DISK_1: finished piece 1 at 06-JAN-13
piece handle=/u01/app/oracle/fast_recovery_area/ORCL/backupset/2013_01_06/o1_mf_ncsnf_TAG20130106T190623_8glprm9z_.bkp tag=TAG20130106T190623 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 06-JAN-13
4.删除新建表空间的数据文件和破坏控制文件
[oracle@ora orabak]$ rm /u01/app/oracle/oradata/orcl/tstest01.dbf
[oracle@ora orabak]$ dd if=/dev/zero of=/u01/app/oracle/oradata/orcl/control01.ctl bs=512K count=10;
10+0 records in
10+0 records out
5242880 bytes (5.2 MB) copied, 0.00571965 s, 917 MB/s
[oracle@ora orabak]$ dd if=/dev/zero of=/u01/app/oracle/fast_recovery_area/orcl/control02.ctl bs=512K count=10;
10+0 records in
10+0 records out
5242880 bytes (5.2 MB) copied, 0.00548415 s, 956 MB/s
5.启动数据库到nomount状态
SYS@orcl>startup force nomount;
ORACLE instance started.
Total System Global Area 1603411968 bytes
Fixed Size 2228784 bytes
Variable Size 956304848 bytes
Database Buffers 637534208 bytes
Redo Buffers 7344128 bytes
6.执行dbms_backup_restore包,从备份集中还原数据文件
SYS@orcl>declare
devtype varchar2(256);
done boolean;
begin
devtype := dbms_backup_restore.DeviceAllocate (type =>‘‘,ident => ‘t1‘);
dbms_backup_restore.RestoreSetDatafile;
dbms_backup_restore.RestoreDatafileTo(dfnumber => 6,toname =>‘/u01/app/oracle/oradata/orcl/tstest01.dbf‘);
dbms_backup_restore.RestoreBackupPiece(done => done,handle =>‘/u01/app/oracle/fast_recovery_area/ORCL/backupset/2013_01_06/o1_mf_nnndf_TAG20130106T190623_8glpokbm_.bkp‘, params => null);
dbms_backup_restore.DeviceDeallocate;
end;
7.执行‘create controlfile‘命令创建控制文件
---因为所有归档日志和在线日志都没有损坏,所以使用‘NORESETLOGS ARCHIVELOG‘创建控制文件
SYS@orcl>CREATE CONTROLFILE REUSE DATABASE "ORCL" NORESETLOGS ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 ‘/u01/app/oracle/oradata/orcl/redo01.log‘ SIZE 50M BLOCKSIZE 512,
GROUP 2 ‘/u01/app/oracle/oradata/orcl/redo02.log‘ SIZE 50M BLOCKSIZE 512,
GROUP 3 ‘/u01/app/oracle/oradata/orcl/redo03.log‘ SIZE 50M BLOCKSIZE 512
-- STANDBY LOGFILE
DATAFILE
‘/u01/app/oracle/oradata/orcl/system01.dbf‘,
‘/u01/app/oracle/oradata/orcl/sysaux01.dbf‘,
‘/u01/app/oracle/oradata/orcl/undotbs01.dbf‘,
‘/u01/app/oracle/oradata/orcl/users01.dbf‘,
‘/u01/app/oracle/oradata/orcl/example01.dbf‘,
‘/u01/app/oracle/oradata/orcl/tstest01.dbf‘
CHARACTER SET AL32UTF8;
Control file created.
8.执行‘recover database‘恢复数据库
RMAN> recover database;
Starting recover at 06-JAN-13
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=10 device type=DISK
starting media recovery
unable to find archived log
archived log thread=1 sequence=12
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 01/06/2013 19:20:11
RMAN-06054: media recovery requesting unknown archived log for thread 1 with sequence 12 and starting SCN of 1118760
---提示12号归档日志找不到
---查询视图,12号redo日志是‘CURRENT‘状态,没有归档
SYS@orcl>select group#,sequence#,a.status,member from v$log a join v$logfile using(group#);
GROUP# SEQUENCE# STATUS MEMBER
---------- ---------- ---------------- ----------------------------------------
1 10 INACTIVE /u01/app/oracle/oradata/orcl/redo01.log
3 12 CURRENT /u01/app/oracle/oradata/orcl/redo03.log
2 11 INACTIVE /u01/app/oracle/oradata/orcl/redo02.log
---在sqlplus下执行‘recover database‘命令
SYS@orcl>recover database using backup controlfile;
ORA-00279: change 1118760 generated at 01/06/2013 19:06:23 needed for thread 1
ORA-00289: suggestion :
/u01/app/oracle/fast_recovery_area/ORCL/archivelog/2013_01_06/o1_mf_1_12_%u_.arc
ORA-00280: change 1118760 for thread 1 is in sequence #12
Specify log: {
dbms_backup_restore Package
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。