Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1021790
  • 博文数量: 584
  • 博客积分: 2293
  • 博客等级: 大尉
  • 技术积分: 3045
  • 用 户 组: 普通用户
  • 注册时间: 2006-03-28 11:15
文章分类

全部博文(584)

文章存档

2012年(532)

2011年(47)

2009年(5)

我的朋友

分类:

2012-03-08 20:15:27

源端和目的端的操作系统和数据库:
Os:Red Hat Linux As 5
Db Version:10GR2
 
前期准备,需要备份源数据库,备份脚本可以参考如下,将备份集拷贝到目的机器上.在目的机器恢复的过程中,db_name,oracle_sid,dbid设置必须跟源数据库保持一致,若需要修改的情况下,等待数据库完成后通过nid来修改.
 
非归档模式下的备份脚本:
  1. run
  2. {
  3. shutdown immediate;
  4. startup mount; #noarchive mode,must be mount
  5. allocate channel c1 type disk;
  6. allocate channel c2 type disk;
  7. backup database format '/u01/rman_backup/2011/201112/20111201/df_%t_%s_%p.bak';
  8. release channel c1;
  9. release channel c2;
  10. alter database open;
  11. }
备份完数据库将备份集拷贝到目的机器上后(具体拷贝过程可以通过FTP,我这里备份集拷贝到目的机器存放于/u01/ftp/mybak.),下面进行在目的机器上的恢复.
步骤1:创建相应目录,这里的前提是目的已经安装了Oracle软件,同时创建了oracle且相应设置了ORACLE_HOME,ORACLE_BASE这些变量.注意我这里ORACLE_SID为oracl,在创建的目录的时候需要做相应替换.
  1. mkdir -p $ORACLE_BASE/admin/oracl/{adump,bdump,cdump,dpdump,udump,pfile}
  2. mkdir -p $ORACLE_BASE/oradata/oracl
  3. mkdir -p $ORACLE_BASE/flash_recovery_area

步骤2:创建口令文件

  1. orapwd file=/u01/app/oracle/product/10.2.0/db_1/dbs/pwdoracl.ora password=oracle

步骤3:恢复初始化参数文件(这里需要找到包含初始化参数文件的备份集,在源端数据库可以通过list backup可以找到包含参数文件的备份集)

  1. [oracle@hxl dbs]$ export ORACLE_SID=oracl
  2. [oracle@hxl dbs]$ rman target /
  3. RMAN> startup nomount

  4. startup failed: ORA-01078: failure in processing system parameters
  5. LRM-00109: could not open parameter file '/u01/app/oracle/product/10.2.0/db_1/dbs/initoracl.ora'

  6. starting Oracle instance without parameter file for retrival of spfile
  7. Oracle instance started

  8. Total System Global Area 159383552 bytes

  9. Fixed Size 1218268 bytes
  10. Variable Size 54528292 bytes
  11. Database Buffers 100663296 bytes
  12. Redo Buffers 2973696 bytes

  13. RMAN> restore spfile to pfile '/u01/app/oracle/product/10.2.0/db_1/dbs/initoracl.ora' from '/u01/ftp/mybak/df_768589735_8_1.bak';

  14. Starting restore at 10-DEC-11
  15. using target database control file instead of recovery catalog
  16. allocated channel: ORA_DISK_1
  17. channel ORA_DISK_1: sid=36 devtype=DISK

  18. channel ORA_DISK_1: autobackup found: /u01/ftp/mybak/df_768589735_8_1.bak
  19. channel ORA_DISK_1: SPFILE restore from autobackup complete
  20. Finished restore at 10-DEC-11
  21. RMAN> shutdown immediate

  22. Oracle instance shut down

