Chinaunix首页 | 论坛 | 博客
  • 博客访问: 5205247
  • 博文数量: 1004
  • 博客积分: 8199
  • 博客等级: 中将
  • 技术积分: 13042
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-25 20:19
个人简介

脚踏实地、勇往直前!

文章分类

全部博文(1004)

文章存档

2020年(1)

2019年(93)

2018年(208)

2017年(81)

2016年(49)

2015年(50)

2014年(170)

2013年(52)

2012年(177)

2011年(93)

2010年(30)

分类: Oracle

2011-12-12 20:21:35

源端和目的端的操作系统和数据库:
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/rman_backup/mybak),下面进行在目的机器上的恢复.
 
步骤1:创建数据库恢复的路径跟源库路径不相同(源库的路径是/u01/app/oracle)
[oracle@hxl01 /]$ mkdir /u01/mydb
 
步骤2:创建数据库各文件目录
[oracle@hxl01 u01]$ mkdir -p /u01/mydb/oracl/{adump,bdump,cdump,dpdump,udump,pfile}
[oracle@hxl01 u01]$ mkdir -p /u01/mydb/oradata/oracl
[oracle@hxl01 u01]$ mkdir -p /u01/mydb/flash_recovery_area
 
步骤3:创建口令文件(linux口令文件命名格式为orapwSID,windows口令文件命名格式为pwdSID)
orapwd file=/u01/app/oracle/product/10.2.0/db_1/dbs/orapworacl.ora password=oracle
 
步骤4:恢复初始化参数文件(这里需要找到包含初始化参数文件的备份集,在源端数据库可以通过list backup可以找到包含参数文件的备份集)
  1. [oracle@hxl01 dbs]$ export ORACLE_SID=oracl
  2. [oracle@hxl01 dbs]$ rman target /
  3. Recovery Manager: Release 10.2.0.1.0 - Production on Mon Dec 12 11:26:55 2011
  4. Copyright (c) 1982, 2005, Oracle. All rights reserved.
  5. connected to target database (not started)
  6. RMAN> startup nomount
  7. startup failed: ORA-01078: failure in processing system parameters
  8. LRM-00109: could not open parameter file '/u01/app/oracle/product/10.2.0/db_1/db s/initoracl.ora'
  9. starting Oracle instance without parameter file for retrival of spfile
  10. Oracle instance started
  11. Total System Global Area 159383552 bytes
  12. Fixed Size 1218268 bytes
  13. Variable Size 54528292 bytes
  14. Database Buffers 100663296 bytes
  15. Redo Buffers 2973696 bytes
  16. RMAN>
  17. RMAN>restore spfile to pfile '/u01/app/oracle/product/10.2.0/db_1/dbs/initoracl.ora' from '/u01/rman_backup/mybak/df_768589735_8_1.bak';
  18. Starting restore at 12-DEC-11
  19. using target database control file instead of recovery catalog
  20. allocated channel: ORA_DISK_1
  21. channel ORA_DISK_1: sid=36 devtype=DISK
  22. channel ORA_DISK_1: autobackup found: /u01/rman_backup/mybak/df_768589735_8_1.bak
  23. channel ORA_DISK_1: SPFILE restore from autobackup complete
  24. Finished restore at 12-DEC-11
  25. RMAN> shutdown immediate
  26. Oracle instance shut down

步骤5:修改初始化参数文件

*.audit_file_dest='/u01/mydb/oracl/adump'
*.background_dump_dest='/u01/mydb/oracl/bdump'
*.control_files='/u01/mydb/oradata/oracl/control01.ctl','/u01/mydb/oradata/oracl/control02.ctl','/u01/mydb/oradata/oracl/control03.ctl'
*.core_dump_dest='/u01/mydb/oracl/cdump'
*.db_recovery_file_dest='/u01/mydb/flash_recovery_area'
*.user_dump_dest='/u01/mydb/oracl/udump'

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

  1. [oracle@hxl01 dbs]$ sqlplus /nolog
  2. SQL*Plus: Release 10.2.0.1.0 - Production on Mon Dec 12 11:45:19 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>

步骤7:恢复控制文件

  1. RMAN> restore controlfile from '/u01/rman_backup/mybak/df_768589733_7_1.bak';
  2. Starting restore at 12-DEC-11
  3. using target database control file instead of recovery catalog
  4. allocated channel: ORA_DISK_1
  5. channel ORA_DISK_1: sid=156 devtype=DISK
  6. channel ORA_DISK_1: restoring control file
  7. channel ORA_DISK_1: restore complete, elapsed time: 00:00:02
  8. output filename=/u01/mydb/oradata/oracl/control01.ctl
  9. output filename=/u01/mydb/oradata/oracl/control02.ctl
  10. output filename=/u01/mydb/oradata/oracl/control03.ctl
  11. Finished restore at 12-DEC-11
  12. RMAN>

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

