RMAN做数据库全备时包含了 数据文件、归档日志、控制文件和参数文件和备份日志,如下:
arch_20160223_08qukp2t_1_1 arch_20160223_0bqukp92_1_1 ctl_c-3234695588-20160223-01 rmanbak-20160223-0852.log scp_20160223_09qukp2u_1_1 scp_20160223_0aqukp2u_1_1
二、测试环境
OS:CentOS release 6.4 (Final)
Database:Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
原平台与当前平台环境一致,但是oracle数据库目录结构不一致。
三、开始恢复
1、 确认原数据库的DBID(通过RMAN的备份日志,或者通过RMAN备份的控制文件名来识别),同时确认一下原数据库的实例名;
2、 将RMAN备份的内容拷贝到目标数据库上;
3、 设置好环境变量:
[oracle@dg1 ~]$ export NLS_DATA_FORMAT='YYYY-MM-DD HH24:MI:SS'
[oracle@dg1 ~]$ export ORACLE_SID=scp
[oracle@dg1 ~]$ rman target /
Recovery Manager: Release 12.1.0.2.0 - Production on Fri May 6 22:18:52 2016
4、装载数据库并进行恢复
A、装载数据库
复制代码
RMAN>set dbid=3234695588
executing command: SET DBID
RMAN>startup nomount
startup failed: ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file '/u01/app/oracle/product/12.1.0.2/dbs/initscp.ora'
starting Oracle instance without parameter file for retrieval of spfile
Oracle instance started
复制代码
B、先恢复spfile文件(或者是pfile文件,可以修改各项参数),因为在spfile 文件中包含了控制文件的位置
RMAN>restore spfile to pfile '$ORACLE_HOME/dbs/initscp.ora' from '/home/OracleBack/rmanbak/ctl_c-3234695588-20160223-01'
OR:
RMAN>restore spfile to '$ORACLE_HOME/dbs/spfilescp.ora' from '/home/OracleBack/rmanbak/ctl_c-3234695588-20160223-01'
C、根据pfile文件中的相关参数去修改本地系统目录,或者修改这个pfile文件来匹配本地系统中的路径和目录,我们选择后者
需要修改:oracle_base、*.audit_file_dest、*.control_files、*.db_recovery_file_dest、*.db_recovery_file_dest_size、*.diagnostic_dest、*.log_archive_dest_1、
memory_target、undo_tablespace等。并在当前系统中创建好相关的目录和权限。
复制代码
[oracle@dg1 dbs]$ vim initscp.ora
scp.__data_transfer_cache_size=0
scp.__db_cache_size=822083584
scp.__java_pool_size=16777216
scp.__large_pool_size=33554432
scp.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment
scp.__pga_aggregate_target=654311424
scp.__sga_target=1241513984
scp.__shared_io_pool_size=50331648
scp.__shared_pool_size=301989888
scp.__streams_pool_size=0
*.audit_file_dest='/u01/app/oracle/admin/scp/adump'
*.audit_trail='db'
*.compatible='12.1.0.2.0'
*.control_files='/u01/app/oracle/oradata/scp/control01.ctl','/u01/app/oracle/fast_recovery_area/scp/control02.ctl'
*.db_block_size=8192
*.db_domain=''
*.db_name='scp'
*.db_recovery_file_dest='/u01/app/oracle/fast_recovery_area'
*.db_recovery_file_dest_size=4560m
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=scpXDB)'
*.log_archive_dest_1='LOCATION=/OracleArch'
*.memory_target=1800m
*.open_cursors=300
*.processes=300
*.remote_login_passwordfile='EXCLUSIVE'
*.undo_tablespace='UNDOTBS1'
复制代码
D、从修改后的pfile文件启动数据库,进行控制文件的恢复
复制代码
RMAN>shutdown abort
RMAN>startup nomount pfile='$ORACLE_HOME/dbs/initscp.ora'
RMAN>restore controlfile from '/home/OracleBack/rmanbak/ctl_c-3234695588-20160223-01'
Starting restore at 06-MAY-16
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=243 device type=DISK
channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/home/OracleData/scp/control01.ctl
output file name=/home/OracleArch/fast_recovery_area/control02.ctl
Finished restore at 06-MAY-16
复制代码
E、控制文件恢复后就可以mount数据库了
RMAN>alter database mount
Statement processed
released channel: ORA_DISK_1
F、至此,控制文件已经恢复,数据库已经mount,所有的RMAN配置参数均已设置,您应该验证路径以确保它们适用于该主机。
复制代码
RMAN>show all
RMAN configuration parameters for database with db_unique_name SCP 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 '/orabackup/RmanBackupSet/20160223/ctl_%F'
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 RMAN OUTPUT TO KEEP FOR 7 DAYS# default
CONFIGURE ARCHIVELOG DELETION POLICY TO NONE# default
CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/u01/app/oracle/product/12.1.0.2/dbs/snapcf_scp.f'# default
复制代码
G、为了能让RMAN找到恢复文件的位置,我们有两种途径可以实现:一是修改RMAN配置以符合当前备份文件所在位置,其次是将RMAN备份文件拷贝到配置文件中设定的位置 (需要参考RMAN的备份日志)。在第一个方法中,为了让RMAN知道备份文件位置 /home/OracleBack/rmanbak ,我们使用catalog命令:
复制代码
RMAN>catalog start with '/home/OracleBack/rmanbak'
Starting implicit crosscheck backup at 06-MAY-16
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=243 device type=DISK
Crosschecked 4 objects
Finished implicit crosscheck backup at 06-MAY-16
Starting implicit crosscheck copy at 06-MAY-16
using channel ORA_DISK_1
Finished implicit crosscheck copy at 06-MAY-16
searching for all files in the recovery area
cataloging files...
no files cataloged
searching for all files that match the pattern /home/OracleBack/rmanbak
List of Files Unknown to the Database
=====================================
File Name: /home/OracleBack/rmanbak/scp_20160223_09qukp2u_1_1
File Name: /home/OracleBack/rmanbak/arch_20160223_0bqukp92_1_1
File Name: /home/OracleBack/rmanbak/scp_20160223_0aqukp2u_1_1
File Name: /home/OracleBack/rmanbak/ctl_c-3234695588-20160223-01
File Name: /home/OracleBack/rmanbak/arch_20160223_08qukp2t_1_1
Do you really want to catalog the above files (enter YES or NO)? yes
cataloging files...
cataloging done
List of Cataloged Files
=======================
File Name: /home/OracleBack/rmanbak/scp_20160223_09qukp2u_1_1
File Name: /home/OracleBack/rmanbak/arch_20160223_0bqukp92_1_1
File Name: /home/OracleBack/rmanbak/scp_20160223_0aqukp2u_1_1
File Name: /home/OracleBack/rmanbak/ctl_c-3234695588-20160223-01
File Name: /home/OracleBack/rmanbak/arch_20160223_08qukp2t_1_1
复制代码
H、对备份集做交叉检查,否则还原数据库时可能会报错
复制代码
RMAN>crosscheck backup
using channel ORA_DISK_1
crosschecked backup piece: found to be 'EXPIRED'
backup piece handle=/orabackup/RmanBackupSet/20160223/arch_20160223_08qukp2t_1_1 RECID=8 STAMP=904553565
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/home/OracleBack/rmanbak/arch_20160223_08qukp2t_1_1 RECID=16 STAMP=911172456
crosschecked backup piece: found to be 'EXPIRED'
backup piece handle=/orabackup/RmanBackupSet/20160223/scp_20160223_0aqukp2u_1_1 RECID=9 STAMP=904553567
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/home/OracleBack/rmanbak/scp_20160223_0aqukp2u_1_1 RECID=14 STAMP=911172456
crosschecked backup piece: found to be 'EXPIRED'
backup piece handle=/orabackup/RmanBackupSet/20160223/scp_20160223_09qukp2u_1_1 RECID=10 STAMP=904553567
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/home/OracleBack/rmanbak/scp_20160223_09qukp2u_1_1 RECID=12 STAMP=911172456
crosschecked backup piece: found to be 'EXPIRED'
backup piece handle=/orabackup/RmanBackupSet/20160223/arch_20160223_0bqukp92_1_1 RECID=11 STAMP=904553762
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/home/OracleBack/rmanbak/arch_20160223_0bqukp92_1_1 RECID=13 STAMP=911172456
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/home/OracleBack/rmanbak/ctl_c-3234695588-20160223-01 RECID=15 STAMP=911172456
Crosschecked 9 objects
复制代码
I、通过控制文件获得表空间及数据文件列表
复制代码
RMAN>report schema
RMAN-06139: WARNING: control file is not current for REPORT SCHEMA
Report of database schema for database with db_unique_name SCP
List of Permanent Datafiles
===========================
File Size(MB) Tablespace RB segs Datafile Name
---- -------- -------------------- ------- ------------------------
10SYSTEM *** /u01/app/oracle/oradata/scp/system01.dbf
20ZYTK_AC *** /u01/app/oracle/oradata/scp/zytk_ac01.dbf
30SYSAUX *** /u01/app/oracle/oradata/scp/sysaux01.dbf
40UNDOTBS1 *** /u01/app/oracle/oradata/scp/undotbs01.dbf
50EXAMPLE *** /u01/app/oracle/oradata/scp/example01.dbf
60USERS*** /u01/app/oracle/oradata/scp/users01.dbf
70ZYTK_AC *** /u01/app/oracle/oradata/scp/zytk_ac02.dbf
80ZYTK_ID *** /u01/app/oracle/oradata/scp/zytk_id01.dbf
90ZYTK_ID *** /u01/app/oracle/oradata/scp/zytk_id02.dbf
10 0ZYTK_OP *** /u01/app/oracle/oradata/scp/zytk_op01.dbf
11 0ZYTK_OP *** /u01/app/oracle/oradata/scp/zytk_op02.dbf
12 0ZYTK_TEST01 *** /u01/app/oracle/oradata/scp/zytk_test01.dbf
List of Temporary Files
=======================
File Size(MB) Tablespace Maxsize(MB) Tempfile Name
---- -------- -------------------- ----------- --------------------
160 TEMP 32767 /u01/app/oracle/oradata/scp/temp01.dbf
注意:restore 的时候不会对temp 表空间进行restore。所以等restore 之后,我们需要手工创建temp表空间。
源服务器和目的服务器的 *** 作系统,oracle版本均一致一:在源服务器上使用rman备份数据库,包括数据文件,归档日志文件和控制文件,参数文件的备份
二:在目的服务器上复制备份数据,并准备好相关的目录
三:在目的服务器上进行恢复,指定DBID,需要和源服务器的DBID一致
启动数据库到nomount状态,这里需要前面创建initorcl.ora文件,否则将报错 恢复参数文件 重启实例到nomout状态 恢复控制文件 还原数据库文件 恢复数据库文件,这里将报错
在sqlplus中对数据库进行until cancel *** 作后以resetlogs方式打开
1. NOARCHIVELOG模式如果在NOARCHIVELOG模式下丢失数据库中的任何数据文件,则需要完全恢复数据库,包括控制文件和所有数据文件。
如果数据库处于NOARCHIVELOG模式,则只能在最后一次备份之前恢复。因此,用户必须重新输入自备份以来所做的所有更改。
使用Enterprise Manager Cloud Control来执行这种类型的恢复:
如果还没有关闭实例,则关闭它。
选择可用性>备份和恢复>执行恢复。
选择整个数据库作为恢复类型。
如果有一个处于NOARCHIVELOG模式、具有增量备份策略的数据库,则RMAN首先还原最近的0级,然后RMAN恢复应用增量备份
2. ARCHIVELOG模式
如果数据库处于ARCHIVELOG模式,那么丢失不属于系统或UNDO表空间的任何数据文件只会影响丢失文件中的对象。数据库的其余部分仍然可供用户继续工作。
3. 关键文件损坏
属于系统表空间或包含撤消数据的数据文件被认为是系统关键文件。丢失其中一个文件需要从挂载状态恢复数据库(不像其他数据文件可以在数据库打开时恢复)。
使用Enterprise Manager Cloud Control执行此恢复:
如果实例还没有关闭,请关闭它。
挂载数据库。
选择可用性>备份和恢复>执行恢复。
在用户定向恢复部分,在恢复范围菜单中选择Datafiles,然后选择“恢复到当前时间”。
单击“添加”以选择需要恢复的所有数据文件。
指定是否要将文件恢复到默认位置,或者(如果缺少磁盘或控制器)恢复到新位置。
提交RMAN作业以恢复和恢复丢失的文件。
打开数据库。恢复到最后一次提交时为止。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)