ITPub博客

首页 > Linux操作系统 > Linux操作系统 > rman 全库恢复asm数据库

rman 全库恢复asm数据库

原创 Linux操作系统 作者:haozg_oracle 时间:2012-06-29 10:24:07 0 删除 编辑
1、做全库备份
 
注意:rman 可以把asm上的数据文件备份到文件系统,也可恢复
 
RMAN> run{
 allocate channel c1 type disk maxpiecesize=500m;
 backup current controlfile format '+dgasm/backup/ctl_%d_%s';
 backup full database format '+dgasm/backup/db_%d_%s_%p_%t';
 sql 'alter system archive log current';
 release channel c1;
 }2> 3> 4> 5> 6> 7>
allocated channel: c1
channel c1: SID=31 device type=DISK
Starting backup at 24-JUN-12
channel c1: starting full datafile backup set
channel c1: specifying datafile(s) in backup set
including current control file in backup set
channel c1: starting piece 1 at 24-JUN-12
channel c1: finished piece 1 at 24-JUN-12
piece handle=+DGASM/backup/ctl_ora11_19 tag=TAG20120624T172227 comment=NONE
channel c1: backup set complete, elapsed time: 00:00:03
Finished backup at 24-JUN-12
Starting backup at 24-JUN-12
channel c1: starting full datafile backup set
channel c1: specifying datafile(s) in backup set
input datafile file number=00001 name=+DGASM/ora11/datafile/system.257.785186755
input datafile file number=00002 name=+DGASM/ora11/datafile/sysaux.258.785186845
input datafile file number=00003 name=+DGASM/ora11/datafile/undotbs1.259.785186901
input datafile file number=00004 name=+DGASM/ora11/datafile/users.261.785186921
channel c1: starting piece 1 at 24-JUN-12
channel c1: finished piece 1 at 24-JUN-12
piece handle=+DGASM/backup/db_ora11_20_1_786820952 tag=TAG20120624T172232 comment=NONE
channel c1: starting piece 2 at 24-JUN-12
channel c1: finished piece 2 at 24-JUN-12
piece handle=+DGASM/backup/db_ora11_20_2_786820952 tag=TAG20120624T172232 comment=NONE
channel c1: backup set complete, elapsed time: 00:01:22
channel c1: starting full datafile backup set
channel c1: specifying datafile(s) in backup set
including current control file in backup set
including current SPFILE in backup set
channel c1: starting piece 1 at 24-JUN-12
channel c1: finished piece 1 at 24-JUN-12
piece handle=+DGASM/backup/db_ora11_21_1_786821034 tag=TAG20120624T172232 comment=NONE
channel c1: backup set complete, elapsed time: 00:00:01
Finished backup at 24-JUN-12
sql statement: alter system archive log current
released channel: c1
RMAN>
2、shutdown immediate  关闭数据库,然后删除user数据文件,模拟数据文件损坏
ASMCMD> ls
SYSAUX.258.785186845
SYSTEM.257.785186755
UNDOTBS1.259.785186901
USERS.261.785186921
ASMCMD>
ASMCMD>
ASMCMD> rm -f USERS.261.785186921 
ASMCMD> ls
SYSAUX.258.785186845
SYSTEM.257.785186755
UNDOTBS1.259.785186901
ASMCMD>
3、启动数据到mount,然后open 出现下面的问题
SQL> alter database open;
alter database open
*
ERROR at line 1:
ORA-01157: cannot identify/lock data file 4 - see DBWR trace file
ORA-01110: data file 4: '+DGASM/ora11/datafile/users.261.785186921'
4、说明数据文件出现问题,查看具体的问题
SQL> select * from v$recover_file
  2  ;
     FILE# ONLINE  ONLINE_ ERROR
---------- ------- ------- -----------------------------------------------------------------
   CHANGE# TIME
---------- ------------
         4 ONLINE  ONLINE  FILE NOT FOUND
         0
FILE NOT FOUND 说明该文件丢失或者损坏,然后执行全库恢复
5、查看备份信息

