Oracle RMAN 完全恢复

 

Objective

Describe the use of RMAN for restoration and recovery

Perform complete recovery in ARCHIVELOG mode

Restore datafiles to different locations

Relocate and recover a tablespace by using archived redo log files

 

 

Restoration Using RMAN

Restore files from backup sets or image copies by using the RMAN RESTORE command

Recover files by using the RMAN RECOVER command

 

 

Using RMAN in ARCHIVELOG

rman target /

RMAN> STARTUP MOUNT

RMAN> RESTORE DATABASE;

RMAN> RECOVER DATABASE;

RMAN> ALTER DATABASE OPEN;

 

 

下面开始实验:

 

实验环境:

SYSTEMIBM AIX 5L                       ORACLE VERSION: 11g R2

 

 

rman target sys/oracle@orcl nocatalog  

 

Recovery Manager: Release 11.2.0.1.0 - Production on Thu Apr 14 09:03:20 2011

 

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

 

connected to target database: ORCL (DBID=1276064171)

using target database control file instead of recovery catalog

 

RMAN> list backup;

 

specification does not match any backup in the repository

 

RMAN> backup database format '/u02/backup/orcl_%U';  --准备一个全备

 

Starting backup at 14-APR-11

using channel ORA_DISK_1

channel ORA_DISK_1: starting full datafile backup set

channel ORA_DISK_1: specifying datafile(s) in backup set

input datafile file number=00001 name=/u01/app/oracle/oradata/orcl/system01.dbf

input datafile file number=00002 name=/u01/app/oracle/oradata/orcl/sysaux01.dbf

input datafile file number=00003 name=/u01/app/oracle/oradata/orcl/undotbs01.dbf

input datafile file number=00005 name=/u01/app/oracle/oradata/orcl/example01.dbf

input datafile file number=00006 name=/u01/app/oracle/oradata/orcl/app01.dbf

input datafile file number=00004 name=/u01/app/oracle/oradata/orcl/users01.dbf

channel ORA_DISK_1: starting piece 1 at 13-APR-11

channel ORA_DISK_1: finished piece 1 at 13-APR-11

piece handle=/u02/backup/orcl_04m9mqh3_1_1 tag=TAG20110413T200555 comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:00:07

Finished backup at 14-APR-11

 

Starting Control File and SPFILE Autobackup at 14-APR-11

piece handle=/u01/app/oracle/flash_recovery_area/ORCL/autobackup/2011_04_13/o1_mf_s_748382762_6tdl3tk7_.bkp comment=NONE

Finished Control File and SPFILE Autobackup at 14-APR-11

 

 

由于是热备,所以备份的过程中联机日志文件有可能发生变化,所以我们还需要备份一下当前的联机重做日志文件。

 

