2007/06/07

oracle rman recover under nocatalog mode and without controlfile (DBMS_BACKUP_RESTORE)

dbmsbkrs.sql - dbms backup restore
prvtbkrs.plb - prvt backup restore

deviceAllocate (type, name, ident, noio, params) return varchar2
restoreControlfileTo
restoreDataFileTo



# backup databases
rman target / nocatalog << __EOF__
run {
allocate channel C1 type disk;
backup full tag 'FullBackup' format 'd:KDE%d_%u_%s_%p.dbf' database include current controlfile;
sql 'alter system archive log current';
release channel C1;
}
__EOF__

# simulate a database corruption
sqlplus "/ as sysdba" << __EOF__
shutdown immediate;
__EOF__
rm $ORADATA/$ORACLE_SID/*.dbf
rm $ORADATA/$ORACLE_SID/*.ora


# restore controlfile
sqlplus "/ as sysdba" << __EOF__
startup force nomount;

DECLARE
devtype varchar2(256);
done boolean;
BEGIN
devtype:=sys.dbms_backup_restore.deviceAllocate(
type=>'', -- can also be 'sbt_tape'
ident=>'T1');
sys.dbms_backup_restore.restoreSetDatafile;
sys.dbms_backup_restore.restoreControlfileTo(cfname=>'d:\oracle\Control01.ctl');
sys.dbms_backup_restore.restoreBackupPiece(
done=>done,
handle=>'D:\KDE\DEMO_01FR79OT_1_1.DBF',
params=>null);
sys.dbms_backup_restore.deviceDeallocate;
END;
/
__EOF__

# restore datafile
sqlplus "/ as sysdba" << __EOF__
DECLARE
devtype varchar2(256);
done boolean;
BEGIN
DECLARE
devtype varchar2(256);
done boolean;
BEGIN
devtype:=sys.dbms_backup_restore.deviceAllocate (type=>'',
ident=>'t1');
sys.dbms_backup_restore.restoreSetDatafile;
sys.dbms_backup_restore.restoreDatafileTo(dfnumber=>01,
toname=>'d:oracleoradatademoSYSTEM01.DBF');
sys.dbms_backup_restore.restoreDatafileTo(dfnumber=>02,
toname=>'d:oracleoradatademoUNDOTBS01.DBF');
sys.dbms_backup_restore.restoreDatafileTo(dfnumber=>03,
toname=>'d:oracleoradatademoDRSYS01.DBF');
sys.dbms_backup_restore.restoreDatafileTo(dfnumber=>04,
toname=>'d:oracleoradatademoEXAMPLE01.DBF');
sys.dbms_backup_restore.restoreDatafileTo(dfnumber=>05,
toname=>'d:oracleoradatademoINDX01.DBF');
sys.dbms_backup_restore.restoreDatafileTo(dfnumber=>06,
toname=>'d:oracleoradatademoODM01.DBF');
sys.dbms_backup_restore.restoreDatafileTo(dfnumber=>07,
toname=>'d:oracleoradatademoTOOLS01.DBF');
sys.dbms_backup_restore.restoreDatafileTo(dfnumber=>08,
toname=>'d:oracleoradatademoUSERS01.DBF');
sys.dbms_backup_restore.restoreDatafileTo(dfnumber=>09,
toname=>'d:oracleoradatademoXDB01.DBF');
sys.dbms_backup_restore.restoreBackupPiece(done=>done,
handle=>'D:KDEDEMO_01FR79OT_1_1.DBF',
params=>null);
sys.dbms_backup_restore.deviceDeallocate;
END;
/
__EOF__

# startup and recovery
sqlplus "/ as sysdba" << __EOF__
startup force mount;
recover database using backup controlfile until cancel;

-- the following message is prompted and answer should be entered manually
-- Specify log: {=suggested | filename | AUTO | CANCEL}
-- D:KDEARC00002.001
__EOF__

# reset logs and open the database
sqlplus "/ as sysdba" << __EOF__
alter database open resetlogs;
__EOF__


the guide line of nocatalog (controlfile) rman backup:
+ should backup controlfile independently and increase CONTROL_FILE_RECORD_KEEP_TIME to make the entries kept as long as possible
+ should make a complete backup plan
+ should be familiar to rman facility

No comments: