一、恢复初始化参数文件:
1、自动备份还原
1)关闭数据库并启动到nomount阶段
2)指定DBID
3)在数据库是使用spfile启动时,使用如下语句会报错,必须使用to来指定另外一个路径(使用pfile启动可解决如下错误)
4)使用to关键词来指定恢复spfile路径
5)发现还原成功
2、手动还原
1)数据库启动到mount阶段
RMAN> alter database mount;
2)列出含有spfile的备份集
3)通过to来制定还原路径,通过from来指定使用那个备份集用于恢复
4)检查发现还原成功
二、恢复控制文件
1)启动数据库到nomount阶段,并指定DBID
2)列出含有控制文件的备份集
3)在nomount状态不需要制定to的路径,故此不指定也可以恢复成功
4)如果数据库处于mount阶段时,使用autobackup会报错
5)因此在mount阶段恢复控制文件时就需制定路径
6)恢复控制文件后,需recover database,再打开数据库必须以resetlogs方式
三、恢复数据文件
1)将某个dbf文件mv或者rm掉
2)这里报错是因为数据库已经异常关闭
3)启动数据库到mount阶段
SQL> startup mount;
4)将数据文件offline
5)还原restore数据文件
6)恢复recover数据文件
7)将数据文件online
8)打开数据库成功
SQL> alter database open;
9)发现恢复成功
四、恢复表空间
1)创建用于测试的表空间
2)删除表空间对应的数据文件
[oracle@cancer neal]$ rm test01.d
3)将表空间offline掉,报错
4)加上immediate关键字
5)这里报错是因为test是关键字,加上''并大写可以解决
6)将表空间重新online
五、三种不完全恢复方式
1、自动备份还原
1)关闭数据库并启动到nomount阶段
- SQL> shutdown immediate;
- ORA-01109: database not open
- Database dismounted.
- ORACLE instance shut down.
-
- SQL> startup nomount;
- ORACLE instance started.
-
- Total System Global Area 939495424 bytes
- Fixed Size 2258840 bytes
- Variable Size 599787624 bytes
- Database Buffers 331350016 bytes
- Redo Buffers 6098944 byt
- RMAN> set dbid=4033362200;
- executing command: SET DBID
- RMAN> restore spfile from autobackup;
-
- Starting restore at 09-MAR-16
- using target database control file instead of recovery catalog
- allocated channel: ORA_DISK_1
- channel ORA_DISK_1: SID=10 device type=DISK
-
- RMAN-00571: ===========================================================
- RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
- RMAN-00571: ===========================================================
- RMAN-03002: failure of restore command at 03/09/2016 19:34:28
- RMAN-06564: must use the TO clause when the instance is started with SPFILE
- RMAN> restore spfile to '/u01/spfileneal.ora' from autobackup;
-
- Starting restore at 09-MAR-16
- using channel ORA_DISK_1
-
- recovery area destination: /u01/oracle/fast_recovery_area
- database name (or database unique name) used for search: NEAL
- channel ORA_DISK_1: AUTOBACKUP /u01/oracle/fast_recovery_area/NEAL/autobackup/2016_03_09/o1_mf_s_906041673_cfzht9tn_.bkp found in the recovery area
- channel ORA_DISK_1: looking for AUTOBACKUP on day: 20160309
- channel ORA_DISK_1: restoring spfile from AUTOBACKUP /u01/oracle/fast_recovery_area/NEAL/autobackup/2016_03_09/o1_mf_s_906041673_cfzht9tn_.bkp
- channel ORA_DISK_1: SPFILE restore from AUTOBACKUP complete
- Finished restore at 09-MAR-16
- [oracle@cancer u01]$ ll
- -rw-r----- 1 oracle oinstall 3584 Mar 9 19:39 spfileneal.ora
1)数据库启动到mount阶段
RMAN> alter database mount;
2)列出含有spfile的备份集
- RMAN> list backup of spfile;
-
- BS Key Type LV Size Device Type Elapsed Time Completion Time
- ------- ---- -- ---------- ----------- ------------ ---------------
- 393 Full 9.73M DISK 00:00:01 09-MAR-16
- BP Key: 393 Status: AVAILABLE Compressed: NO Tag: TAG20160309T141433
- Piece Name: /u01/oracle/fast_recovery_area/NEAL/autobackup/2016_03_09/o1_mf_s_906041673_cfzht9tn_.bkp
- SPFILE Included: Modification time: 09-MAR-16
- SPFILE db_unique_name: NEAL
- RMAN> restore spfile to '/u01/neal.ora' from '/u01/oracle/fast_recovery_area/NEAL/autobackup/2016_03_09/o1_mf_s_906041673_cfzht9tn_.bkp';
-
- Starting restore at 09-MAR-16
- allocated channel: ORA_DISK_1
- channel ORA_DISK_1: SID=237 device type=DISK
-
- channel ORA_DISK_1: restoring spfile from AUTOBACKUP /u01/oracle/fast_recovery_area/NEAL/autobackup/2016_03_09/o1_mf_s_906041673_cfzht9tn_.bkp
- channel ORA_DISK_1: SPFILE restore from AUTOBACKUP complete
- Finished restore at 09-MAR-16
- [oracle@cancer u01]$ ll
- -rw-r----- 1 oracle oinstall 3584 Mar 9 19:47 neal.ora
1)启动数据库到nomount阶段,并指定DBID
- SQL> startup nomount;
- RMAN> set dbid=4033362200;
- RMAN> list backup of controlfile;
-
- List of Backup Sets
- ===================
- BS Key Type LV Size Device Type Elapsed Time Completion Time
- ------- ---- -- ---------- ----------- ------------ ---------------
- 393 Full 9.73M DISK 00:00:01 09-MAR-16
- BP Key: 393 Status: AVAILABLE Compressed: NO Tag: TAG20160309T141433
- Piece Name: /u01/oracle/fast_recovery_area/NEAL/autobackup/2016_03_09/o1_mf_s_906041673_cfzht9tn_.bkp
- Control File Included: Ckp SCN: 7176260 Ckp time: 09-MAR-16
- RMAN> restore controlfile from '/u01/oracle/fast_recovery_area/NEAL/autobackup/2016_03_09/o1_mf_s_906041673_cfzht9tn_.bkp';
-
- Starting restore at 09-MAR-16
- using target database control file instead of recovery catalog
- allocated channel: ORA_DISK_1
- channel ORA_DISK_1: SID=10 device type=DISK
-
- channel ORA_DISK_1: restoring control file
- channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
- output file name=/u01/oracle/oradata/neal/control01.ctl
- output file name=/u01/oracle/fast_recovery_area/neal/control02.ctl
- Finished restore at 09-MAR-16
- RMAN> restore controlfile from autobackup;
-
- Starting restore at 09-MAR-16
- released channel: ORA_DISK_1
- Starting implicit crosscheck backup at 09-MAR-16
- allocated channel: ORA_DISK_1
- channel ORA_DISK_1: SID=10 device type=DISK
- Crosschecked 50 objects
- Finished implicit crosscheck backup at 09-MAR-16
-
- Starting implicit crosscheck copy at 09-MAR-16
- using channel ORA_DISK_1
- Crosschecked 2 objects
- Finished implicit crosscheck copy at 09-MAR-16
-
- searching for all files in the recovery area
- cataloging files...
- cataloging done
-
- List of Cataloged Files
- =======================
- File Name: /u01/oracle/fast_recovery_area/NEAL/autobackup/2016_03_09/o1_mf_s_906041673_cfzht9tn_.bkp
-
- using channel ORA_DISK_1
-
- RMAN-00571: ===========================================================
- RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
- RMAN-00571: ===========================================================
- RMAN-03002: failure of restore command at 03/09/2016 20:12:10
- RMAN-06496: must use the TO clause when the database is mounted or open
- RMAN> restore controlfile to '/u01/a.ctl' from '/u01/oracle/fast_recovery_area/NEAL/autobackup/2016_03_09/o1_mf_s_906041673_cfzht9tn_.bkp';
-
- Starting restore at 09-MAR-16
- using channel ORA_DISK_1
-
- channel ORA_DISK_1: restoring control file
- channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
- Finished restore at 09-MAR-16
- [oracle@cancer u01]$ ll
- -rw-r----- 1 oracle oinstall 10141696 Mar 9 20:13 a.ctl
- SQL> alter database open resetlogs;
- alter database open resetlogs
- *
- ERROR at line 1:
- ORA-01152: file 1 was not restored from a sufficiently old backup
- ORA-01110: data file 1: '/u01/oracle/oradata/neal/system01.dbf'
-
- RMAN> recover database;
-
- Starting recover at 09-MAR-16
- using channel ORA_DISK_1
-
- starting media recovery
-
- archived log for thread 1 with sequence 1 is already on disk as file /u01/oracle/oradata/neal/redo01.log
- archived log file name=/u01/oracle/oradata/neal/redo01.log thread=1 sequence=1
- media recovery complete, elapsed time: 00:00:00
- Finished recover at 09-MAR-16
-
- SQL> alter database open resetlogs;
-
- Database altered.
1)将某个dbf文件mv或者rm掉
- [oracle@cancer neal]$ mv sales_2009_2.dbf sales_2009_2.dbf.bak
- RMAN> sql 'alter database datafile 12 offline';
-
- using target database control file instead of recovery catalog
- RMAN-00571: ===========================================================
- RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
- RMAN-00571: ===========================================================
- RMAN-03002: failure of sql command at 03/09/2016 20:26:35
- RMAN-06403: could not obtain a fully authorized session
- ORA-01034: ORACLE not available
- ORA-27101: shared memory realm does not exist
- Linux-x86_64 Error: 2: No such file or directory
SQL> startup mount;
4)将数据文件offline
- RMAN> sql 'alter database datafile 12 offline';
-
- using target database control file instead of recovery catalog
- sql statement: alter database datafile 12 offline
- RMAN> restore datafile 12;
-
- Starting restore at 09-MAR-16
- using channel ORA_DISK_1
-
- 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 00012 to /u01/oracle/oradata/neal/sales_2009_2.dbf
- channel ORA_DISK_1: reading from backup piece /home/oracle/backup/neal_lv0_dgr02ri7_1_1_20160309
- channel ORA_DISK_1: piece handle=/home/oracle/backup/neal_lv0_dgr02ri7_1_1_20160309 tag=NEAL_LV0
- channel ORA_DISK_1: restored backup piece 1
- channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
- Finished restore at 09-MAR-16
- RMAN> recover datafile 12;
-
- Starting recover at 09-MAR-16
- using channel ORA_DISK_1
-
- starting media recovery
- media recovery complete, elapsed time: 00:00:00
-
- Finished recover at 09-MAR-16
- RMAN> sql 'alter database datafile 12 online';
-
- sql statement: alter database datafile 12 online
SQL> alter database open;
9)发现恢复成功
- [oracle@cancer neal]$ ll
-
- -rw-r----- 1 oracle oinstall 52436992 Mar 9 20:28 sales_2009_2.dbf
- -rw-r----- 1 oracle oinstall 52436992 Mar 9 20:17 sales_2009_2.dbf.bak
1)创建用于测试的表空间
- SQL> create tablespace test datafile '/u01/oracle/oradata/neal/test01.dbf' size 10m;
-
- Tablespace created.
[oracle@cancer neal]$ rm test01.d
3)将表空间offline掉,报错
- RMAN> sql 'alter tablespace test offline';
-
- using target database control file instead of recovery catalog
- sql statement: alter tablespace test offline
- RMAN-00571: ===========================================================
- RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
- RMAN-00571: ===========================================================
- RMAN-03009: failure of sql command on default channel at 03/09/2016 21:27:45
- RMAN-11003: failure during parse/execution of SQL statement: alter tablespace test offline
- ORA-01116: error in opening database file 16
- ORA-01110: data file 16: '/u01/oracle/oradata/neal/test01.dbf'
- ORA-27041: unable to open file
- Linux-x86_64 Error: 2: No such file or directory
- Additional information: 3
- RMAN> sql 'alter tablespace test offline immediate';
-
- sql statement: alter tablespace test offline immediate
- RMAN> restore tablespace test;
-
- RMAN-00571: ===========================================================
- RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
- RMAN-00571: ===========================================================
- RMAN-00558: error encountered while parsing input commands
- RMAN-01009: syntax error: found "test": expecting one of: "double-quoted-string, identifier, single-quoted-string"
- RMAN-01007: at line 1 column 20 file: standard input
-
- RMAN> restore tablespace 'TEST';
-
- Starting restore at 09-MAR-16
- allocated channel: ORA_DISK_1
- channel ORA_DISK_1: SID=255 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 00016 to /u01/oracle/oradata/neal/test01.dbf
- channel ORA_DISK_1: reading from backup piece /home/oracle/backup/neal_lv0_e4r02vfk_1_1_20160309
- channel ORA_DISK_1: piece handle=/home/oracle/backup/neal_lv0_e4r02vfk_1_1_20160309 tag=NEAL_LV0
- channel ORA_DISK_1: restored backup piece 1
- channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
- Finished restore at 09-MAR-16
-
- RMAN> recover tablespace 'TEST';
-
- Starting recover at 09-MAR-16
- using channel ORA_DISK_1
-
- starting media recovery
- media recovery complete, elapsed time: 00:00:00
-
- Finished recover at 09-MAR-16
- RMAN> sql 'alter tablespace test online';
-
- sql statement: alter tablespace test online
五、三种不完全恢复方式
- 1)基于时间点
-
- run{
- set until time "to_date('2016-03-10 12:00:00','yyyy-mm-dd hh24:mi:ss')";
- restore database;
- recover database;
- alter database open resetlogs;
- }
-
- 2)基于SCN
-
- startup mount;
- restore database until scn 10000;
- recover database until scn 10000;
- alter database open resetlogs;
-
- 3)基于日志序列
-
- startup mount;
- restore database until sequence 100 thread 1;
- recover database until sequence 100 thread 1;
- alter database open resetlogs;
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29812844/viewspace-2063673/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/29812844/viewspace-2063673/