RMAN> sql 'alter system archive log current';  --归档当前联机重做日志文件(REDO LOG

 

sql statement: alter system archive log current

 

RMAN> list backup;

 

 

List of Backup Sets

===================

 

 

BS Key  Type LV Size       Device Type Elapsed Time Completion Time

------- ---- -- ---------- ----------- ------------ ---------------

3       Full    1.06G      DISK        00:00:05     13-APR-11      

        BP Key: 3   Status: AVAILABLE  Compressed: NO  Tag: TAG20110413T200555

        Piece Name: /u02/backup/orcl_04m9mqh3_1_1

  List of Datafiles in backup set 3

  File LV Type Ckp SCN    Ckp Time  Name

  ---- -- ---- ---------- --------- ----

  1       Full 1224029    13-APR-11 /u01/app/oracle/oradata/orcl/system01.dbf

  2       Full 1224029    13-APR-11 /u01/app/oracle/oradata/orcl/sysaux01.dbf

  3       Full 1224029    13-APR-11 /u01/app/oracle/oradata/orcl/undotbs01.dbf

  4       Full 1224029    13-APR-11 /u01/app/oracle/oradata/orcl/users01.dbf

  5       Full 1224029    13-APR-11 /u01/app/oracle/oradata/orcl/example01.dbf

  6       Full 1183312    13-APR-11 /u01/app/oracle/oradata/orcl/app01.dbf

 

BS Key  Type LV Size       Device Type Elapsed Time Completion Time

------- ---- -- ---------- ----------- ------------ ---------------

4       Full    7.58M      DISK        00:00:00     13-APR-11      

        BP Key: 4   Status: AVAILABLE  Compressed: NO  Tag: TAG20110413T200602

        Piece Name: /u01/app/oracle/flash_recovery_area/ORCL/autobackup/2011_04_13/o1_mf_s_748382762_6tdl3tk7_.bkp

  SPFILE Included: Modification time: 13-APR-11

  SPFILE db_unique_name: ORCL

  Control File Included: Ckp SCN: 1224037      Ckp time: 13-APR-11

 

RMAN> show all;

 

RMAN configuration parameters for database with db_unique_name ORCL are:

CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;

CONFIGURE BACKUP OPTIMIZATION OFF; # default

CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default

CONFIGURE CONTROLFILE AUTOBACKUP ON;

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 COMPRESSION ALGORITHM 'BASIC' AS OF RELEASE 'DEFAULT' OPTIMIZE FOR LOAD TRUE ; # default

CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default

CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/u01/app/oracle/product/11.2.0/db_1/dbs/snapcf_orcl.f'; # default

 

RMAN> backup incremental level 0 database plus archivelog delete all input format '/u02/backup/all_lev0_%U';  --准一个0级增量备份

 

 

Starting backup at 14-APR-11

current log archived

using channel ORA_DISK_1

channel ORA_DISK_1: starting archived log backup set

channel ORA_DISK_1: specifying archived log(s) in backup set

input archived log thread=1 sequence=9 RECID=10 STAMP=748318710

input archived log thread=1 sequence=10 RECID=5 STAMP=748318710

input archived log thread=1 sequence=11 RECID=7 STAMP=748318710

channel ORA_DISK_1: starting piece 1 at 13-APR-11

channel ORA_DISK_1: finished piece 1 at 13-APR-11

piece handle=/u02/backup/all_lev0_06m9mqs7_1_1 tag=TAG20110413T201151 comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01

channel ORA_DISK_1: deleting archived log(s)

archived log file name=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2011_04_12/o1_mf_1_9_6t8pt4rh_.arc RECID=10 STAMP=748318710

archived log file name=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2011_04_12/o1_mf_1_10_6t8p9oyh_.arc RECID=5 STAMP=748318710

archived log file name=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2011_04_12/o1_mf_1_10_6t8pt4q1_.arc RECID=6 STAMP=748318710

archived log file name=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2011_04_12/o1_mf_1_11_6t8pt4qz_.arc RECID=7 STAMP=748318710

channel ORA_DISK_1: starting archived log backup set

channel ORA_DISK_1: specifying archived log(s) in backup set

input archived log thread=1 sequence=1 RECID=11 STAMP=748318710

input archived log thread=1 sequence=2 RECID=9 STAMP=748318710

input archived log thread=1 sequence=3 RECID=13 STAMP=748318710

input archived log thread=1 sequence=4 RECID=14 STAMP=748318710

input archived log thread=1 sequence=5 RECID=16 STAMP=748322138

input archived log thread=1 sequence=6 RECID=17 STAMP=748322138

input archived log thread=1 sequence=7 RECID=15 STAMP=748322138

channel ORA_DISK_1: starting piece 1 at 13-APR-11

channel ORA_DISK_1: finished piece 1 at 13-APR-11

piece handle=/u02/backup/all_lev0_07m9mqs8_1_1 tag=TAG20110413T201151 comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01

channel ORA_DISK_1: deleting archived log(s)

archived log file name=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2011_04_13/o1_mf_1_1_6tbf15og_.arc RECID=11 STAMP=748318710

archived log file name=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2011_04_12/o1_mf_1_1_6t8px7qb_.arc RECID=8 STAMP=748318710

archived log file name=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2011_04_12/o1_mf_1_2_6tb4h343_.arc RECID=9 STAMP=748318710

archived log file name=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2011_04_13/o1_mf_1_2_6tbf15sb_.arc RECID=12 STAMP=748318710

archived log file name=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2011_04_13/o1_mf_1_3_6tbf1fx2_.arc RECID=13 STAMP=748318710

archived log file name=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2011_04_13/o1_mf_1_3_6tblllsk_.arc RECID=1 STAMP=748317698

archived log file name=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2011_04_13/o1_mf_1_4_6tbhlh0o_.arc RECID=14 STAMP=748318710

archived log file name=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2011_04_13/o1_mf_1_4_6tblllt8_.arc RECID=2 STAMP=748317698

archived log file name=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2011_04_13/o1_mf_1_5_6tbpxbkd_.arc RECID=16 STAMP=748322138

archived log file name=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2011_04_13/o1_mf_1_5_6tbllty1_.arc RECID=3 STAMP=748317706

archived log file name=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2011_04_13/o1_mf_1_6_6tbpxbkw_.arc RECID=17 STAMP=748322138

archived log file name=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2011_04_13/o1_mf_1_6_6tbm558s_.arc RECID=4 STAMP=748318293

archived log file name=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2011_04_13/o1_mf_1_7_6tbpxbjp_.arc RECID=15 STAMP=748322138

channel ORA_DISK_1: starting archived log backup set

channel ORA_DISK_1: specifying archived log(s) in backup set

input archived log thread=1 sequence=1 RECID=18 STAMP=748342924

input archived log thread=1 sequence=2 RECID=19 STAMP=748374137

input archived log thread=1 sequence=3 RECID=20 STAMP=748382872

input archived log thread=1 sequence=4 RECID=21 STAMP=748383111

channel ORA_DISK_1: starting piece 1 at 13-APR-11

channel ORA_DISK_1: finished piece 1 at 13-APR-11

piece handle=/u02/backup/all_lev0_08m9mqs9_1_1 tag=TAG20110413T201151 comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01

channel ORA_DISK_1: deleting archived log(s)

archived log file name=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2011_04_13/o1_mf_1_1_6tcc6wpc_.arc RECID=18 STAMP=748342924

archived log file name=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2011_04_13/o1_mf_1_2_6td9p9s8_.arc RECID=19 STAMP=748374137

archived log file name=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2011_04_13/o1_mf_1_3_6tdl78of_.arc RECID=20 STAMP=748382872

archived log file name=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2011_04_13/o1_mf_1_4_6tdlgq62_.arc RECID=21 STAMP=748383111

Finished backup at 14-APR-11

 

Starting backup at 14-APR-11

using channel ORA_DISK_1

channel ORA_DISK_1: starting incremental level 0 datafile backup set

channel ORA_DISK_1: specifying datafile(s) in backup set

input datafile file number=00001 name=/u01/app/oracle/oradata/orcl/system01.dbf

input datafile file number=00002 name=/u01/app/oracle/oradata/orcl/sysaux01.dbf

input datafile file number=00003 name=/u01/app/oracle/oradata/orcl/undotbs01.dbf

input datafile file number=00005 name=/u01/app/oracle/oradata/orcl/example01.dbf

input datafile file number=00006 name=/u01/app/oracle/oradata/orcl/app01.dbf

input datafile file number=00004 name=/u01/app/oracle/oradata/orcl/users01.dbf

channel ORA_DISK_1: starting piece 1 at 13-APR-11

channel ORA_DISK_1: finished piece 1 at 13-APR-11

piece handle=/u01/app/oracle/flash_recovery_area/ORCL/backupset/2011_04_13/o1_mf_nnnd0_TAG20110413T201154_6tdlgv6g_.bkp tag=TAG20110413T201154 comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:00:07

Finished backup at 14-APR-11

 

Starting backup at 14-APR-11

current log archived

using channel ORA_DISK_1

channel ORA_DISK_1: starting archived log backup set

channel ORA_DISK_1: specifying archived log(s) in backup set

input archived log thread=1 sequence=5 RECID=22 STAMP=748383122

channel ORA_DISK_1: starting piece 1 at 13-APR-11

channel ORA_DISK_1: finished piece 1 at 13-APR-11

piece handle=/u02/backup/all_lev0_0am9mqsi_1_1 tag=TAG20110413T201202 comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01

channel ORA_DISK_1: deleting archived log(s)

archived log file name=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2011_04_13/o1_mf_1_5_6tdlh265_.arc RECID=22 STAMP=748383122

Finished backup at 14-APR-11

 

Starting Control File and SPFILE Autobackup at 14-APR-11

piece handle=/u01/app/oracle/flash_recovery_area/ORCL/autobackup/2011_04_13/o1_mf_s_748383123_6tdlh3hf_.bkp comment=NONE

Finished Control File and SPFILE Autobackup at 14-APR-11

 

SQL> conn lsf/lsf

Connected.

SQL> insert into T values(1,'lsf');

 

1 row created.

 

SQL> insert into T values(2,'lsf');

 

1 row created.

 

SQL> commit;

 

Commit complete.

 

SQL> conn /as sysdba;

Connected.

SQL> alter system checkpoint;

 

System altered.

 

SQL> alter system archive log current;

 

System altered.

 

RMAN> backup incremental level 1 database format '/u02/backup/all_lev1_%U' plus archivelog delete all input;  --准备一个1级增量备份

 

 

Starting backup at 14-APR-11

current log archived

using channel ORA_DISK_1

channel ORA_DISK_1: starting archived log backup set

channel ORA_DISK_1: specifying archived log(s) in backup set

input archived log thread=1 sequence=6 RECID=23 STAMP=748383628

input archived log thread=1 sequence=7 RECID=24 STAMP=748383744

channel ORA_DISK_1: starting piece 1 at 13-APR-11

channel ORA_DISK_1: finished piece 1 at 13-APR-11

piece handle=/u01/app/oracle/flash_recovery_area/ORCL/backupset/2011_04_13/o1_mf_annnn_TAG20110413T202224_6tdm2jl4_.bkp tag=TAG20110413T202224 comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01

channel ORA_DISK_1: deleting archived log(s)

archived log file name=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2011_04_13/o1_mf_1_6_6tdlywrn_.arc RECID=23 STAMP=748383628

archived log file name=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2011_04_13/o1_mf_1_7_6tdm2jd0_.arc RECID=24 STAMP=748383744

Finished backup at 14-APR-11

 

Starting backup at 14-APR-11

using channel ORA_DISK_1

channel ORA_DISK_1: starting incremental level 1 datafile backup set

channel ORA_DISK_1: specifying datafile(s) in backup set

input datafile file number=00001 name=/u01/app/oracle/oradata/orcl/system01.dbf

input datafile file number=00002 name=/u01/app/oracle/oradata/orcl/sysaux01.dbf

input datafile file number=00003 name=/u01/app/oracle/oradata/orcl/undotbs01.dbf

input datafile file number=00005 name=/u01/app/oracle/oradata/orcl/example01.dbf

input datafile file number=00006 name=/u01/app/oracle/oradata/orcl/app01.dbf

input datafile file number=00004 name=/u01/app/oracle/oradata/orcl/users01.dbf

channel ORA_DISK_1: starting piece 1 at 13-APR-11

channel ORA_DISK_1: finished piece 1 at 13-APR-11

piece handle=/u02/backup/all_lev1_0dm9mrg1_1_1 tag=TAG20110413T202225 comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01

Finished backup at 14-APR-11

 

Starting backup at 14-APR-11

current log archived

using channel ORA_DISK_1

channel ORA_DISK_1: starting archived log backup set

channel ORA_DISK_1: specifying archived log(s) in backup set

input archived log thread=1 sequence=8 RECID=25 STAMP=748383746

channel ORA_DISK_1: starting piece 1 at 13-APR-11

channel ORA_DISK_1: finished piece 1 at 13-APR-11

piece handle=/u01/app/oracle/flash_recovery_area/ORCL/backupset/2011_04_13/o1_mf_annnn_TAG20110413T202226_6tdm2m0k_.bkp tag=TAG20110413T202226 comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01

channel ORA_DISK_1: deleting archived log(s)

archived log file name=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2011_04_13/o1_mf_1_8_6tdm2lvg_.arc RECID=25 STAMP=748383746

Finished backup at 14-APR-11

 

Starting Control File and SPFILE Autobackup at 14-APR-11

piece handle=/u01/app/oracle/flash_recovery_area/ORCL/autobackup/2011_04_13/o1_mf_s_748383748_6tdm2n56_.bkp comment=NONE

Finished Control File and SPFILE Autobackup at 14-APR-11

 

 

RMAN> quit

 

 

Recovery Manager complete.

 

 

基础准备工作完成,下面演示数据文件丢失后的恢复。

 

 

$ sqlplus /nolog

 

SQL*Plus: Release 11.2.0.1.0 Production on Thu Apr 14 09:24:06 2011

 

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

 

SQL> conn /as sysdba

Connected.

SQL> shutdown immediate

Database closed.

Database dismounted.

ORACLE instance shut down.

 

$ cd /u01/app/oracle/oradata/orcl   --模拟故障(删除所有的数据文件)

rm -rf *.dbf

 

 

恢复操作过程:

$ sqlplus /nolog

 

SQL*Plus: Release 11.2.0.1.0 Production on Thu Apr 14 09:26:34 2011

 

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

 

SQL> conn /as sysdba

Connected to an idle instance.

SQL> startup mount;  --启动数据库到mount状态

ORACLE instance started.

 

Total System Global Area 6847938560 bytes

Fixed Size                  2219808 bytes

Variable Size            3539992800 bytes

Database Buffers         3288334336 bytes

Redo Buffers               17391616 bytes

Database mounted.

SQL> exit

Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options

 

rman target sys/oracle@orcl nocatalog

 

Recovery Manager: Release 11.2.0.1.0 - Production on Thu Apr 14 09:28:18 2011

 

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

 

connected to target database: ORCL (DBID=1276064171, not open)

using target database control file instead of recovery catalog

 

RMAN> restore database;  --还原 (rman会自动选择备份集)

 

Starting restore at 14-APR-11

allocated channel: ORA_DISK_1

channel ORA_DISK_1: SID=63 device type=DISK

 

channel ORA_DISK_1: starting datafile backup set restore

channel ORA_DISK_1: specifying datafile(s) to restore from backup set

channel ORA_DISK_1: restoring datafile 00001 to /u01/app/oracle/oradata/orcl/system01.dbf

channel ORA_DISK_1: restoring datafile 00002 to /u01/app/oracle/oradata/orcl/sysaux01.dbf

channel ORA_DISK_1: restoring datafile 00003 to /u01/app/oracle/oradata/orcl/undotbs01.dbf

channel ORA_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/orcl/users01.dbf

channel ORA_DISK_1: restoring datafile 00005 to /u01/app/oracle/oradata/orcl/example01.dbf

channel ORA_DISK_1: restoring datafile 00006 to /u01/app/oracle/oradata/orcl/app01.dbf

channel ORA_DISK_1: reading from backup piece /u01/app/oracle/flash_recovery_area/ORCL/backupset/2011_04_13/o1_mf_nnnd0_TAG20110413T201154_6tdlgv6g_.bkp

channel ORA_DISK_1: piece handle=/u01/app/oracle/flash_recovery_area/ORCL/backupset/2011_04_13/o1_mf_nnnd0_TAG20110413T201154_6tdlgv6g_.bkp tag=TAG20110413T201154

channel ORA_DISK_1: restored backup piece 1

channel ORA_DISK_1: restore complete, elapsed time: 00:00:07

Finished restore at 14-APR-11

 

RMAN> recover database;  --恢复(应用联机日志,归档日志)

 

Starting recover at 14-APR-11

using channel ORA_DISK_1

channel ORA_DISK_1: starting incremental datafile backup set restore

channel ORA_DISK_1: specifying datafile(s) to restore from backup set

destination for restore of datafile 00001: /u01/app/oracle/oradata/orcl/system01.dbf

destination for restore of datafile 00002: /u01/app/oracle/oradata/orcl/sysaux01.dbf

destination for restore of datafile 00003: /u01/app/oracle/oradata/orcl/undotbs01.dbf

destination for restore of datafile 00004: /u01/app/oracle/oradata/orcl/users01.dbf

destination for restore of datafile 00005: /u01/app/oracle/oradata/orcl/example01.dbf

destination for restore of datafile 00006: /u01/app/oracle/oradata/orcl/app01.dbf

channel ORA_DISK_1: reading from backup piece /u02/backup/all_lev1_0dm9mrg1_1_1

channel ORA_DISK_1: piece handle=/u02/backup/all_lev1_0dm9mrg1_1_1 tag=TAG20110413T202225

channel ORA_DISK_1: restored backup piece 1

channel ORA_DISK_1: restore complete, elapsed time: 00:00:01

 

starting media recovery

media recovery complete, elapsed time: 00:00:00

 

Finished recover at 14-APR-11

 

RMAN> alter database open;  --打开数据库

 

database opened

 

 

验证数据:

$ sqlplus /nolog

 

SQL*Plus: Release 11.2.0.1.0 Production on Wed Apr 13 20:32:40 2011

 

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

 

SQL> conn /as sysdba

Connected.

SQL> select * from lsf.t;

 

        ID NAME

---------- --------------------

         1 lsf

         2 lsf

 

恢复成功。

 

 

 

下面演示恢复数据文件到不同的目录:

Restore to a New Location

Use the SET NEWNAME command to restore the datafile to the new location.

SET NEWNAME FOR DATAFILE 1 TO '/<newdir>/system01.dbf';

Use the SWITCH command to record the change in the control file.

SWITCH DATAFILE ALL;

 

 

开始实验:

SQL> shutdown immediate

Database closed.

Database dismounted.

ORACLE instance shut down.

 

$ cd /u01/app/oracle/oradata/orcl

rm -rf app01.dbf  --模拟故障(删除数据文件)

 

SQL> startup mount  --启动到mount状态

ORACLE instance started.

 

Total System Global Area 6847938560 bytes

Fixed Size                  2219808 bytes

Variable Size            3539992800 bytes

Database Buffers         3288334336 bytes

Redo Buffers               17391616 bytes

Database mounted.

 

SQL> col name format a50

SQL> select file#,name from v$datafile;

 

     FILE# NAME

---------- --------------------------------------------------

         1 /u01/app/oracle/oradata/orcl/system01.dbf

         2 /u01/app/oracle/oradata/orcl/sysaux01.dbf

         3 /u01/app/oracle/oradata/orcl/undotbs01.dbf

         4 /u01/app/oracle/oradata/orcl/users01.dbf

         5 /u01/app/oracle/oradata/orcl/example01.dbf

         6 /u01/app/oracle/oradata/orcl/app01.dbf

 

6 rows selected.

 

rman target sys/oracle@orcl nocatalog

 

Recovery Manager: Release 11.2.0.1.0 - Production on Thu Apr 14 10:23:21 2011

 

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

 

connected to target database: ORCL (DBID=1276064171, not open)

using target database control file instead of recovery catalog

 

RMAN> RUN {

2> set newname for datafile 6 to '/u01/app/oracle/oradata/app01.dbf';

3> restore database;

4> switch datafile all;

5> recover database;

6> alter database open;

7> }

 

executing command: SET NEWNAME

 

Starting restore at 14-APR-11

allocated channel: ORA_DISK_1

channel ORA_DISK_1: SID=63 device type=DISK

 

channel ORA_DISK_1: starting datafile backup set restore

channel ORA_DISK_1: specifying datafile(s) to restore from backup set

channel ORA_DISK_1: restoring datafile 00001 to /u01/app/oracle/oradata/orcl/system01.dbf

channel ORA_DISK_1: restoring datafile 00002 to /u01/app/oracle/oradata/orcl/sysaux01.dbf

channel ORA_DISK_1: restoring datafile 00003 to /u01/app/oracle/oradata/orcl/undotbs01.dbf

channel ORA_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/orcl/users01.dbf

channel ORA_DISK_1: restoring datafile 00005 to /u01/app/oracle/oradata/orcl/example01.dbf

channel ORA_DISK_1: restoring datafile 00006 to /u01/app/oracle/oradata/app01.dbf

channel ORA_DISK_1: reading from backup piece /u01/app/oracle/flash_recovery_area/ORCL/backupset/2011_04_13/o1_mf_nnnd0_TAG20110413T201154_6tdlgv6g_.bkp

channel ORA_DISK_1: piece handle=/u01/app/oracle/flash_recovery_area/ORCL/backupset/2011_04_13/o1_mf_nnnd0_TAG20110413T201154_6tdlgv6g_.bkp tag=TAG20110413T201154

channel ORA_DISK_1: restored backup piece 1

channel ORA_DISK_1: restore complete, elapsed time: 00:00:07

Finished restore at 14-APR-11

 

datafile 6 switched to datafile copy

input datafile copy RECID=8 STAMP=748387486 file name=/u01/app/oracle/oradata/app01.dbf

 

Starting recover at 14-APR-11

using channel ORA_DISK_1

channel ORA_DISK_1: starting incremental datafile backup set restore

channel ORA_DISK_1: specifying datafile(s) to restore from backup set

destination for restore of datafile 00001: /u01/app/oracle/oradata/orcl/system01.dbf

destination for restore of datafile 00002: /u01/app/oracle/oradata/orcl/sysaux01.dbf

destination for restore of datafile 00003: /u01/app/oracle/oradata/orcl/undotbs01.dbf

destination for restore of datafile 00004: /u01/app/oracle/oradata/orcl/users01.dbf

destination for restore of datafile 00005: /u01/app/oracle/oradata/orcl/example01.dbf

destination for restore of datafile 00006: /u01/app/oracle/oradata/app01.dbf

channel ORA_DISK_1: reading from backup piece /u02/backup/all_lev1_0dm9mrg1_1_1

channel ORA_DISK_1: piece handle=/u02/backup/all_lev1_0dm9mrg1_1_1 tag=TAG20110413T202225

channel ORA_DISK_1: restored backup piece 1

channel ORA_DISK_1: restore complete, elapsed time: 00:00:01

 

starting media recovery

media recovery complete, elapsed time: 00:00:01

 

Finished recover at 14-APR-11

 

database opened

 

恢复完成

 

 

恢复表空间实例:

Recovery a Tablespace

Use the following RMAN commands to restore and recover a database:

RESTORE TABLESPACE

RECOVER TABLESPACE

RUN {

sql 'alter tablespace users offline immediate';

restore tablespace users;

recover tablespace users;

sql 'alter tablespace users online';

}

 

 

数据库处于打开状态,其中一个数据文件丢失

 

rm -rf app01.dbf  --模拟故障

 

SQL> select * from lsf.t;

select * from lsf.t

                  *

ERROR at line 1:

ORA-01116: error in opening database file 6

ORA-01110: data file 6: '/u01/app/oracle/oradata/orcl/app01.dbf'

ORA-27041: unable to open file

IBM AIX RISC System/6000 Error: 2: No such file or directory

Additional information: 3

Additional information: 4

Additional information: 4194304

 

SQL> col error for a18

SQL> select * from v$recover_file;

 

no rows selected

 

rman target sys/oracle@orcl nocatalog

 

Recovery Manager: Release 11.2.0.1.0 - Production on Thu Apr 14 12:18:31 2011

 

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

 

connected to target database: ORCL (DBID=1276219506)

using target database control file instead of recovery catalog

 

RMAN> RUN {

2> sql 'alter tablespace app offline immediate';

3> restore tablespace app;

4> recover tablespace app;

5> sql 'alter tablespace app online';

6> }

 

sql statement: alter tablespace app offline immediate

 

Starting restore at 14-APR-11

allocated channel: ORA_DISK_1

channel ORA_DISK_1: SID=11 device type=DISK

 

channel ORA_DISK_1: starting datafile backup set restore

channel ORA_DISK_1: specifying datafile(s) to restore from backup set

channel ORA_DISK_1: restoring datafile 00006 to /u01/app/oracle/oradata/orcl/app01.dbf

channel ORA_DISK_1: reading from backup piece /u01/app/oracle/flash_recovery_area/ORCL/backupset/2011_04_14/o1_mf_nnnd0_TAG20110414T120156_6tdwfnfb_.bkp

channel ORA_DISK_1: piece handle=/u01/app/oracle/flash_recovery_area/ORCL/backupset/2011_04_14/o1_mf_nnnd0_TAG20110414T120156_6tdwfnfb_.bkp tag=TAG20110414T120156

channel ORA_DISK_1: restored backup piece 1

channel ORA_DISK_1: restore complete, elapsed time: 00:00:01

Finished restore at 14-APR-11

 

Starting recover at 14-APR-11

using channel ORA_DISK_1

channel ORA_DISK_1: starting incremental datafile backup set restore

channel ORA_DISK_1: specifying datafile(s) to restore from backup set

destination for restore of datafile 00006: /u01/app/oracle/oradata/orcl/app01.dbf

channel ORA_DISK_1: reading from backup piece /u02/backup/all_lev1_09m9oij6_1_1

channel ORA_DISK_1: piece handle=/u02/backup/all_lev1_09m9oij6_1_1 tag=TAG20110414T120246

channel ORA_DISK_1: restored backup piece 1

channel ORA_DISK_1: restore complete, elapsed time: 00:00:01

 

starting media recovery

media recovery complete, elapsed time: 00:00:00

 

Finished recover at 14-APR-11

 

sql statement: alter tablespace app online

 

 

验证恢复后的数据

SQL> select * from lsf.t;

 

        ID NAME

---------- --------------------

         1 lsf

         2 lsf

 

恢复成功

 

 

恢复表空间到不同的目录:

Relocate a Tablespace

Use the SET NEWNAME command to restore the files.

Use the SWITCH command to record the new names in the control file.

Use the RECOVER TABLESPACE command to recover the datafiles of the tablespace.

 

 

Summary:

Recover a database in ARCHIVELOG mode

Restore datafiles to different locations if the original location is unavailable

 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Oracle RMAN恢复是一种强大的工具,用于恢复数据库到损坏的状态。它提供了一套丰富的功能,可以从备份中恢复数据文件、控制文件和日志文件。 首先,我们需要创建一个有效的RMAN备份。可以使用RMAN备份整个数据库或只备份指定的数据文件、控制文件和日志文件。 在恢复过程中,我们可以使用几种不同的恢复策略。完全恢复将数据库恢复到最新的可用备份,然后应用所有丢失的日志文件。部分恢复可以用于恢复单个表空间或数据文件。 在进行恢复之前,我们需要确保数据库处于彻底关闭状态。然后,我们可以使用RMAN进行恢复。可以通过启动RMAN工具、连接到目标数据库并执行所需的恢复操作来完成。 恢复过程中的一些重要术语包括“恢复目标”、“恢复窗口”和“重做应用”。恢复目标是指正在进行恢复操作的数据库,恢复窗口是可以恢复到其中的时间范围,而重做应用是指将丢失的或损坏的数据应用到数据库中。 RMAN可以自动执行备份集的恢复操作,或者我们可以手动指定要恢复的备份集。完成恢复后,我们可以打开数据库并验证数据的完整性。 总而言之,Oracle RMAN是一种强大的工具,可以为数据库提供高效的恢复解决方案。它提供了多种恢复策略,可以根据需要选择合适的方法。使用RMAN进行恢复操作需要一些准备工作和理解,但它可以帮助我们迅速恢复数据库并保障数据的完整性。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值