RMAN> alter database mount;
database mounted
released channel: ORA_DISK_1

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

  1. RMAN> catalog start with '/u01/rman_backup/mybak';
  2. Starting implicit crosscheck backup at 12-DEC-11
  3. allocated channel: ORA_DISK_1
  4. channel ORA_DISK_1: sid=156 devtype=DISK
  5. Crosschecked 5 objects
  6. Finished implicit crosscheck backup at 12-DEC-11
  7. Starting implicit crosscheck copy at 12-DEC-11
  8. using channel ORA_DISK_1
  9. Finished implicit crosscheck copy at 12-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/rman_backup/mybak
  14. List of Files Unknown to the Database
  15. =====================================
  16. File Name: /u01/rman_backup/mybak/bash_profile.txt
  17. File Name: /u01/rman_backup/mybak/df_768589733_7_1.bak
  18. File Name: /u01/rman_backup/mybak/df_768589674_5_1.bak
  19. File Name: /u01/rman_backup/mybak/df_768589674_6_1.bak
  20. File Name: /u01/rman_backup/mybak/df_768589735_8_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/rman_backup/mybak/df_768589733_7_1.bak
  27. File Name: /u01/rman_backup/mybak/df_768589674_5_1.bak
  28. File Name: /u01/rman_backup/mybak/df_768589674_6_1.bak
  29. File Name: /u01/rman_backup/mybak/df_768589735_8_1.bak
  30. List of Files Which Where Not Cataloged
  31. =======================================
  32. File Name: /u01/rman_backup/mybak/bash_profile.txt
  33.   RMAN-07517: Reason: The file header is corrupted

步骤10:恢复数据文件,因为恢复的路径跟源库的数据文件路径不一致,需要用set newname转换路径.

  1. RMAN> run{
  2. set newname for datafile 1 to '/u01/mydb/oradata/oracl/system01.dbf';
  3. set newname for datafile 2 to '/u01/mydb/oradata/oracl/undotbs01.dbf';
  4. set newname for datafile 3 to '/u01/mydb/oradata/oracl/sysaux01.dbf';
  5. set newname for datafile 4 to '/u01/mydb/oradata/oracl/users01.dbf';
  6. set newname for datafile 5 to '/u01/mydb/oradata/oracl/hxl01.dbf';
  7. restore database;
  8. switch datafile all;
  9. }
  10. executing command: SET NEWNAME
  11. executing command: SET NEWNAME
  12. executing command: SET NEWNAME
  13. executing command: SET NEWNAME
  14. executing command: SET NEWNAME
  15. Starting restore at 12-DEC-11
  16. using channel ORA_DISK_1
  17. channel ORA_DISK_1: starting datafile backupset restore
  18. channel ORA_DISK_1: specifying datafile(s) to restore from backup set
  19. restoring datafile 00001 to /u01/mydb/oradata/oracl/system01.dbf
  20. restoring datafile 00004 to /u01/mydb/oradata/oracl/users01.dbf
  21. channel ORA_DISK_1: reading from backup piece /u01/rman_backup/mybak/df_768589674_5_1.bak
  22. channel ORA_DISK_1: restored backup piece 1
  23. piece handle=/u01/rman_backup/mybak/df_768589674_5_1.bak tag=TAG20111130T170752
  24. channel ORA_DISK_1: restore complete, elapsed time: 00:00:38
  25. channel ORA_DISK_1: starting datafile backupset restore
  26. channel ORA_DISK_1: specifying datafile(s) to restore from backup set
  27. restoring datafile 00002 to /u01/mydb/oradata/oracl/undotbs01.dbf
  28. restoring datafile 00003 to /u01/mydb/oradata/oracl/sysaux01.dbf
  29. restoring datafile 00005 to /u01/mydb/oradata/oracl/hxl01.dbf
  30. channel ORA_DISK_1: reading from backup piece /u01/rman_backup/mybak/df_768589674_6_1.bak
  31. channel ORA_DISK_1: restored backup piece 1
  32. piece handle=/u01/rman_backup/mybak/df_768589674_6_1.bak tag=TAG20111130T170752
  33. channel ORA_DISK_1: restore complete, elapsed time: 00:00:26
  34. Finished restore at 12-DEC-11
  35. datafile 1 switched to datafile copy
  36. input datafile copy recid=6 stamp=769694142 filename=/u01/mydb/oradata/oracl/system01.dbf
  37. datafile 2 switched to datafile copy
  38. input datafile copy recid=7 stamp=769694142 filename=/u01/mydb/oradata/oracl/undotbs01.dbf
  39. datafile 3 switched to datafile copy
  40. input datafile copy recid=8 stamp=769694142 filename=/u01/mydb/oradata/oracl/sysaux01.dbf
  41. datafile 4 switched to datafile copy
  42. input datafile copy recid=9 stamp=769694142 filename=/u01/mydb/oradata/oracl/users01.dbf
  43. datafile 5 switched to datafile copy
  44. input datafile copy recid=10 stamp=769694142 filename=/u01/mydb/oradata/oracl/hxl01.dbf