RMAN> list backup    
2> ;
using target database control file instead of recovery catalog
List of Backup Sets
===================

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
1       Full    9.33M      DISK        00:00:04     05-JUN-12     
        BP Key: 1   Status: AVAILABLE  Compressed: NO  Tag: TAG20120605T141421
        Piece Name: /oracle/backup/ctl_ORA11_1
  Control File Included: Ckp SCN: 796843       Ckp time: 05-JUN-12
BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
2       Full    1005.39M   DISK        00:02:07     05-JUN-12     
  List of Datafiles in backup set 2
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  1       Full 796853     05-JUN-12 +DGASM/ora11/datafile/system.257.785186755
  2       Full 796853     05-JUN-12 +DGASM/ora11/datafile/sysaux.258.785186845
  3       Full 796853     05-JUN-12 +DGASM/ora11/datafile/undotbs1.259.785186901
  4       Full 796853     05-JUN-12 +DGASM/ora11/datafile/users.261.785186921
  Backup Set Copy #1 of backup set 2
  Device Type Elapsed Time Completion Time Compressed Tag
  ----------- ------------ --------------- ---------- ---
  DISK        00:02:07     05-JUN-12       NO         TAG20120605T141429
    List of Backup Pieces for backup set 2 Copy #1
    BP Key  Pc# Status      Piece Name
    ------- --- ----------- ----------
    2       1   AVAILABLE   /oracle/backup/db_ORA11_2_1_785168069
    3       2   AVAILABLE   /oracle/backup/db_ORA11_2_2_785168069
    4       3   AVAILABLE   /oracle/backup/db_ORA11_2_3_785168069
BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
3       Full    9.33M      DISK        00:00:04     05-JUN-12     
        BP Key: 5   Status: AVAILABLE  Compressed: NO  Tag: TAG20120605T141429
        Piece Name: /oracle/backup/db_ORA11_3_1_785168198
  Control File Included: Ckp SCN: 796891       Ckp time: 05-JUN-12
BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
4       Full    80.00K     DISK        00:00:01     05-JUN-12     
        BP Key: 6   Status: AVAILABLE  Compressed: NO  Tag: TAG20120605T192553
        Piece Name: +DGASM/ora11/backupset/2012_06_05/nnsnf0_tag20120605t192553_0.262.785186923
  SPFILE Included: Modification time: 05-JUN-12
  SPFILE db_unique_name: ORA11
BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
5       Full    9.33M      DISK        00:00:02     18-JUN-12     
        BP Key: 7   Status: AVAILABLE  Compressed: NO  Tag: TAG20120618T170921
        Piece Name: /oracle/backupasm/ctl_ORA11_10
  Control File Included: Ckp SCN: 839167       Ckp time: 18-JUN-12
BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
6       Full    943.18M    DISK        00:01:35     18-JUN-12     
  List of Datafiles in backup set 6
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  1       Full 839176     18-JUN-12 +DGASM/ora11/datafile/system.257.785186755
  2       Full 839176     18-JUN-12 +DGASM/ora11/datafile/sysaux.258.785186845
  3       Full 839176     18-JUN-12 +DGASM/ora11/datafile/undotbs1.259.785186901
  4       Full 839176     18-JUN-12 +DGASM/ora11/datafile/users.261.785186921
  Backup Set Copy #1 of backup set 6
  Device Type Elapsed Time Completion Time Compressed Tag
  ----------- ------------ --------------- ---------- ---
  DISK        00:01:35     18-JUN-12       NO         TAG20120618T170924
    List of Backup Pieces for backup set 6 Copy #1
    BP Key  Pc# Status      Piece Name
    ------- --- ----------- ----------
    8       1   AVAILABLE   /oracle/backupasm/db_ORA11_11_1_786301764
    9       2   AVAILABLE   /oracle/backupasm/db_ORA11_11_2_786301764
BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
7       Full    9.36M      DISK        00:00:04     18-JUN-12     
        BP Key: 10   Status: AVAILABLE  Compressed: NO  Tag: TAG20120618T170924
        Piece Name: /oracle/backupasm/db_ORA11_12_1_786301867
  SPFILE Included: Modification time: 18-JUN-12
  SPFILE db_unique_name: ORA11
  Control File Included: Ckp SCN: 839215       Ckp time: 18-JUN-12
BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
8       Full    9.33M      DISK        00:00:03     24-JUN-12     
        BP Key: 11   Status: AVAILABLE  Compressed: NO  Tag: TAG20120624T163428
        Piece Name: /oracle/backupasm/ctl_ORA11_13
  Control File Included: Ckp SCN: 875884       Ckp time: 24-JUN-12
BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
9       Full    950.97M    DISK        00:01:36     24-JUN-12     
  List of Datafiles in backup set 9
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  1       Full 875893     24-JUN-12 +DGASM/ora11/datafile/system.257.785186755
  2       Full 875893     24-JUN-12 +DGASM/ora11/datafile/sysaux.258.785186845
  3       Full 875893     24-JUN-12 +DGASM/ora11/datafile/undotbs1.259.785186901
  4       Full 875893     24-JUN-12 +DGASM/ora11/datafile/users.261.785186921
  Backup Set Copy #1 of backup set 9
  Device Type Elapsed Time Completion Time Compressed Tag
  ----------- ------------ --------------- ---------- ---
  DISK        00:01:36     24-JUN-12       NO         TAG20120624T163434
    List of Backup Pieces for backup set 9 Copy #1
    BP Key  Pc# Status      Piece Name
    ------- --- ----------- ----------
    12      1   AVAILABLE   /oracle/backupasm/db_ORA11_14_1_786818074
    13      2   AVAILABLE   /oracle/backupasm/db_ORA11_14_2_786818074
BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
10      Full    9.36M      DISK        00:00:02     24-JUN-12     
        BP Key: 14   Status: AVAILABLE  Compressed: NO  Tag: TAG20120624T163434
        Piece Name: /oracle/backupasm/db_ORA11_15_1_786818176
  SPFILE Included: Modification time: 24-JUN-12
  SPFILE db_unique_name: ORA11
  Control File Included: Ckp SCN: 875932       Ckp time: 24-JUN-12
BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
11      Full    9.33M      DISK        00:00:03     24-JUN-12     
        BP Key: 15   Status: AVAILABLE  Compressed: NO  Tag: TAG20120624T164029
        Piece Name: +DGASM/backup/ctl_ora11_16
  Control File Included: Ckp SCN: 876056       Ckp time: 24-JUN-12
BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
12      Full    950.97M    DISK        00:01:38     24-JUN-12     
  List of Datafiles in backup set 12
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  1       Full 876064     24-JUN-12 +DGASM/ora11/datafile/system.257.785186755
  2       Full 876064     24-JUN-12 +DGASM/ora11/datafile/sysaux.258.785186845
  3       Full 876064     24-JUN-12 +DGASM/ora11/datafile/undotbs1.259.785186901
  4       Full 876064     24-JUN-12 +DGASM/ora11/datafile/users.261.785186921
  Backup Set Copy #1 of backup set 12
  Device Type Elapsed Time Completion Time Compressed Tag
  ----------- ------------ --------------- ---------- ---
  DISK        00:01:38     24-JUN-12       NO         TAG20120624T164034
    List of Backup Pieces for backup set 12 Copy #1
    BP Key  Pc# Status      Piece Name
    ------- --- ----------- ----------
    16      1   AVAILABLE   +DGASM/backup/db_ora11_17_1_786818434
    17      2   AVAILABLE   +DGASM/backup/db_ora11_17_2_786818434
BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
13      Full    9.36M      DISK        00:00:02     24-JUN-12     
        BP Key: 18   Status: AVAILABLE  Compressed: NO  Tag: TAG20120624T164034
        Piece Name: +DGASM/backup/db_ora11_18_1_786818542
  SPFILE Included: Modification time: 24-JUN-12
  SPFILE db_unique_name: ORA11
  Control File Included: Ckp SCN: 876107       Ckp time: 24-JUN-12
BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
14      Full    9.33M      DISK        00:00:03     24-JUN-12     
        BP Key: 19   Status: AVAILABLE  Compressed: NO  Tag: TAG20120624T172227
        Piece Name: +DGASM/backup/ctl_ora11_19
  Control File Included: Ckp SCN: 877939       Ckp time: 24-JUN-12
BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
15      Full    951.52M    DISK        00:01:18     24-JUN-12     
  List of Datafiles in backup set 15
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  1       Full 877947     24-JUN-12 +DGASM/ora11/datafile/system.257.785186755
  2       Full 877947     24-JUN-12 +DGASM/ora11/datafile/sysaux.258.785186845
  3       Full 877947     24-JUN-12 +DGASM/ora11/datafile/undotbs1.259.785186901
  4       Full 877947     24-JUN-12 +DGASM/ora11/datafile/users.261.785186921
  Backup Set Copy #1 of backup set 15
  Device Type Elapsed Time Completion Time Compressed Tag
  ----------- ------------ --------------- ---------- ---
  DISK        00:01:18     24-JUN-12       NO         TAG20120624T172232
    List of Backup Pieces for backup set 15 Copy #1
    BP Key  Pc# Status      Piece Name
    ------- --- ----------- ----------
    20      1   AVAILABLE   +DGASM/backup/db_ora11_20_1_786820952
    21      2   AVAILABLE   +DGASM/backup/db_ora11_20_2_786820952
BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
16      Full    9.36M      DISK        00:00:02     24-JUN-12     
        BP Key: 22   Status: AVAILABLE  Compressed: NO  Tag: TAG20120624T172232
        Piece Name: +DGASM/backup/db_ora11_21_1_786821034
  SPFILE Included: Modification time: 24-JUN-12
  SPFILE db_unique_name: ORA11
  Control File Included: Ckp SCN: 877981       Ckp time: 24-JUN-12
RMAN>
6、restore database,以最近的备份来恢复数据库,
(1)转储数据库(RESTORE):
按照RMAN存储库的条目从备份文件恢复需要的文件,是指利用备份的数据库文件来
替换已经损坏的数据库文件或者将其恢复到一个新的位置。RMAN在进行修复操作时,
会利用恢复目录(没有建立恢复目录的话就使用目标数据库的控制文件)来获取备份信息,
并从中选择最合适的备份进行修复操作。
选择备份时有两个原则(1、选择距离恢复目录时刻最近;2、优先选择镜像复制,其次才是备份集)
(2)数据库恢复(RECOVER):使用数据文件和REDO文件进行完全的或者时间点的数据库媒体恢复,
是指利用重做日志或增量备份来重建丢失的数据。
RMAN> restore database;
Starting restore at 26-JUN-12
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=27 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 +DGASM/ora11/datafile/system.257.785186755
channel ORA_DISK_1: restoring datafile 00002 to +DGASM/ora11/datafile/sysaux.258.785186845
channel ORA_DISK_1: restoring datafile 00003 to +DGASM/ora11/datafile/undotbs1.259.785186901
channel ORA_DISK_1: restoring datafile 00004 to +DGASM/ora11/datafile/users.261.785186921
channel ORA_DISK_1: reading from backup piece +DGASM/backup/db_ora11_20_1_786820952
channel ORA_DISK_1: piece handle=+DGASM/backup/db_ora11_20_1_786820952 tag=TAG20120624T172232
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: reading from backup piece +DGASM/backup/db_ora11_20_2_786820952
channel ORA_DISK_1: piece handle=+DGASM/backup/db_ora11_20_2_786820952 tag=TAG20120624T172232
channel ORA_DISK_1: restored backup piece 2
channel ORA_DISK_1: restore complete, elapsed time: 00:01:51
Finished restore at 26-JUN-12
SQL> select file#,error from v$recover_file;
     FILE# ERROR
---------- -----------------------------------------------------------------
         1
         2
         3
         4
        
查看已经没有错
7、恢复数据库,应用重做日志,然后打开数据库。
RMAN> recover database;
Starting recover at 26-JUN-12
using channel ORA_DISK_1
starting media recovery
media recovery complete, elapsed time: 00:00:20
Finished recover at 26-JUN-12
RMAN> alter database open;
database opened
RMAN>
总结:用rman做全库恢复,首先保证控制文件是完好的,在恢复的过程中不会恢复控制文件,是以控制文件为标准来恢复数据文件。应用redo日志直到控制文件中记录的数据文件的scn和数据文件头中记录的scn一致。这种恢复如果归档和当前redo都完好,就不会丢数据。
 

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/23062014/viewspace-734112/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2009-12-22

  • 博文量
    37
  • 访问量
    156691