源端和目的端的操作系统和数据库:
Os:Red Hat Linux As 5
Db Version:10GR2
前期准备,需要备份源数据库,备份脚本可以参考如下,将备份集拷贝到目的机器上.在目的机器恢复的过程中,db_name,oracle_sid,dbid设置必须跟源数据库保持一致,若需要修改的情况下,等待数据库完成后通过nid来修改.
非归档模式下的备份脚本:
- run
- {
- shutdown immediate;
- startup mount; #noarchive mode,must be mount
- allocate channel c1 type disk;
- allocate channel c2 type disk;
- backup database format '/u01/rman_backup/2011/201112/20111201/df_%t_%s_%p.bak';
- release channel c1;
- release channel c2;
- alter database open;
- }
备份完数据库将备份集拷贝到目的机器上后(具体拷贝过程可以通过FTP,我这里备份集拷贝到目的机器存放于/u01/ftp/mybak.),下面进行在目的机器上的恢复.
步骤1:创建相应目录,这里的前提是目的已经安装了Oracle软件,同时创建了oracle且相应设置了ORACLE_HOME,ORACLE_BASE这些变量.注意我这里ORACLE_SID为oracl,在创建的目录的时候需要做相应替换.
- mkdir -p $ORACLE_BASE/admin/oracl/{adump,bdump,cdump,dpdump,udump,pfile}
- mkdir -p $ORACLE_BASE/oradata/oracl
- mkdir -p $ORACLE_BASE/flash_recovery_area
步骤2:创建口令文件
- orapwd file=/u01/app/oracle/product/10.2.0/db_1/dbs/pwdoracl.ora password=oracle
步骤3:恢复初始化参数文件(这里需要找到包含初始化参数文件的备份集,在源端数据库可以通过list backup可以找到包含参数文件的备份集)
- [oracle@hxl dbs]$ export ORACLE_SID=oracl
- [oracle@hxl dbs]$ rman target /
- RMAN> startup nomount
- startup failed: ORA-01078: failure in processing system parameters
- LRM-00109: could not open parameter file '/u01/app/oracle/product/10.2.0/db_1/dbs/initoracl.ora'
- starting Oracle instance without parameter file for retrival of spfile
- Oracle instance started
- Total System Global Area 159383552 bytes
- Fixed Size 1218268 bytes
- Variable Size 54528292 bytes
- Database Buffers 100663296 bytes
- Redo Buffers 2973696 bytes
- 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';
- Starting restore at 10-DEC-11
- using target database control file instead of recovery catalog
- allocated channel: ORA_DISK_1
- channel ORA_DISK_1: sid=36 devtype=DISK
- channel ORA_DISK_1: autobackup found: /u01/ftp/mybak/df_768589735_8_1.bak
- channel ORA_DISK_1: SPFILE restore from autobackup complete
- Finished restore at 10-DEC-11
- RMAN> shutdown immediate
- 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数据库
- [oracle@hxl dbs]$ sqlplus /nolog
- SQL*Plus: Release 10.2.0.1.0 - Production on Sat Dec 10 15:45:45 2011
- Copyright (c) 1982, 2005, Oracle. All rights reserved.
- SQL> connect / as sysdba
- Connected to an idle instance.
- SQL> startup nomount pfile=/u01/app/oracle/product/10.2.0/db_1/dbs/initoracl.ora
- ORACLE instance started.
- Total System Global Area 524288000 bytes
- Fixed Size 1220360 bytes
- Variable Size 159383800 bytes
- Database Buffers 360710144 bytes
- Redo Buffers 2973696 bytes
- SQL>
步骤6:恢复控制文件
- [oracle@hxl ~]$ rman target /
- Recovery Manager: Release 10.2.0.1.0 - Production on Sat Dec 10 15:47:36 2011
- Copyright (c) 1982, 2005, Oracle. All rights reserved.
- connected to target database: oracl (not mounted)
- RMAN> restore controlfile from '/u01/ftp/mybak/df_768589733_7_1.bak';
- Starting restore at 10-DEC-11
- using target database control file instead of recovery catalog
- allocated channel: ORA_DISK_1
- channel ORA_DISK_1: sid=155 devtype=DISK
- channel ORA_DISK_1: restoring control file
- channel ORA_DISK_1: restore complete, elapsed time: 00:00:05
- output filename=/u01/app/oracle/oradata/oracl/control01.ctl
- output filename=/u01/app/oracle/oradata/oracl/control02.ctl
- output filename=/u01/app/oracle/oradata/oracl/control03.ctl
- 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.
- RMAN> CATALOG START WITH '/u01/ftp/mybak';
- Starting implicit crosscheck backup at 10-DEC-11
- allocated channel: ORA_DISK_1
- channel ORA_DISK_1: sid=155 devtype=DISK
- Crosschecked 5 objects
- Finished implicit crosscheck backup at 10-DEC-11
- Starting implicit crosscheck copy at 10-DEC-11
- using channel ORA_DISK_1
- Finished implicit crosscheck copy at 10-DEC-11
- searching for all files in the recovery area
- cataloging files...
- no files cataloged
- searching for all files that match the pattern /u01/ftp/mybak
- List of Files Unknown to the Database
- =====================================
- File Name: /u01/ftp/mybak/df_768589735_8_1.bak
- File Name: /u01/ftp/mybak/df_768589674_5_1.bak
- File Name: /u01/ftp/mybak/bash_profile.txt
- File Name: /u01/ftp/mybak/df_768589733_7_1.bak
- File Name: /u01/ftp/mybak/df_768589674_6_1.bak
- Do you really want to catalog the above files (enter YES or NO)? YES
- cataloging files...
- cataloging done
- List of Cataloged Files
- =======================
- File Name: /u01/ftp/mybak/df_768589735_8_1.bak
- File Name: /u01/ftp/mybak/df_768589674_5_1.bak
- File Name: /u01/ftp/mybak/df_768589733_7_1.bak
- File Name: /u01/ftp/mybak/df_768589674_6_1.bak
- List of Files Which Where Not Cataloged
- =======================================
- File Name: /u01/ftp/mybak/bash_profile.txt
- RMAN-07517: Reason: The file header is corrupted
步骤9:查看当前的备份信息,可以发现目前控制文件中已经记录了备份信息
步骤10:恢复数据文件,数据文件存放的回复目录跟源端的目录是一致的,所以这里不需要set newname 来转换数据文件的转换.
- RMAN> restore database;
- Starting restore at 10-DEC-11
- using channel ORA_DISK_1
- channel ORA_DISK_1: starting datafile backupset restore
- channel ORA_DISK_1: specifying datafile(s) to restore from backup set
- restoring datafile 00001 to /u01/app/oracle/oradata/oracl/system01.dbf
- restoring datafile 00004 to /u01/app/oracle/oradata/oracl/users01.dbf
- channel ORA_DISK_1: reading from backup piece /u01/ftp/mybak/df_768589674_5_1.bak
- channel ORA_DISK_1: restored backup piece 1
- piece handle=/u01/ftp/mybak/df_768589674_5_1.bak tag=TAG20111130T170752
- channel ORA_DISK_1: restore complete, elapsed time: 00:00:50
- channel ORA_DISK_1: starting datafile backupset restore
- channel ORA_DISK_1: specifying datafile(s) to restore from backup set
- restoring datafile 00002 to /u01/app/oracle/oradata/oracl/undotbs01.dbf
- restoring datafile 00003 to /u01/app/oracle/oradata/oracl/sysaux01.dbf
- restoring datafile 00005 to /u01/app/oracle/oradata/oracl/hxl01.dbf
- channel ORA_DISK_1: reading from backup piece /u01/ftp/mybak/df_768589674_6_1.bak
- channel ORA_DISK_1: restored backup piece 1
- piece handle=/u01/ftp/mybak/df_768589674_6_1.bak tag=TAG20111130T170752
- channel ORA_DISK_1: restore complete, elapsed time: 00:00:36
- Finished restore at 10-DEC-11
步骤11:恢复数据库
- RMAN> recover database;
- Starting recover at 10-DEC-11
- using channel ORA_DISK_1
- starting media recovery
- unable to find archive log
- archive log thread=1 sequence=4
- RMAN-00571: ===========================================================
- RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
- RMAN-00571: ===========================================================
- RMAN-03002: failure of recover command at 12/10/2011 16:13:43
- 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配置监听器,想必大家都比较熟悉配置过程,这里具体过程省略.
恢复过程完成!
阅读(243) | 评论(0) | 转发(0) |