Oracle dbms_backup_restore恢复数据库

Oracle Version:Oracle 10.2.0.5 64bit
OS:RHEL5.4 64bit


1.fullbackup
[oracle@Kin ~]$ rman target /


Recovery Manager: Release 10.2.0.5.0 - Production on Mon Sep 17 17:00:14 2012


Copyright (c) 1982, 2007, Oracle.  All rights reserved.


connected to target database: KIN (DBID=2123478169)


RMAN> show all;
using target database control file instead of recovery catalog
RMAN configuration parameters are:
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 14 DAYS;
CONFIGURE BACKUP OPTIMIZATION OFF; # default
CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default
CONFIGURE CONTROLFILE AUTOBACKUP OFF; # default
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '%F'; # default
CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET; # default
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK 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 '/oracle/oracle10g/dbs/snapcf_KIN.f'; # default


RMAN> backup database format '/db/backup/full_%d_%T_%s';


Starting backup at 17-SEP-12
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=158 devtype=DISK
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00001 name=/oradata/KIN/system01.dbf
input datafile fno=00002 name=/oradata/KIN/undotbs01.dbf
input datafile fno=00003 name=/oradata/KIN/sysaux01.dbf
input datafile fno=00005 name=/oradata/KIN/kin.dbf
channel ORA_DISK_1: starting piece 1 at 17-SEP-12
channel ORA_DISK_1: finished piece 1 at 17-SEP-12
piece handle=/db/backup/full_KIN_20120917_5 tag=TAG20120917T170520 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:35
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
including current control file in backupset
including current SPFILE in backupset
channel ORA_DISK_1: starting piece 1 at 17-SEP-12
channel ORA_DISK_1: finished piece 1 at 17-SEP-12
piece handle=/db/backup/full_KIN_20120917_6 tag=TAG20120917T170520 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:05
Finished backup at 17-SEP-12


2.archivelog backup
RMAN> backup format '/db/backup/arch_%d_%T_%s' archivelog all delete input;


Starting backup at 17-SEP-12
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=26 recid=16 stamp=794250422
input archive log thread=1 sequence=27 recid=17 stamp=794250423
input archive log thread=1 sequence=28 recid=18 stamp=794250427
input archive log thread=1 sequence=29 recid=19 stamp=794250508
channel ORA_DISK_1: starting piece 1 at 17-SEP-12
channel ORA_DISK_1: finished piece 1 at 17-SEP-12
piece handle=/db/backup/arch_KIN_20120917_7 tag=TAG20120917T170828 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03
channel ORA_DISK_1: deleting archive log(s)
archive log filename=/oradata/KIN/archive/KIN_1_26_790937753.arc recid=16 stamp=794250422
archive log filename=/oradata/KIN/archive/KIN_1_27_790937753.arc recid=17 stamp=794250423
archive log filename=/oradata/KIN/archive/KIN_1_28_790937753.arc recid=18 stamp=794250427
archive log filename=/oradata/KIN/archive/KIN_1_29_790937753.arc recid=19 stamp=794250508
Finished backup at 17-SEP-12


RMAN> list backup of controlfile;




List of Backup Sets
===================


BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
3       Full    6.77M      DISK        00:00:02     05-SEP-12      
        BP Key: 3   Status: AVAILABLE  Compressed: NO  Tag: DBFULL
        Piece Name: /db/backup/dbfullbackup_KIN_20120905_3
  Control File Included: Ckp SCN: 471210       Ckp time: 05-SEP-12


BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
6       Full    6.80M      DISK        00:00:03     17-SEP-12      
        BP Key: 6   Status: AVAILABLE  Compressed: NO  Tag: TAG20120917T170520
        Piece Name: /db/backup/full_KIN_20120917_6
  Control File Included: Ckp SCN: 476736       Ckp time: 17-SEP-12
  
3.Query the file location
[oracle@Kin backup]$ sqlplus '/as sysdba'


SQL*Plus: Release 10.2.0.5.0 - Production on Mon Sep 17 17:15:40 2012


Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.




Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options


SQL> select name from v$datafile;


NAME
--------------------------------------------------------------------------------
/oradata/KIN/system01.dbf
/oradata/KIN/undotbs01.dbf
/oradata/KIN/sysaux01.dbf
/oradata/KIN/kin.dbf


GROUP# STATUS TYPE   MEMBER  IS_RECOVERY_DEST_FILE
------ ------ -------------------- ------------------------------ -------------------------
     1      ONLINE   /oradata/KIN/redo01.log  NO
     2      ONLINE   /oradata/KIN/redo02.log  NO
     3      ONLINE   /oradata/KIN/redo03.log  NO
 


SQL> select * from v$controlfile;


STATUS   NAME  IS_RECOVERY_DEST_FILE     BLOCK_SIZE FILE_SIZE_BLKS
---------- ------------------------------ ------------------------- ---------- --------------
  /oradata/KIN/control01.ctl  NO 16384  430
  /oradata/KIN/control02.ctl  NO 16384  430
  /oradata/KIN/control03.ctl  NO 16384  430


4.Use dbms_backup_restore to restore Database


startup nomount;


Restore controlfile:
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.restorecontrolfileto(cfname=>'/oradata/KIN/control01.ctl');
sys.dbms_backup_restore.restorebackuppiece(done=>done,handle=>'/db/backup/full_KIN_20120917_6',params=>null);
sys.dbms_backup_restore.devicedeallocate;
end;
/


Restore datafile:
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=>'/oradata/KIN/system01.dbf');
sys.dbms_backup_restore.restoredatafileto(dfnumber=>02,toname=>'/oradata/KIN/undotbs01.dbf');
sys.dbms_backup_restore.restoredatafileto(dfnumber=>03,toname=>'/oradata/KIN/sysaux01.dbf');
sys.dbms_backup_restore.restoredatafileto(dfnumber=>05,toname=>'/oradata/KIN/kin.dbf');
sys.dbms_backup_restore.restorebackuppiece(done=>done,handle=>'/db/backup/full_KIN_20120917_5',params=>null);
sys.dbms_backup_restore.devicedeallocate;
end;
/


startup mount;


Restore archive:
mkdir archive


declare
devtype varchar2(256);
done boolean;
begin
devtype:=sys.dbms_backup_restore.deviceallocate(type=>'',ident=>'t1');
sys.dbms_backup_restore.restoresetarchivedlog(destination=>'/oradata/KIN/archive');
sys.dbms_backup_restore.restorearchivedlog(thread=>1,sequence=>26);
sys.dbms_backup_restore.restorearchivedlog(thread=>1,sequence=>27);
sys.dbms_backup_restore.restorearchivedlog(thread=>1,sequence=>28);
sys.dbms_backup_restore.restorearchivedlog(thread=>1,sequence=>29);
sys.dbms_backup_restore.restorebackuppiece(done=>done,handle=>'/db/backup/arch_KIN_20120917_7',params=>null);
sys.dbms_backup_restore.devicedeallocate;
end;
/


recover database using backup controlfile until cancel;


alter database open resetlogs;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值