数据库今天宕机了,数据文件和控制文件在一个磁盘,全部损坏,redo文件和
归档日志在两外一个磁盘,完好无损,只有两天前的rman全备份。经过30分钟的奋战,数据全部恢复。
模拟环境,具体恢复如下:
1:首先用rman全备份数据库数据(模拟两天前的rman全备份)
[oracle@www oracle]$ rman target /
Recovery Manager: Release 9.2.0.8.0 - Production
Copyright (c) 1995, 2002, Oracle Corporation. All rights reserved.
connected to target database: EXITGOGO (DBID=267967027)
www.ixdba.net
RMAN> backup database;
Starting backup at 23-11月-06
using target database controlfile instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=11 devtype=DISK
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00001 name=/free/oracle/oradata/exitgogo/system01.dbf
input datafile fno=00002 name=/free/oracle/oradata/exitgogo/undotbs01.dbf
input datafile fno=00003 name=/free/oracle/oradata/exitgogo/users01.dbf
input datafile fno=00006 name=/free/oracle/oradata/exitgogo/pub.dbf
input datafile fno=00004 name=/free/oracle/oradata/exitgogo/tools01.dbf
input datafile fno=00005 name=/free/oracle/oradata/exitgogo/indx01.dbf
channel ORA_DISK_1: starting piece 1 at 23-11月-06
channel ORA_DISK_1: finished piece 1 at 23-11月-06
piece handle=/free/oracle/product/9.2.0.8/dbs/03i34pja_1_1 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:06
Finished backup at 23-11月-06
Starting Control File Autobackup at 23-11月-06
piece handle=/free/oracle/orabak/c-267967027-20061123-01 comment=NONE
Finished Control File Autobackup at 23-11月-06
RMAN> show all;
RMAN configuration parameters are:
CONFIGURE RETENTION POLICY TO REDUNDANCY 2;
CONFIGURE BACKUP OPTIMIZATION ON;
CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/free/oracle/orabak/%F';
CONFIGURE DEVICE TYPE DISK PARALLELISM 1;
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
RMAN configuration has no stored or default parameters
CONFIGURE MAXSETSIZE TO UNLIMITED; # default
CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/free/oracle/product/9.2.0.8/dbs/snapcf_exitgogo.f'; # default
RMAN>quit
2:创建一个新的表空间,然后添加测试数据(模拟两天之间数据库的变化)
创建了一个新的表空间pub,然后创建了用户pub。
[oracle@www oracle]$ sqlplus pub/pub
SQL*Plus: Release 9.2.0.8.0 - Production on 星期四 11月 23 17:37:28 2006
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
Connected to:
Oracle9i Enterprise Edition Release 9.2.0.8.0 - Production
With the Partitioning and Oracle Data Mining options
JServer Release 9.2.0.8.0 – Production
添加一点测试数据:
SQL> create table gaojf1 as select * from all_objects;
Table created.
SQL> insert into gaojf1 select * from gaojf1;
5884 rows created.
SQL> /
11768 rows created.
SQL> /
。。。。。。。。。。。
188288 rows created.
SQL> /
376576 rows created.
SQL> commit;
Commit complete.
SQL> quit
Disconnected from Oracle9i Enterprise Edition Release 9.2.0.8.0 - Production
With the Partitioning and Oracle Data Mining options
JServer Release 9.2.0.8.0 - Production
3:删除所有数据文件和控制文件(模拟数据库宕机)
[oracle@www exitgogo]$ls -sh
total 886M
3.5M control01.ctl 33M indx01.dbf 51M redo02.log 136K temp01.dbf 129M users01.dbf 3.5M control02.ctl 101M pub.dbf 51M redo03.log 65M tools01.dbf 3.5M control03.ctl 51M redo01.log 201M system01.dbf 201M undotbs01.dbf
[oracle@www exitgogo]$ rm -rf ./*.dbf ./*.ctl
[oracle@www exitgogo]$ ls
redo01.log redo02.log redo03.log
4:恢复开始:
[oracle@www exitgogo]$ rman target /
Recovery Manager: Release 9.2.0.8.0 - Production
Copyright (c) 1995, 2002, Oracle Corporation. All rights reserved.
connected to target database (not started)
RMAN> startup nomount
Oracle instance started
Total System Global Area 235999648 bytes
Fixed Size 450976 bytes
Variable Size 201326592 bytes
Database Buffers 33554432 bytes
Redo Buffers 667648 bytes
首先从原来的全备份中恢复控制文件
RMAN>
restore controlfile from '/free/oracle/orabak/c-267967027-20061123-01';
Starting restore at 23-11月-06
using target database controlfile instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=13 devtype=DISK
channel ORA_DISK_1: restoring controlfile
channel ORA_DISK_1: restore complete
replicating controlfile
input filename=/free/oracle/oradata/exitgogo/control01.ctl
output filename=/free/oracle/oradata/exitgogo/control02.ctl
output filename=/free/oracle/oradata/exitgogo/control03.ctl
Finished restore at 23-11月-06
RMAN> alter database mount;
database mounted
RMAN> list backup;
List of Backup Sets
===================
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
1 Full 3M DISK 00:00:00 23-11月-06
BP Key: 1 Status: AVAILABLE Tag:
Piece Name: /free/oracle/orabak/c-267967027-20061123-01
Controlfile Included: Ckp SCN: 73561 Ckp time: 23-11月-06
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
2 Full 223M DISK 00:00:57 23-11月-06
BP Key: 2 Status: AVAILABLE Tag: TAG20061123T173423
Piece Name: /free/oracle/product/9.2.0.8/dbs/03i34p90_1_1
List of Datafiles in backup set 2
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- ---------- ----
1 Full 73688 23-11月-06 /free/oracle/oradata/exitgogo/system01.dbf
2 Full 73688 23-11月-06 /free/oracle/oradata/exitgogo/undotbs01.dbf
3 Full 73688 23-11月-06 /free/oracle/oradata/exitgogo/users01.dbf
4 Full 73688 23-11月-06 /free/oracle/oradata/exitgogo/tools01.dbf
5 Full 73688 23-11月-06 /free/oracle/oradata/exitgogo/indx01.dbf
还原数据文件
RMAN> restore database;
Starting restore at 23-11月-06
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 /free/oracle/oradata/exitgogo/system01.dbf
restoring datafile 00002 to /free/oracle/oradata/exitgogo/undotbs01.dbf
restoring datafile 00003 to /free/oracle/oradata/exitgogo/users01.dbf
restoring datafile 00004 to /free/oracle/oradata/exitgogo/tools01.dbf
restoring datafile 00005 to /free/oracle/oradata/exitgogo/indx01.dbf
channel ORA_DISK_1: restored backup piece 1
piece handle=/free/oracle/product/9.2.0.8/dbs/03i34p90_1_1 tag=TAG20061123T173423 params=NULL
channel ORA_DISK_1: restore complete
Finished restore at 23-11月-06
RMAN> quit
下面进入sqlplus进行不完全恢复
[oracle@www exitgogo]$ sqlplus "/as sysdba"
SQL*Plus: Release 9.2.0.8.0 - Production on 星期四 11月 23 17:51:07 2006
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
Connected to:
Oracle9i Enterprise Edition Release 9.2.0.8.0 - Production
With the Partitioning and Oracle Data Mining options
JServer Release 9.2.0.8.0 - Production
SQL> select name from v$datafile;
NAME
------------------------------------------------------------------------------
/free/oracle/oradata/exitgogo/system01.dbf
/free/oracle/oradata/exitgogo/undotbs01.dbf
/free/oracle/oradata/exitgogo/users01.dbf
/free/oracle/oradata/exitgogo/tools01.dbf
/free/oracle/oradata/exitgogo/indx01.dbf
可以看到,由于rman的全备份早于创建pub表空间,因此restore恢复中没有记录pub表空间的信息,但是由于redo file中还记录了pub表空间创建的信息,因此,先recover试试!
SQL> recover database using backup controlfile;
ORA-00279: change 73688 generated at 11/23/2006 17:34:24 needed for thread 1
ORA-00289: suggestion :
/free/oracle/product/9.2.0.8/dbs/archexitgogo/T0001S0000000008.ARC
ORA-00280: change 73688 for thread 1 is in sequence #8
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
auto
ORA-00283: recovery session canceled due to errors
ORA-01244: unnamed datafile(s) added to controlfile by media recovery
ORA-01110: data file 6: '/free/oracle/oradata/exitgogo/pub.dbf'
ORA-01112: media recovery not started
可以看到,在恢复了一个归档日志以后,oracle认出了pub表空间,同时提示了ORA-01244