步骤11:打开数据库

  1. SQL> alter database open resetlogs;
  2. alter database open resetlogs
  3. *
  4. ERROR at line 1:
  5. ORA-00344: unable to re-create online log
  6. '/u01/app/oracle/oradata/oracl/redo01.log'
  7. ORA-27040: file create error, unable to create file
  8. Linux Error: 2: No such file or directory

这里报找不到redo日志文件的错误,因为数据库是非归档的,日志文件没有备份,在新库中也没有redo日志文件,这里需要重新创建日志文件组.

alter database drop logfile group 1;
alter database add logfile group 1 '/u01/mydb/oradata/oracl/redo01.log' size 50m;
 
alter database drop logfile group 2;
alter database add logfile group 2 '/u01/mydb/oradata/oracl/redo02.log' size 50m;
日志组1和组2能顺利的删除并重新创建.

SQL> alter database drop logfile group 3;
alter database drop logfile group 3
*
ERROR at line 1:
ORA-01623: log 3 is current log for instance oracl (thread 1) - cannot drop
ORA-00312: online log 3 thread 1: '/u01/app/oracle/oradata/oracl/redo03.log'

呵呵,日志组3是当前日志组,当然删除不了.下面试着切换日志组,也不行,因为数据库未打开.

SQL> alter system switch logfile;
alter system switch logfile
*
ERROR at line 1:
ORA-01109: database not open

下面试着修改日志文件的在控制文件中的路径(restore回来的控制文件中记录的日志文件路径是源端日志文件的路径)

SQL> alter database rename file  '/u01/app/oracle/oradata/oracl/redo03.log' TO '/u01/mydb/oradata/oracl/redo03.log';
Database altered.

SQL>alter database open resetlogs;

步骤12:处理临时表空间文件

  1. SQL> connect / as sysdba
  2. Connected to an idle instance.
  3. SQL> startup
  4. ORACLE instance started.

  5. Total System Global Area 524288000 bytes
  6. Fixed Size 1220360 bytes
  7. Variable Size 159383800 bytes
  8. Database Buffers 360710144 bytes
  9. Redo Buffers 2973696 bytes
  10. Database mounted.
  11. Database opened.
  12. SQL> select * from dba_temp_files;
  13. Select * From Dba_Temp_Files
  14.               *
  15. ERROR at line 1:
  16. ORA-01157: cannot identify/lock data file 201 - see DBWR trace file
  17. ORA-01110: data file 201: '/u01/app/oracle/oradata/oracl/temp01.dbf'

  18. SQL> shutdown immediate
  19. Database closed.
  20. Database dismounted.
  21. ORACLE instance shut down.
  22. SQL> startup mount
  23. ORACLE instance started.

  24. Total System Global Area 524288000 bytes
  25. Fixed Size 1220360 bytes
  26. Variable Size 159383800 bytes
  27. Database Buffers 360710144 bytes
  28. Redo Buffers 2973696 bytes
  29. Database mounted.
  30. SQL> alter database rename file '/u01/app/oracle/oradata/oracl/temp01.dbf' TO '/u01/mydb/oradata/oracl/temp01.dbf';

  31. Database altered.


  32. SQL> select file_name,tablespace_name from dba_temp_files;

  33. FILE_NAME TABLESPACE_NAME
  34. ----------------------------------- ------------------------------

  35. /u01/mydb/oradata/oracl/temp01.dbf TEMP

步骤13:创建spfile

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

步骤14:配置监听器

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

总结:目的端数据文件若跟源端数据文件不一致的情况下,在restore的时候需要使用set newname改变目的端数据文件的路径,同时日志文件和临时表空间文件与源端路径不一致的情况下,需要修改控制文件的中信息,以便控制文件能够识别目的端的路径.


 

阅读(2393) | 评论(0) | 转发(1) |
0

上一篇:日常维护脚本

下一篇:rman list命令

给主人留下些什么吧!~~