步骤4:修改初始化参数文件/u01/app/oracle/product/10.2.0/db_1/dbs/initoracl.ora(若如下参数路径跟原来的不一致则需要修改,这里源端和目的端的路径是一致的,所以不需要修改.

*.audit_file_dest='/u01/app/oracle/admin/oracl/adump'
*.background_dump_dest='/u01/app/oracle/admin/oracl/bdump'
*.control_files='/u01/app/oracle/oradata/oracl/control01.ctl','/u01/app/oracle/o
radata/oracl/control02.ctl','/u01/app/oracle/oradata/oracl/control03.ctl'
*.core_dump_dest='/u01/app/oracle/admin/oracl/cdump'
*.db_recovery_file_dest='/u01/app/oracle/flash_recovery_area'

步骤5:使用恢复的初始化参数文件nomount数据库

  1. [oracle@hxl dbs]$ sqlplus /nolog

  2. SQL*Plus: Release 10.2.0.1.0 - Production on Sat Dec 10 15:45:45 2011

  3. Copyright (c) 1982, 2005, Oracle. All rights reserved.

  4. SQL> connect / as sysdba
  5. Connected to an idle instance.
  6. SQL> startup nomount pfile=/u01/app/oracle/product/10.2.0/db_1/dbs/initoracl.ora
  7. ORACLE instance started.

  8. Total System Global Area 524288000 bytes
  9. Fixed Size 1220360 bytes
  10. Variable Size 159383800 bytes
  11. Database Buffers 360710144 bytes
  12. Redo Buffers 2973696 bytes
  13. SQL>

步骤6:恢复控制文件

  1. [oracle@hxl ~]$ rman target /

  2. Recovery Manager: Release 10.2.0.1.0 - Production on Sat Dec 10 15:47:36 2011

  3. Copyright (c) 1982, 2005, Oracle. All rights reserved.

  4. connected to target database: oracl (not mounted)

  5. RMAN> restore controlfile from '/u01/ftp/mybak/df_768589733_7_1.bak';

  6. Starting restore at 10-DEC-11
  7. using target database control file instead of recovery catalog
  8. allocated channel: ORA_DISK_1
  9. channel ORA_DISK_1: sid=155 devtype=DISK

  10. channel ORA_DISK_1: restoring control file
  11. channel ORA_DISK_1: restore complete, elapsed time: 00:00:05
  12. output filename=/u01/app/oracle/oradata/oracl/control01.ctl
  13. output filename=/u01/app/oracle/oradata/oracl/control02.ctl
  14. output filename=/u01/app/oracle/oradata/oracl/control03.ctl
  15. Finished restore at 10-DEC-11

进入到目录/u01/app/oracle/oradata/oracl,可以发现控制文件已经恢复,restore controlfile命令恢复控制文件到具体某个目录由参数文件中的参数*.control_files所决定.

[oracle@hxl oracl]$ ls -al
total 20732
drwxr-xr-x 2 oracle oinstall    4096 Dec 10 15:48 .
drwxr-xr-x 3 oracle oinstall    4096 Dec 10 15:25 ..
-rw-r----- 1 oracle oinstall 7061504 Dec 10 15:48 control01.ctl
-rw-r----- 1 oracle oinstall 7061504 Dec 10 15:48 control02.ctl
-rw-r----- 1 oracle oinstall 7061504 Dec 10 15:48 control03.ctl

步骤7:启动数据库到mount状态

RMAN> alter database mount;

database mounted
released channel: ORA_DISK_1

步骤8:将备份集的信息加入到catalog,使目前的控制文件记录有目前的备份信息,以便用户恢复.从远端数据库拷贝过来的备份集存放于目录/u01/ftp/mybak.

  1. RMAN> CATALOG START WITH '/u01/ftp/mybak';

  2. Starting implicit crosscheck backup at 10-DEC-11
  3. allocated channel: ORA_DISK_1
  4. channel ORA_DISK_1: sid=155 devtype=DISK
  5. Crosschecked 5 objects
  6. Finished implicit crosscheck backup at 10-DEC-11

  7. Starting implicit crosscheck copy at 10-DEC-11
  8. using channel ORA_DISK_1
  9. Finished implicit crosscheck copy at 10-DEC-11

  10. searching for all files in the recovery area
  11. cataloging files...
  12. no files cataloged

  13. searching for all files that match the pattern /u01/ftp/mybak

  14. List of Files Unknown to the Database
  15. =====================================
  16. File Name: /u01/ftp/mybak/df_768589735_8_1.bak
  17. File Name: /u01/ftp/mybak/df_768589674_5_1.bak
  18. File Name: /u01/ftp/mybak/bash_profile.txt
  19. File Name: /u01/ftp/mybak/df_768589733_7_1.bak
  20. File Name: /u01/ftp/mybak/df_768589674_6_1.bak

  21. Do you really want to catalog the above files (enter YES or NO)? YES
  22. cataloging files...
  23. cataloging done

  24. List of Cataloged Files
  25. =======================
  26. File Name: /u01/ftp/mybak/df_768589735_8_1.bak
  27. File Name: /u01/ftp/mybak/df_768589674_5_1.bak
  28. File Name: /u01/ftp/mybak/df_768589733_7_1.bak
  29. File Name: /u01/ftp/mybak/df_768589674_6_1.bak

  30. List of Files Which Where Not Cataloged
  31. =======================================
  32. File Name: /u01/ftp/mybak/bash_profile.txt
  33.   RMAN-07517: Reason: The file header is corrupted

步骤9:查看当前的备份信息,可以发现目前控制文件中已经记录了备份信息

  1. RMAN> list backup;


  2. List of Backup Sets
  3. ===================

  4. BS Key Type LV Size Device Type Elapsed Time Completion Time
  5. ------- ---- -- ---------- ----------- ------------ ---------------

  6. 1 Full 6.80M DISK 00:00:03 30-NOV-11
  7.         BP Key: 1 Status: EXPIRED Compressed: NO Tag: TAG20111130T164258
  8.         Piece Name: /u01/rman_backup/tmp/df_768588181_2_1.bak
  9.   Control File Included: Ckp SCN: 528487 Ckp time: 30-NOV-11
  10.   SPFILE Included: Modification time: 30-NOV-11

  11. BS Key Type LV Size Device Type Elapsed Time Completion Time
  12. ------- ---- -- ---------- ----------- ------------ ---------------

  13. 2 Full 525.08M DISK 00:00:57 30-NOV-11
  14.         BP Key: 2 Status: EXPIRED Compressed: NO Tag: TAG20111130T164547
  15.         Piece Name: /u01/rman_backup/tmp/df_768588349_3_1.bak
  16.   List of Datafiles in backup set 2
  17.   File LV Type Ckp SCN Ckp Time Name
  18.   ---- -- ---- ---------- --------- ----

  19.   1 Full 528611 30-NOV-11 /u01/app/oracle/oradata/oracl/system01.dbf
  20.   2 Full 528611 30-NOV-11 /u01/app/oracle/oradata/oracl/undotbs01.dbf
  21.   3 Full 528611 30-NOV-11 /u01/app/oracle/oradata/oracl/sysaux01.dbf
  22.   4 Full 528611 30-NOV-11 /u01/app/oracle/oradata/oracl/users01.dbf
  23.   5 Full 528611 30-NOV-11 /u01/app/oracle/oradata/oracl/hxl01.dbf

  24. BS Key Type LV Size Device Type Elapsed Time Completion Time
  25. ------- ---- -- ---------- ----------- ------------ ---------------

  26. 3 Full 6.80M DISK 00:00:03 30-NOV-11
  27.         BP Key: 3 Status: EXPIRED Compressed: NO Tag: TAG20111130T164547
  28.         Piece Name: /u01/rman_backup/tmp/df_768588418_4_1.bak
  29.   Control File Included: Ckp SCN: 528611 Ckp time: 30-NOV-11
  30.   SPFILE Included: Modification time: 30-NOV-11

  31. BS Key Type LV Size
  32. ------- ---- -- ----------

  33. 4 Full 351.26M
  34.   List of Datafiles in backup set 4
  35.   File LV Type Ckp SCN Ckp Time Name
  36.   ---- -- ---- ---------- --------- ----

  37.   1 Full 530571 30-NOV-11 /u01/app/oracle/oradata/oracl/system01.dbf
  38.   4 Full 530571 30-NOV-11 /u01/app/oracle/oradata/oracl/users01.dbf

  39.   Backup Set Copy #1 of backup set 4
  40.   Device Type Elapsed Time Completion Time Compressed Tag
  41.   ----------- ------------ --------------- ---------- ---

  42.   DISK 00:00:51 30-NOV-11 NO TAG20111130T170752

  43.     List of Backup Pieces for backup set 4 Copy #1
  44.     BP Key Pc# Status Piece Name
  45.     ------- --- ----------- ----------

  46.     4 1 EXPIRED /u01/rman_backup/2011/201111/df_768589674_5_1.bak

  47.   Backup Set Copy #2 of backup set 4
  48.   Device Type Elapsed Time Completion Time Compressed Tag
  49.   ----------- ------------ --------------- ---------- ---

  50.   DISK 00:00:51 10-DEC-11 NO TAG20111130T170752

  51.     List of Backup Pieces for backup set 4 Copy #2
  52.     BP Key Pc# Status Piece Name
  53.     ------- --- ----------- ----------

  54.     7 1 AVAILABLE /u01/ftp/mybak/df_768589674_5_1.bak

  55. BS Key Type LV Size
  56. ------- ---- -- ----------

  57. 5 Full 173.91M
  58.   List of Datafiles in backup set 5
  59.   File LV Type Ckp SCN Ckp Time Name
  60.   ---- -- ---- ---------- --------- ----

  61.   2 Full 530571 30-NOV-11 /u01/app/oracle/oradata/oracl/undotbs01.dbf
  62.   3 Full 530571 30-NOV-11 /u01/app/oracle/oradata/oracl/sysaux01.dbf
  63.   5 Full 530571 30-NOV-11 /u01/app/oracle/oradata/oracl/hxl01.dbf

  64.   Backup Set Copy #1 of backup set 5
  65.   Device Type Elapsed Time Completion Time Compressed Tag
  66.   ----------- ------------ --------------- ---------- ---

  67.   DISK 00:00:55 30-NOV-11 NO TAG20111130T170752

  68.     List of Backup Pieces for backup set 5 Copy #1
  69.     BP Key Pc# Status Piece Name
  70.     ------- --- ----------- ----------

  71.     5 1 EXPIRED /u01/rman_backup/2011/201111/df_768589674_6_1.bak

  72.   Backup Set Copy #2 of backup set 5
  73.   Device Type Elapsed Time Completion Time Compressed Tag
  74.   ----------- ------------ --------------- ---------- ---

  75.   DISK 00:00:55 10-DEC-11 NO TAG20111130T170752

  76.     List of Backup Pieces for backup set 5 Copy #2
  77.     BP Key Pc# Status Piece Name
  78.     ------- --- ----------- ----------

  79.     9 1 AVAILABLE /u01/ftp/mybak/df_768589674_6_1.bak

  80. BS Key Type LV Size Device Type Elapsed Time Completion Time
  81. ------- ---- -- ---------- ----------- ------------ ---------------

  82. 6 Full 80.00K DISK 00:00:00 30-NOV-11
  83.         BP Key: 6 Status: AVAILABLE Compressed: NO Tag: TAG20111130T170752
  84.         Piece Name: /u01/ftp/mybak/df_768589735_8_1.bak
  85.   SPFILE Included: Modification time: 30-NOV-11

  86. BS Key Type LV Size Device Type Elapsed Time Completion Time
  87. ------- ---- -- ---------- ----------- ------------ ---------------

  88. 7 Full 6.77M DISK 00:00:00 30-NOV-11
  89.         BP Key: 8 Status: AVAILABLE Compressed: NO Tag: TAG20111130T170752
  90.         Piece Name: /u01/ftp/mybak/df_768589733_7_1.bak
  91.   Control File Included: Ckp SCN: 530571 Ckp time: 30-NOV-11

步骤10:恢复数据文件,数据文件存放的回复目录跟源端的目录是一致的,所以这里不需要set newname 来转换数据文件的转换.

  1. RMAN> restore database;

  2. Starting restore at 10-DEC-11
  3. using channel ORA_DISK_1

  4. channel ORA_DISK_1: starting datafile backupset restore
  5. channel ORA_DISK_1: specifying datafile(s) to restore from backup set
  6. restoring datafile 00001 to /u01/app/oracle/oradata/oracl/system01.dbf
  7. restoring datafile 00004 to /u01/app/oracle/oradata/oracl/users01.dbf
  8. channel ORA_DISK_1: reading from backup piece /u01/ftp/mybak/df_768589674_5_1.bak
  9. channel ORA_DISK_1: restored backup piece 1
  10. piece handle=/u01/ftp/mybak/df_768589674_5_1.bak tag=TAG20111130T170752
  11. channel ORA_DISK_1: restore complete, elapsed time: 00:00:50
  12. channel ORA_DISK_1: starting datafile backupset restore
  13. channel ORA_DISK_1: specifying datafile(s) to restore from backup set
  14. restoring datafile 00002 to /u01/app/oracle/oradata/oracl/undotbs01.dbf
  15. restoring datafile 00003 to /u01/app/oracle/oradata/oracl/sysaux01.dbf
  16. restoring datafile 00005 to /u01/app/oracle/oradata/oracl/hxl01.dbf
  17. channel ORA_DISK_1: reading from backup piece /u01/ftp/mybak/df_768589674_6_1.bak
  18. channel ORA_DISK_1: restored backup piece 1
  19. piece handle=/u01/ftp/mybak/df_768589674_6_1.bak tag=TAG20111130T170752
  20. channel ORA_DISK_1: restore complete, elapsed time: 00:00:36
  21. Finished restore at 10-DEC-11

步骤11:恢复数据库

  1. RMAN> recover database;

  2. Starting recover at 10-DEC-11
  3. using channel ORA_DISK_1

  4. starting media recovery

  5. unable to find archive log
  6. archive log thread=1 sequence=4
  7. RMAN-00571: ===========================================================
  8. RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
  9. RMAN-00571: ===========================================================
  10. RMAN-03002: failure of recover command at 12/10/2011 16:13:43
  11. RMAN-06054: media recovery requesting unknown log: thread 1 seq 4 lowscn 530571

这里提示找不到scn是530571的日志文件,因为这里的数据库是在非归档模式下备份的,相当于是冷备份,没有任何的归档日志,这里不需要使用归档日志恢复,直接使用resetlogs打开数据库即可.

步骤12:打开数据库

RMAN> alter database open resetlogs;

步骤13:处理redo日记文件

查看日志文件,我的数据库版本是10GR2,使用resetlogs打开数据库后,系统自动会创建3组日记文件,这里日志文件的目录跟源端日志文件的目录是一致的,这里不要重新创建日志文件(主要目的是改变日志文件存放的路径)
SQL> select * from v$logfile;

    GROUP# STATUS  TYPE    MEMBER                                   IS_
---------- ------- ------- ---------------------------------------- ---
         3         ONLINE  /u01/app/oracle/oradata/oracl/redo03.log NO
         2         ONLINE  /u01/app/oracle/oradata/oracl/redo02.log NO
         1         ONLINE  /u01/app/oracle/oradata/oracl/redo01.log NO

步骤14:处理临时表空间数据文件

默认情况下,使用resetlogs打开数据库后,系统会创建临时文件temp01.dbf,因为这里临时文件存放的路径跟源端一致,所以也不需要做迁移.
SQL> select name from v$tempfile;

NAME
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/oracl/temp01.dbf

步骤15:验证数据
SQL>connect hxl/hxl
SQL> select * from tb_test;

        ID NAME
---------- ----------
         1 test01
         2 test02
         3 test03
         4 test04

步骤16:创建spfile

SQL> connect / as sysdba
SQL> create spfile from pfile='/u01/app/oracle/product/10.2.0/db_1/dbs/initoracl.ora';

步骤17:配置监听器

可以使用netca配置监听器,想必大家都比较熟悉配置过程,这里具体过程省略.

恢复过程完成!

阅读(251) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~