1. 登录 rman
[oracle@indb oradata]$ rman target /
Recovery Manager: Release 10.2.0.1.0 - Production on 星期一 9月 22 14:50:07 2008
Copyright (c) 1982, 2005, Oracle. All rights reserved.
connected to target database: FSNW (DBID=734270689)
|
2. 备份数据库
RMAN> backup database format '/oracle/oradata/rmanbackup/DATA.%U.rman'
2> plus archivelog format '/oracle/oradata/rmanbackup/ARCH.%U.rman' 3> delete all input; Starting backup at 22-9月 -08 current log archived 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=1 recid=45 stamp=666108755 input archive log thread=1 sequence=2 recid=46 stamp=666108763 input archive log thread=1 sequence=3 recid=47 stamp=666108769 input archive log thread=1 sequence=4 recid=48 stamp=666108770 input archive log thread=1 sequence=5 recid=49 stamp=666108812 channel ORA_DISK_1: starting piece 1 at 22-9月 -08 channel ORA_DISK_1: finished piece 1 at 22-9月 -08 piece handle=/oracle/oradata/rmanbackup/ARCH.0mjr80sc_1_1.rman tag=TAG20080922T141332 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02 channel ORA_DISK_1: deleting archive log(s) archive log filename=/oracle/oradata/arch/1_1_666101140.dbf recid=45 stamp=666108755 archive log filename=/oracle/oradata/arch/1_2_666101140.dbf recid=46 stamp=666108763 archive log filename=/oracle/oradata/arch/1_3_666101140.dbf recid=47 stamp=666108769 archive log filename=/oracle/oradata/arch/1_4_666101140.dbf recid=48 stamp=666108770 archive log filename=/oracle/oradata/arch/1_5_666101140.dbf recid=49 stamp=666108812 Finished backup at 22-9月 -08
Starting backup at 22-9月 -08
using channel ORA_DISK_1 channel ORA_DISK_1: starting full datafile backupset channel ORA_DISK_1: specifying datafile(s) in backupset input datafile fno=00005 name=/oracle/oradata/FSNW/FINANCE.dbf input datafile fno=00001 name=/oracle/oradata/FSNW/system01.dbf input datafile fno=00003 name=/oracle/oradata/FSNW/sysaux01.dbf input datafile fno=00002 name=/oracle/oradata/FSNW/undotbs01.dbf input datafile fno=00004 name=/oracle/oradata/FSNW/users01.dbf channel ORA_DISK_1: starting piece 1 at 22-9月 -08 channel ORA_DISK_1: finished piece 1 at 22-9月 -08 piece handle=/oracle/oradata/rmanbackup/DATA.0njr80sf_1_1.rman tag=TAG20080922T141335 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:03:25 Finished backup at 22-9月 -08
Starting backup at 22-9月 -08
current log archived 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=6 recid=50 stamp=666109020 channel ORA_DISK_1: starting piece 1 at 22-9月 -08 channel ORA_DISK_1: finished piece 1 at 22-9月 -08 piece handle=/oracle/oradata/rmanbackup/ARCH.0ojr812t_1_1.rman tag=TAG20080922T141700 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01 channel ORA_DISK_1: deleting archive log(s) archive log filename=/oracle/oradata/arch/1_6_666101140.dbf recid=50 stamp=666109020 Finished backup at 22-9月 -08
Starting Control File and SPFILE Autobackup at 22-9月 -08
piece handle=/oracle/oradata/rmanbackup/CTL.c-734270689-20080922-03.rman comment=NONE Finished Control File and SPFILE Autobackup at 22-9月 -08
RMAN> exit
Recovery Manager complete. |
3. 模拟业务操作(创建一张测试表)
[oracle@indb rmanbackup]$ sqlplus
SQL*Plus: Release 10.2.0.1.0 - Production on 星期一 9月 22 14:25:07 2008
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Enter user-name: / as sysdba
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production With the Partitioning, OLAP and Data Mining options
SQL> create table test_tianyc as select * From dba_objects;
Table created.
SQL> select count(*) from test_tianyc;
COUNT(*)
---------- 49625 |
4. 模拟数据库损坏(丢失控制文件、在线日志文件和数据文件)
SQL> shutdown immediate;
Database closed. Database dismounted. ORACLE instance shut down. SQL> exit Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production With the Partitioning, OLAP and Data Mining options [oracle@indb rmanbackup]$ cd /oracle/oradata [oracle@indb oradata]$ ll 总计 12 drwxrwxr-x 2 oracle oracle 4096 09-22 14:17 arch drwxrwxr-x 2 oracle oracle 4096 09-22 12:05 FSNW drwxrwxr-x 2 oracle oracle 4096 09-22 14:17 rmanbackup
-- 将数据文件、控制文件、在线日志文件所在文件夹FSNW重命名为FSNW_BAK
[oracle@indb oradata]$ mv FSNW FSNW_BAK [oracle@indb oradata]$ ll 总计 12 drwxrwxr-x 2 oracle oracle 4096 09-22 14:17 arch drwxrwxr-x 2 oracle oracle 4096 09-22 12:05 FSNW_BAK drwxrwxr-x 2 oracle oracle 4096 09-22 14:17 rmanbackup
-- 重新启动数据库,出现错误:找不到控制文件
[oracle@indb oradata]$ sqlplus
SQL*Plus: Release 10.2.0.1.0 - Production on 星期一 9月 22 14:28:51 2008
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Enter user-name: / as sysdba
Connected to an idle instance.
SQL> startup
ORACLE instance started.
Total System Global Area 926941184 bytes
Fixed Size 1222648 bytes Variable Size 264243208 bytes Database Buffers 654311424 bytes Redo Buffers 7163904 bytes ORA-00205: error in identifying control file, check alert log for more info
SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production With the Partitioning, OLAP and Data Mining options |
5. 使用rman进行恢复
[oracle@indb oradata]$ rman target /
Recovery Manager: Release 10.2.0.1.0 - Production on 星期一 9月 22 14:29:26 2008
Copyright (c) 1982, 2005, Oracle. All rights reserved.
connected to target database: FSNW (not mounted)
|
5.1 恢复控制文件
5.2 恢复数据文件
5.3 恢复归档日志文件
5.4 修复数据库
-- 恢复控制文件必须加上 from 子句,“from + autobackup”或者“from + 控制文件所在的备份片”
-- 这里提示恢复失败,是因为没有文件夹 /oracle/oradata/FSNW
RMAN> restore controlfile from '/oracle/oradata/rmanbackup/CTL.c-734270689-20080922-03.rman';
Starting restore at 22-9月 -08
using target database control file instead of recovery catalog allocated channel: ORA_DISK_1 channel ORA_DISK_1: sid=156 devtype=DISK
channel ORA_DISK_1: restoring control file
RMAN-00571: =========================================================== RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS =============== RMAN-00571: =========================================================== RMAN-03002: failure of restore command at 09/22/2008 14:30:28 ORA-19870: error reading backup piece /oracle/oradata/rmanbackup/CTL.c-734270689-20080922-03.rman ORA-19504: failed to create file "/oracle/oradata/FSNW/control01.ctl" ORA-27040: file create error, unable to create file Linux Error: 2: No such file or directory
RMAN> exit
Recovery Manager complete. [oracle@indb oradata]$ ll 总计 12 drwxrwxr-x 2 oracle oracle 4096 09-22 14:17 arch drwxrwxr-x 2 oracle oracle 4096 09-22 12:05 FSNW_BAK drwxrwxr-x 2 oracle oracle 4096 09-22 14:17 rmanbackup
-- 创建文件夹 FSNW,重新进行恢复
[oracle@indb oradata]$ mkdir FSNW [oracle@indb oradata]$ rman target /
Recovery Manager: Release 10.2.0.1.0 - Production on 星期一 9月 22 14:31:01 2008
Copyright (c) 1982, 2005, Oracle. All rights reserved.
connected to target database: FSNW (not mounted)
RMAN> restore controlfile from '/oracle/oradata/rmanbackup/CTL.c-734270689-20080922-03.rman';
Starting restore at 22-9月 -08
using target database control file instead of recovery catalog allocated channel: ORA_DISK_1 channel ORA_DISK_1: sid=159 devtype=DISK
channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:02 output filename=/oracle/oradata/FSNW/control01.ctl output filename=/oracle/oradata/FSNW/control02.ctl output filename=/oracle/oradata/FSNW/control03.ctl Finished restore at 22-9月 -08
RMAN> alter database mount;
database mounted
released channel: ORA_DISK_1 |
5.2 恢复数据文件
RMAN> restore database;
Starting restore at 22-9月 -08
Starting implicit crosscheck backup at 22-9月 -08 allocated channel: ORA_DISK_1 channel ORA_DISK_1: sid=159 devtype=DISK Crosschecked 3 objects Finished implicit crosscheck backup at 22-9月 -08
Starting implicit crosscheck copy at 22-9月 -08
using channel ORA_DISK_1 Finished implicit crosscheck copy at 22-9月 -08
searching for all files in the recovery area
cataloging files... no files cataloged
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set restoring datafile 00001 to /oracle/oradata/FSNW/system01.dbf restoring datafile 00002 to /oracle/oradata/FSNW/undotbs01.dbf restoring datafile 00003 to /oracle/oradata/FSNW/sysaux01.dbf restoring datafile 00004 to /oracle/oradata/FSNW/users01.dbf restoring datafile 00005 to /oracle/oradata/FSNW/FINANCE.dbf channel ORA_DISK_1: reading from backup piece /oracle/oradata/rmanbackup/DATA.0njr80sf_1_1.rman channel ORA_DISK_1: restored backup piece 1 piece handle=/oracle/oradata/rmanbackup/DATA.0njr80sf_1_1.rman tag=TAG20080922T141335 channel ORA_DISK_1: restore complete, elapsed time: 00:03:30 Finished restore at 22-9月 -08 |
5.3 恢复归档日志文件
-- 如果未删除过期的归档记录,则恢复归档日志时可能会出现错误,就像下面的这样:
RMAN> restore archivelog all;
Starting restore at 22-9月 -08
using channel ORA_DISK_1
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS =============== RMAN-00571: =========================================================== RMAN-03002: failure of restore command at 09/22/2008 14:37:08 RMAN-06026: some targets not found - aborting restore RMAN-06025: no backup of log thread 1 seq 3 lowscn 87447181 found to restore RMAN-06025: no backup of log thread 1 seq 2 lowscn 87447109 found to restore RMAN-06025: no backup of log thread 1 seq 1 lowscn 87439708 found to restore RMAN-06025: no backup of log thread 1 seq 1146 lowscn 87439440 found to restore RMAN-06025: no backup of log thread 1 seq 1145 lowscn 87439370 found to restore RMAN-06025: no backup of log thread 1 seq 1144 lowscn 87438455 found to restore RMAN-06025: no backup of log thread 1 seq 1143 lowscn 87438384 found to restore RMAN-06025: no backup of log thread 1 seq 1142 lowscn 87438291 found to restore RMAN-06025: no backup of log thread 1 seq 1141 lowscn 87438206 found to restore RMAN-06025: no backup of log thread 1 seq 1140 lowscn 87427959 found to restore RMAN-06025: no backup of log thread 1 seq 1139 lowscn 87383649 found to restore
-- 可以手工指定要恢复的归档日志序列号(序列号可以从备份记录中查到)
RMAN> restore archivelog sequence between 1 and 4;
Starting restore at 22-9月 -08
using channel ORA_DISK_1
channel ORA_DISK_1: starting archive log restore to default destination
channel ORA_DISK_1: restoring archive log archive log thread=1 sequence=1 channel ORA_DISK_1: restoring archive log archive log thread=1 sequence=2 channel ORA_DISK_1: restoring archive log archive log thread=1 sequence=3 channel ORA_DISK_1: restoring archive log archive log thread=1 sequence=4 channel ORA_DISK_1: reading from backup piece /oracle/oradata/rmanbackup/ARCH.0mjr80sc_1_1.rman channel ORA_DISK_1: restored backup piece 1 piece handle=/oracle/oradata/rmanbackup/ARCH.0mjr80sc_1_1.rman tag=TAG20080922T141332 channel ORA_DISK_1: restore complete, elapsed time: 00:00:03 Finished restore at 22-9月 -08
-- 恢复完指定序列号后,应该再尝试恢复后面的序列号,直到无对应的序列号为止
RMAN> restore archivelog sequence between 5 and 5;
Starting restore at 22-9月 -08
using channel ORA_DISK_1
channel ORA_DISK_1: starting archive log restore to default destination
channel ORA_DISK_1: restoring archive log archive log thread=1 sequence=5 channel ORA_DISK_1: reading from backup piece /oracle/oradata/rmanbackup/ARCH.0mjr80sc_1_1.rman channel ORA_DISK_1: restored backup piece 1 piece handle=/oracle/oradata/rmanbackup/ARCH.0mjr80sc_1_1.rman tag=TAG20080922T141332 channel ORA_DISK_1: restore complete, elapsed time: 00:00:01 Finished restore at 22-9月 -08
RMAN> restore archivelog sequence between 6 and 6;
Starting restore at 22-9月 -08
using channel ORA_DISK_1
channel ORA_DISK_1: starting archive log restore to default destination
channel ORA_DISK_1: restoring archive log archive log thread=1 sequence=6 channel ORA_DISK_1: reading from backup piece /oracle/oradata/rmanbackup/ARCH.0ojr812t_1_1.rman channel ORA_DISK_1: restored backup piece 1 piece handle=/oracle/oradata/rmanbackup/ARCH.0ojr812t_1_1.rman tag=TAG20080922T141700 channel ORA_DISK_1: restore complete, elapsed time: 00:00:02 Finished restore at 22-9月 -08
RMAN> restore archivelog sequence between 7 and 7;
Starting restore at 22-9月 -08
using channel ORA_DISK_1 RMAN-00571: =========================================================== RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS =============== RMAN-00571: =========================================================== RMAN-03002: failure of restore command at 09/22/2008 14:39:56 RMAN-20242: specification does not match any archive log in the recovery catalog |
5.4 修复数据库
-- 修复失败,因为缺少在线重做日志文件(此时可以进行不完全恢复)。
RMAN> recover database;
Starting recover at 22-9月 -08
using channel ORA_DISK_1
starting media recovery
archive log thread 1 sequence 6 is already on disk as file /oracle/oradata/arch/1_6_666101140.dbf
archive log filename=/oracle/oradata/arch/1_6_666101140.dbf thread=1 sequence=6 unable to find archive log archive log thread=1 sequence=7 RMAN-00571: =========================================================== RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS =============== RMAN-00571: =========================================================== RMAN-03002: failure of recover command at 09/22/2008 14:44:25 RMAN-06054: media recovery requesting unknown log: thread 1 seq 7 lowscn 87458540 |
5.4.1 这里假设未丢失在线日志文件(将在线日志文件拷贝回去),测试一下完全修复。
5.4.2 拷贝在线日志到原位置,测试完全恢复
5.4.3 再次recover数据库:成功
6. 打开数据库
7. 检查数据
RMAN> recover database;
Starting recover at 22-9月 -08
using channel ORA_DISK_1
starting media recovery
archive log thread 1 sequence 6 is already on disk as file /oracle/oradata/arch/1_6_666101140.dbf
archive log filename=/oracle/oradata/arch/1_6_666101140.dbf thread=1 sequence=6 unable to find archive log archive log thread=1 sequence=7 RMAN-00571: =========================================================== RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS =============== RMAN-00571: =========================================================== RMAN-03002: failure of recover command at 09/22/2008 14:44:25 RMAN-06054: media recovery requesting unknown log: thread 1 seq 7 lowscn 87458540 |
5.4.2 拷贝在线日志到原位置,测试完全恢复
RMAN> host;
[oracle@indb FSNW_BAK]$ cp *.log ../FSNW
[oracle@indb FSNW_BAK]$ exit exit host command complete |
5.4.3 再次recover数据库:成功
RMAN> recover database;
Starting recover at 22-9月 -08
using channel ORA_DISK_1
starting media recovery
archive log thread 1 sequence 7 is already on disk as file /oracle/oradata/FSNW/redo03.log
archive log filename=/oracle/oradata/FSNW/redo03.log thread=1 sequence=7 media recovery complete, elapsed time: 00:00:02 Finished recover at 22-9月 -08 |
6. 打开数据库
-- 由于恢复了控制文件,所以必须以resetlogs方式打开
RMAN> alter database open;
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS =============== RMAN-00571: =========================================================== RMAN-03002: failure of alter db command at 09/22/2008 14:46:02 ORA-01589: must use RESETLOGS or NORESETLOGS option for database open
RMAN> alter database open resetlogs;
database opened
|
7. 检查数据
-- 未丢失数据
RMAN> exit
Recovery Manager complete. [oracle@indb oradata]$ sqlplus
SQL*Plus: Release 10.2.0.1.0 - Production on 星期一 9月 22 14:49:32 2008
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Enter user-name: / as sysdba
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production With the Partitioning, OLAP and Data Mining options
SQL> select count(*) from test_tianyc;
COUNT(*)
---------- 49625 |