一、查看RMAN备份参数
[oracle@oraserver ~]$ rman target /
Recovery Manager: Release 10.2.0.1.0 - Productionon Mon Aug 15 13:21:54 2011
Copyright (c) 1982, 2005, Oracle. All rights reserved.
connected to target database: MYDATA(DBID=305115346)
RMAN> show all;
using target database control file instead of recoverycatalog
RMAN configuration parameters are:
CONFIGURE RETENTION POLICY TO REDUNDANCY 1; #default
CONFIGURE BACKUP OPTIMIZATION OFF; # default
CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default
CONFIGURE CONTROLFILE AUTOBACKUP OFF; # default
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICETYPE DISK TO '%F'; # default
CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUPTYPE TO BACKUPSET; # default
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPEDISK TO 1; # default
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPEDISK TO 1; # default
CONFIGURE MAXSETSIZE TO UNLIMITED; # default
CONFIGURE ENCRYPTION FOR DATABASE OFF; # default
CONFIGURE ENCRYPTION ALGORITHM 'AES128'; # default
CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; #default
CONFIGURE SNAPSHOT CONTROLFILE NAME TO'/orahome/oracle/product/10.2.0/db_1/dbs/snapcf_mydata.f'; # default
RMAN> list backup;
二、执行RMAN备份
1、全库备份
RMAN> backup database;
Starting backup at 15-AUG-11
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=154 devtype=DISK
channel ORA_DISK_1: starting full datafilebackupset
channel ORA_DISK_1: specifying datafile(s) inbackupset
input datafile fno=00001name=/oradata/mydata/mydata/system01.dbf
input datafile fno=00003name=/oradata/mydata/mydata/sysaux01.dbf
input datafile fno=00002name=/oradata/mydata/mydata/undotbs01.dbf
input datafile fno=00005name=/oradata/mydata/mydata/example01.dbf
input datafile fno=00004name=/oradata/mydata/mydata/users01.dbf
channel ORA_DISK_1: starting piece 1 at 15-AUG-11
channel ORA_DISK_1: finished piece 1 at 15-AUG-11
piecehandle=/orahome/flash_recovery_area/MYDATA/backupset/2011_08_15/o1_mf_nnndf_TAG20110815T132445_74kcdxvn_.bkptag=TAG20110815T132445 comment=NONE
channel ORA_DISK_1: backup set complete, elapsedtime: 00:00:45
channel ORA_DISK_1: starting full datafilebackupset
channel ORA_DISK_1: specifying datafile(s) inbackupset
including current control file in backupset
including current SPFILE in backupset
channel ORA_DISK_1: starting piece 1 at 15-AUG-11
channel ORA_DISK_1: finished piece 1 at 15-AUG-11
piecehandle=/orahome/flash_recovery_area/MYDATA/backupset/2011_08_15/o1_mf_ncsnf_TAG20110815T132445_74kcgdj8_.bkptag=TAG20110815T132445 comment=NONE
channel ORA_DISK_1: backup set complete, elapsedtime: 00:00:04
Finished backup at 15-AUG-11
2、备份归档日志
RMAN> backup archivelog all delete input;
Starting backup at 15-AUG-11
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archive log backupset
channel ORA_DISK_1: specifying archive log(s) inbackup set
input archive log thread=1 sequence=3 recid=1stamp=758254922
input archive log thread=1 sequence=4 recid=2stamp=758346126
input archive log thread=1 sequence=5 recid=3stamp=758459109
input archive log thread=1 sequence=6 recid=4stamp=758570310
input archive log thread=1 sequence=7 recid=5stamp=758661373
input archive log thread=1 sequence=8 recid=6stamp=758729176
input archive log thread=1 sequence=9 recid=7stamp=758733084
input archive log thread=1 sequence=10 recid=8stamp=758761235
input archive log thread=1 sequence=11 recid=9stamp=758844014
input archive log thread=1 sequence=12 recid=10stamp=758930411
input archive log thread=1 sequence=13 recid=11stamp=759002811
input archive log thread=1 sequence=14 recid=12stamp=759046328
input archive log thread=1 sequence=15 recid=13stamp=759146966
input archive log thread=1 sequence=16 recid=14stamp=759246991
channel ORA_DISK_1: starting piece 1 at 15-AUG-11
channel ORA_DISK_1: finished piece 1 at 15-AUG-11
piece handle=/orahome/flash_recovery_area/MYDATA/backupset/2011_08_15/o1_mf_annnn_TAG20110815T135631_74kf8k2h_.bkptag=TAG20110815T135631 comment=NONE
channel ORA_DISK_1: backup set complete, elapsedtime: 00:00:36
channel ORA_DISK_1: deleting archive log(s)
archive logfilename=/orahome/flash_recovery_area/MYDATA/archivelog/2011_08_04/o1_mf_1_3_73m4g9ht_.arcrecid=1 stamp=758254922
archive logfilename=/orahome/flash_recovery_area/MYDATA/archivelog/2011_08_05/o1_mf_1_4_73oxjffh_.arcrecid=2 stamp=758346126
archive logfilename=/orahome/flash_recovery_area/MYDATA/archivelog/2011_08_06/o1_mf_1_5_73scv41h_.arcrecid=3 stamp=758459109
archive logfilename=/orahome/flash_recovery_area/MYDATA/archivelog/2011_08_07/o1_mf_1_6_73wrg5ov_.arcrecid=4 stamp=758570310
archive logfilename=/orahome/flash_recovery_area/MYDATA/archivelog/2011_08_08/o1_mf_1_7_73zkcwh3_.arcrecid=5 stamp=758661373
archive logfilename=/orahome/flash_recovery_area/MYDATA/archivelog/2011_08_09/o1_mf_1_8_741mlq6o_.arcrecid=6 stamp=758729176
archive logfilename=/orahome/flash_recovery_area/MYDATA/archivelog/2011_08_09/o1_mf_1_9_741qdvq6_.arcrecid=7 stamp=758733084
archive logfilename=/orahome/flash_recovery_area/MYDATA/archivelog/2011_08_09/o1_mf_1_10_742lwl6y_.arcrecid=8 stamp=758761235
archive logfilename=/orahome/flash_recovery_area/MYDATA/archivelog/2011_08_10/o1_mf_1_11_7453qfps_.arcrecid=9 stamp=758844014
archive logfilename=/orahome/flash_recovery_area/MYDATA/archivelog/2011_08_11/o1_mf_1_12_747r39d5_.arcrecid=10 stamp=758930411
archive logfilename=/orahome/flash_recovery_area/MYDATA/archivelog/2011_08_12/o1_mf_1_13_749ysv2t_.arcrecid=11 stamp=759002811
archive logfilename=/orahome/flash_recovery_area/MYDATA/archivelog/2011_08_13/o1_mf_1_14_74c99q5d_.arcrecid=12 stamp=759046328
archive logfilename=/orahome/flash_recovery_area/MYDATA/archivelog/2011_08_14/o1_mf_1_15_74gclo7p_.arcrecid=13 stamp=759146966
archive logfilename=/orahome/flash_recovery_area/MYDATA/archivelog/2011_08_15/o1_mf_1_16_74kf8g2z_.arcrecid=14 stamp=759246991
Finished backup at 15-AUG-11
RMAN>
3、查看controlfile备份
RMAN> list backup of controlfile;
List of Backup Sets
===================
BS Key TypeLV Size Device Type Elapsed TimeCompletion Time
------- ---- -- ---------- ----------------------- ---------------
2 Full 6.80M DISK 00:00:01 15-AUG-11
BPKey: 2 Status: AVAILABLE Compressed: NO Tag: TAG20110815T132445
Piece Name:/orahome/flash_recovery_area/MYDATA/backupset/2011_08_15/o1_mf_ncsnf_TAG20110815T132445_74kcgdj8_.bkp
ControlFile Included: Ckp SCN: 1223929 Ckptime: 15-AUG-11
RMAN> exit
Recovery Manager complete.
二、通过视图查看数据库数据文件、控制文件、日志文件路径信息
1、查看数据文件
[oracle@oraserver ~]$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.1.0 - Production on MonAug 15 14:02:09 2011
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Miningoptions
查看数据文件
SQL> select name from v$datafile;
NAME
--------------------------------------------------------------------------------
/oradata/mydata/mydata/system01.dbf
/oradata/mydata/mydata/undotbs01.dbf
/oradata/mydata/mydata/sysaux01.dbf
/oradata/mydata/mydata/users01.dbf
/oradata/mydata/mydata/example01.dbf
2、查看日志文件
SQL> col member for a40
SQL> select * from v$logfile;
GROUP# STATUS TYPE MEMBER IS_RECOVERY_DEST_FILE
------ -------- ------------------------------------------ ----------------------
3 ONLINE /oradata/mydata/mydata/redo03.log NO
2 ONLINE /oradata/mydata/mydata/redo02.log NO
1 ONLINE /oradata/mydata/mydata/redo01.log NO
3、查看控制文件
SQL> col name for a40
SQL> select * from v$controlfile;
STATUS NAME IS_RECOVERY_DEST_FILE BLOCK_SIZEFILE_SIZE_BLKS
-------- --------------------------------------------------------------- ---------- --------------
/oradata/mydata/mydata/control01.ctl NO 16384 430
/oradata/mydata/mydata/control02.ctl NO 16384 430
/oradata/mydata/mydata/control03.ctl NO 16384 430
三、删除所有数据文件、控制文件、日志文件
[oracle@oraserver mydata]$ pwd
/oradata/mydata/mydata
[oracle@oraserver mydata]$ ll
总用量 1257640
-rw-r----- 1 oracle oinstall 7061504 8月 15 14:19 control01.ctl
-rw-r----- 1 oracle oinstall 7061504 8月 15 14:19 control02.ctl
-rw-r----- 1 oracle oinstall 7061504 8月 15 14:19 control03.ctl
-rw-r----- 1 oracle oinstall 104865792 8月 1514:01 example01.dbf
-rw-r----- 1 oracle oinstall 52429312 8月 15 14:19 redo01.log
-rw-r----- 1 oracle oinstall 52429312 8月 14 10:09 redo02.log
-rw-r----- 1 oracle oinstall 52429312 8月 15 13:56 redo03.log
-rw-r----- 1 oracle oinstall 325066752 8月 1514:19 sysaux01.dbf
-rw-r----- 1 oracle oinstall 513810432 8月 1514:19 system01.dbf
-rw-r----- 1 oracle oinstall 20979712 8月 13 06:00 temp01.dbf
-rw-r----- 1 oracle oinstall 157294592 8月 1514:18 undotbs01.dbf
-rw-r----- 1 oracle oinstall 5251072 8月 15 14:01 users01.dbf
[oracle@oraserver mydata]$ rm -rf *
[oracle@oraserver mydata]$ ls
[oracle@oraserver mydata]$
用dbms_backup_restore包恢复数据库
[oracle@oraserver mydata]$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.1.0 - Production on MonAug 15 14:24:57 2011
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Miningoptions
SQL> shutdown abort
ORACLE instance shut down.
SQL> startup
ORACLE instance started.
Total System Global Area 603979776 bytes
Fixed Size 1220796 bytes
Variable Size 180358980 bytes
Database Buffers 415236096 bytes
Redo Buffers 7163904 bytes
ORA-00205: error in identifying control file,check alert log for more info
丢失控制文件,数据库启动到nomount状态。
1、恢复控制文件
SQL> declare
2 devtype varchar2(256);
3 done boolean;
4 begin
5 devtype:=sys.dbms_backup_restore.deviceallocate(type=>'',ident=>'t1');
6 sys.dbms_backup_restore.restoresetdatafile;
7 sys.dbms_backup_restore.restorecontrolfileto(cfname=>'/oradata/mydata/mydata/control01.ctl');
8 sys.dbms_backup_restore.restorebackuppiece(done=>done,handle=>'/orahome/flash_recovery_area/MYDATA/backupset/2011_08_15/o1_mf_ncsnf_TAG20110815T132445_74kcgdj8_.bkp');
9 sys.dbms_backup_restore.devicedeallocate;
10 end;
11 /
PL/SQL procedure successfully completed.
2、恢复数据文件
SQL> declare
2 devtype varchar2(256);
3 done boolean;
4 begin
5 devtype:=sys.dbms_backup_restore.deviceallocate(type=>'',ident=>'t1');
6 sys.dbms_backup_restore.restoresetdatafile;
7 sys.dbms_backup_restore.restoredatafileto(dfnumber=>01,toname=>'/oradata/mydata/mydata/system01.dbf');
8 sys.dbms_backup_restore.restoredatafileto(dfnumber=>02,toname=>'/oradata/mydata/mydata/undotbs01.dbf');
9 sys.dbms_backup_restore.restoredatafileto(dfnumber=>03,toname=>'/oradata/mydata/mydata/sysaux01.dbf');
10 sys.dbms_backup_restore.restoredatafileto(dfnumber=>04,toname=>'/oradata/mydata/mydata/users01.dbf');
11 sys.dbms_backup_restore.restoredatafileto(dfnumber=>05,toname=>'/oradata/mydata/mydata/example01.dbf');
12 sys.dbms_backup_restore.restorebackuppiece(done=>done,handle=>'/orahome/flash_recovery_area/MYDATA/backupset/2011_08_15/o1_mf_nnndf_TAG20110815T132445_74kcdxvn_.bkp');
13 sys.dbms_backup_restore.devicedeallocate;
14 end;
15 /
注意:这里每个dbf文件的dfnumber必须与未出现故障时,每个dbf文件的number一致,可通过selectfile#,name from v$datafile中查询。
若不一致,恢复后打开数据库会报错,如:
SQL>
SQL> alter database mount;
Database altered.
SQL> alter database open;
alter database open
*
ERROR at line 1:
ORA-01122: database file 1 failed verificationcheck
ORA-01110: data file 1:'/oradata/mydata/mydata/system01.dbf'
ORA-01251: Unknown File Header Version read forfile number 1
SQL> host ls /oradata/mydata/mydata
control01.ctl example01.dbf sysaux01.dbf system01.dbf undotbs01.dbf users01.dbf
[oracle@oraserver mydata]$ cp control01.ctlcontrol02.ctl
[oracle@oraserver mydata]$ cp control01.ctlcontrol03.ctl
SQL> startup nomount
ORA-01081: cannot start already-running ORACLE -shut it down first
SQL> startup mount
ORA-01081: cannot start already-running ORACLE -shut it down first
SQL> shutdown immediate
ORA-01507: database not mounted
ORACLE instance shut down.
SQL> startup nomount
ORACLE instance started.
Total System Global Area 603979776 bytes
Fixed Size 1220796 bytes
Variable Size 180358980 bytes
Database Buffers 415236096 bytes
Redo Buffers 7163904 bytes
SQL> alter database mount;
Database altered.
declare
devtype varchar2(256);
done boolean;
begin
devtype:=sys.dbms_backup_restore.deviceallocate(type=>'',ident=>'t1');
sys.dbms_backup_restore.restoresetarchivedlog(destination=>'/orahome/flash_recovery_area/MYDATA/archivelog');
sys.dbms_backup_restore.restorearchivedlog(thread=>1,sequence=>3);
sys.dbms_backup_restore.restorearchivedlog(thread=>1,sequence=>4);
sys.dbms_backup_restore.restorearchivedlog(thread=>1,sequence=>5);
sys.dbms_backup_restore.restorearchivedlog(thread=>1,sequence=>6);
sys.dbms_backup_restore.restorearchivedlog(thread=>1,sequence=>7);
sys.dbms_backup_restore.restorearchivedlog(thread=>1,sequence=>8);
sys.dbms_backup_restore.restorearchivedlog(thread=>1,sequence=>9);
sys.dbms_backup_restore.restorearchivedlog(thread=>1,sequence=>10);
sys.dbms_backup_restore.restorearchivedlog(thread=>1,sequence=>11);
sys.dbms_backup_restore.restorearchivedlog(thread=>1,sequence=>12);
sys.dbms_backup_restore.restorearchivedlog(thread=>1,sequence=>13);
sys.dbms_backup_restore.restorearchivedlog(thread=>1,sequence=>14);
sys.dbms_backup_restore.restorearchivedlog(thread=>1,sequence=>15);
sys.dbms_backup_restore.restorearchivedlog(thread=>1,sequence=>16);
sys.dbms_backup_restore.restorebackuppiece(done=>done,handle=>'/orahome/flash_recovery_area/MYDATA/backupset/2011_08_15/o1_mf_nnndf_TAG20110815T132445_74kcdxvn_.bkp');
sys.dbms_backup_restore.devicedeallocate;
end;
/
SQL> alter database open;
alter database open
*
ERROR at line 1:
ORA-01589: must use RESETLOGS or NORESETLOGSoption for database open
使用controlfile恢复数据库
SQL> recover database until cancel using backupcontrolfile;
ORA-00279: change 1223908 generated at 08/15/201113:24:45 needed for thread 1
ORA-00289: suggestion :
/orahome/flash_recovery_area/MYDATA/archivelog/2011_08_15/o1_mf_1_16_%u_.arc
ORA-00280: change 1223908 for thread 1 is insequence #16
Specify log: {<RET>=suggested | filename |AUTO | CANCEL}
auto
ORA-00279: change 1225044 generated at 08/15/201113:56:30 needed for thread 1
ORA-00289: suggestion :
/orahome/flash_recovery_area/MYDATA/archivelog/2011_08_15/o1_mf_1_17_%u_.arc
ORA-00280: change 1225044 for thread 1 is insequence #17
ORA-00278: log file
'/orahome/flash_recovery_area/MYDATA/archivelog/1_16_758221587.dbf'no longer
needed for this recovery
ORA-00308: cannot open archived log
'/orahome/flash_recovery_area/MYDATA/archivelog/2011_08_15/o1_mf_1_17_%u_.arc'
ORA-27037: unable to obtain file status
Linux Error: 2: No such file or directory
Additional information: 3
resetlog打开数据库
SQL> alter database open resetlogs;
Database altered.
SQL>