<style type="text/css"> <!-- p {margin-bottom:0.21cm} --> </style>
<style type="text/css"> <!-- p {margin-bottom:0.21cm} --> </style>
rman恢复
rman转储命令
restoredatabase --mount状态
restoretablespace --open状态
restoredatafile --mount或open状态
restorecontrolfile --nomount状态
restorearchivelog --mount或open状态
restorespfile --nomount状态
rman恢复命令
当执行recover命令时,rman会自动应用自最近备份以来的所有归档日志。
recoverdatabase --mount状态
recovertablespace --open状态
recoverdatafile --mount或open状态
恢复数据库
示例一所有数据文件被误删除
全备数据库。
删除所有数据文件。
使用restoredatabase转储所有数据文件,使用recoverdatabase恢复数据库,最后使用alterdatabase open 打开数据库。
[oracle@localhost ~]$ rman target sys/oracle@oralife nocatalog --全备数据库 RMAN> run{ 2> backup database format='/oracle/10g/oracle/rman/%d_%s.dbf' 3> tag='whole_bak'; 4> sql 'alter system archive log current'; 5> } --添加记录并切换日志 SQL> select count(*) from t; COUNT(*) ---------- 0 SQL> desc t; Name Null? Type ----------------------------------------- -------- ---------------------------- TEXT VARCHAR2(1000) SQL> insert into t select 'oracle' from dual; 1 row created. SQL> commit; Commit complete. SQL> alter system switch logfile; System altered. SQL> alter system checkpoint; System altered. --删除所有数据文件,并启动数据库 SQL> host rm $ORACLE_BASE/product/10.2.0/oradata/oralife/*.dbf SQL> shutdown immediate ORA-01116: error in opening database file 2 ORA-01110: data file 2: '/oracle/10g/oracle/product/10.2.0/oradata/oralife/undotbs01.dbf' ORA-27041: unable to open file Linux Error: 2: No such file or directory Additional information: 3 SQL> shutdown abort ORACLE instance shut down. SQL> startup ORACLE instance started. Total System Global Area 528482304 bytes Fixed Size 1220360 bytes Variable Size 163578104 bytes Database Buffers 356515840 bytes Redo Buffers 7168000 bytes Database mounted. ORA-01157: cannot identify/lock data file 1 - see DBWR trace file ORA-01110: data file 1: '/oracle/10g/oracle/product/10.2.0/oradata/oralife/system01.dbf' SQL> select file#,error from v$recover_file; FILE# ERROR ---------- ----------------------------------------------------------------- 1 FILE NOT FOUND 2 FILE NOT FOUND 3 FILE NOT FOUND 4 FILE NOT FOUND 5 FILE NOT FOUND --使用rman连接数据库,进入mount状态进行恢复 [oracle@localhost ~]$ rman target sys/oracle@oralife nocatalog RMAN> startup mount database is already started RMAN> run{ 2> restore database; 3> recover database; 4> sql 'alter database open'; 5> } --验证恢复情况 SQL> select * from t; TEXT -------------------------------------------------------------------------------- oracle<style type="text/css"> <!-- p {margin-bottom:0.21cm} --> </style>
示例二数据文件所在磁盘出现硬件故障
在restoredatabase之前,执行setnewname为数据文件指定新的位置。
在restoredatabase之后,执行switchdatafile改变控制文件中数据文件位置和名称。
之后通过执行recoverdatabase应用归档日志。
最后执行alterdatabase open打开数据库。
--删除所有数据文件来模拟磁盘故障,并打开数据库 SQL> host rm $ORACLE_BASE/product/10.2.0/oradata/oralife/*.dbf SQL> shutdown abort ORACLE instance shut down. SQL> startup ORACLE instance started. Total System Global Area 528482304 bytes Fixed Size 1220360 bytes Variable Size 163578104 bytes Database Buffers 356515840 bytes Redo Buffers 7168000 bytes Database mounted. ORA-01157: cannot identify/lock data file 1 - see DBWR trace file ORA-01110: data file 1: '/oracle/10g/oracle/product/10.2.0/oradata/oralife/system01.dbf' SQL> select file#,error from v$recover_file; FILE# ERROR ---------- ----------------------------------------------------------------- 1 FILE NOT FOUND 2 FILE NOT FOUND 3 FILE NOT FOUND 4 FILE NOT FOUND 5 FILE NOT FOUND SQL> column name for a100 SQL> set linesize 150 SQL> select file#,name from v$datafile; FILE# NAME ---------- ---------------------------------------------------------------------------------------------------- 1 /oracle/10g/oracle/product/10.2.0/oradata/oralife/system01.dbf 2 /oracle/10g/oracle/product/10.2.0/oradata/oralife/undotbs01.dbf 3 /oracle/10g/oracle/product/10.2.0/oradata/oralife/sysaux01.dbf 4 /oracle/10g/oracle/product/10.2.0/oradata/oralife/users01.dbf 5 /oracle/10g/oracle/product/10.2.0/oradata/oralife/example01.dbf --使用rman连接数据库,转储数据文件到oradatabak目录(其它磁盘) [oracle@localhost ~]$ rman target sys/oracle@oralife nocatalog RMAN> run{ 2> startup mount; 3> set newname for datafile 1 to '/oracle/10g/oracle/product/10.2.0/oradatabak/system01.dbf'; 4> set newname for datafile 2 to '/oracle/10g/oracle/product/10.2.0/oradatabak/undotbs01.dbf'; 5> set newname for datafile 3 to '/oracle/10g/oracle/product/10.2.0/oradatabak/sysaux01.dbf'; 6> set newname for datafile 4 to '/oracle/10g/oracle/product/10.2.0/oradatabak/users01.dbf'; 7> set newname for datafile 5 to '/oracle/10g/oracle/product/10.2.0/oradatabak/example01.dbf'; 8> restore database; 9> switch datafile all; 10> recover database; 11> sql 'alter database open'; 12> } --验证恢复情况 SQL> select file#,name,status from v$datafile; FILE# NAME STATUS ---------- ---------------------------------------------------------------------------------------------------- ------- 1 /oracle/10g/oracle/product/10.2.0/oradatabak/system01.dbf SYSTEM 2 /oracle/10g/oracle/product/10.2.0/oradatabak/undotbs01.dbf ONLINE 3 /oracle/10g/oracle/product/10.2.0/oradatabak/sysaux01.dbf ONLINE 4 /oracle/10g/oracle/product/10.2.0/oradatabak/users01.dbf ONLINE 5 /oracle/10g/oracle/product/10.2.0/oradatabak/example01.dbf ONLINE SQL> select * from t; TEXT --------------------------- oracle