RMAN整机详细恢复
- 从主机整机恢复至备机(基本信息及配置)
主备机都为11.2.0.4 实例名都是tytest
备机oracle安装目录与主机不同,所有相关文件位置包括oradata等均不相同
备机只需要装oracle
主机pfile里涉及到的目录备机都要有可以位置不一样
mkdir -p $ORACLE_HOME/cfgtoollogs/dbca/tbcdmp
mkdir -p $ORACLE_BASE/admin/tbcdmp/adump
mkdir -p $ORACLE_BASE/admin/tbcdmp/bdump
mkdir -p $ORACLE_BASE/admin/tbcdmp/cdump
mkdir -p $ORACLE_BASE/admin/tbcdmp/dpdump
mkdir -p $ORACLE_BASE/admin/tbcdmp/pfile
mkdir -p $ORACLE_BASE/admin/tbcdmp/udump
mkdir -p $ORACLE_BASE/flash_recovery_area
tytest.__db_cache_size=356515840
tytest.__java_pool_size=4194304
tytest.__large_pool_size=8388608
tytest.__oracle_base=’/Data/oracle’#ORACLE_BASE set from environment
tytest.__pga_aggregate_target=272629760
tytest.__sga_target=511705088
tytest.__shared_io_pool_size=0
tytest.__shared_pool_size=130023424
tytest.__streams_pool_size=0
*.audit_file_dest=’/Data/oracle/admin/tytest/adump’
*.audit_trail=‘DB_EXTENDED’
*.compatible=‘11.2.0.4.0’
*.control_files=’/Data/oracle/oradata/tytest/control01.ctl’,’/Data/oracle/fast_recovery_area/tytest/control02.ctl’
*.db_block_size=8192
*.db_domain=’’
*.db_name=‘tytest’
*.db_recovery_file_dest=’/Data/oracle/fast_recovery_area’
*.db_recovery_file_dest_size=4385144832
*.diagnostic_dest=’/Data/oracle’
*.dispatchers=’(PROTOCOL=TCP) (SERVICE=tytestXDB)’
*.memory_target=783286272
*.nls_date_format=‘yyyy-mm-dd hh24:mi:ss’
*.open_cursors=300
*.pga_aggregate_target=272629760
*.processes=150
*.remote_login_passwordfile=‘EXCLUSIVE’
*.sga_max_size=511705088
*.sga_target=511705088
*.standby_file_management=‘AUTO’
*.undo_tablespace=‘UNDOTBS2’
-
目标端生成spfile文件并将数据库开启至nomount
sqlplus / as sysdba
SQL> create spfile from pfile;
SQL> startup nomount -
将源端全备出来的rman文件全部传过来
rman target /
run{
allocate channel t1 type disk; --开启四个通道
allocate channel t2 type disk;
allocate channel t3 type disk;
allocate channel t4 type disk;
crosscheck archivelog all;
sql ‘alter system checkpoint’; --执行checkpoint和归档的原因是怕源端数据在redolog里没有释放导致recover时找不到Medio
sql ’ alter system switch logfile’;
sql ‘alter system archive log current’;
backup database format ‘/Data/test/tytest_%U.bak’;
sql ‘alter system checkpoint’;
sql ’ alter system switch logfile’;
sql ‘alter system archive log current’;
backup current controlfile format ‘/Data/test/ctl_%d_%T_%U’;
crosscheck archivelog all;
release channel t1; --关闭四个通道
release channel t2;
release channel t3;
release channel t4;
}
scp * oracle@10.76.17.117:/Data/test --将备份出来的信息传到目标库的存放地址
- 目标端恢复控制文件
先在主库查出DBID
rman target /
Recovery Manager: Release 11.2.0.4.0 - Production on Thu Jun 18 09:34:00 2020
Copyright © 1982, 2011, Oracle and/or its affiliates. All rights reserved.
connected to target database: TYTEST (DBID=124402371)
目标端rman target /
RMAN> set dbid=124402371;
恢复controlfile 控制文件
(*.control_files=’/Data/oracle/oradata/tytest/control01.ctl’,’/Data/oracle/fast_recovery_area/tytest/control02.ctl’) --目标端pfile里关于controlfile存放的信息
run
{
sql “alter session set nls_date_format=’‘yyyymmdd hh24:mi:ss’’”;
allocate channel ‘ch1’ type disk;
restore controlfile from ‘/Data/test/ctl_TYTEST_20200618_2ov321i7_1_1’;
release channel ‘ch1’;
}
RMAN> alter database mount; --控制文件恢复成功后将数据库mount状态
CATALOG 备份信息 CONTROLFILE
RMAN>catalog start with ‘/Data/test/’ --catalog目标端备份文件
5. 恢复数据文件
set newname for datafile ‘/oracle/oradata/tytest/users01.dbf’ (源端数据文集位置)
to ‘/postgres/oradata/system01.dbf’(目标端计划放置位置);
run{
allocate channel c1 type disk ;
allocate channel c2 type disk ;
allocate channel c3 type disk ;
allocate channel c4 type disk ;
set newname for datafile ‘/oracle/oradata/tytest/users01.dbf’ to ‘/postgres/oradata/system01.dbf’;
set newname for datafile ‘/Data/oradata/tytest/sysaux01.dbf’ to ‘/postgres/oradata/undotbs01.dbf’;
set newname for datafile ‘/oracle/oradata/tytest/system01.dbf’ to ‘/postgres/oradata/sysaux01.dbf’;
set newname for datafile ‘/Data/oradata/tytest/D_DB_DATA01.dbdf’ to ‘/postgres/oradata/users01.dbf’;
set newname for datafile ‘/Data/oradata/tytest/sysaux02.dbf’ to ‘/postgres/oradata/I_R_WIP_KEYPARTS_T01.dbf’;
set newname for datafile ‘/Data/oradata/tytest/system02.dbf’ to ‘/postgres/oradata/I_RP10WEB_DATA01.dbf’;
set newname for datafile ‘/Data/oradata/tytest/UNDOTBS1.dbf’ to ‘/postgres/oradata/I_RP10_CSFIS01.dbf’;
restore database;
switch datafile all; —switch上面所有的文件在新的datafile里
release channel c1;
release channel c2;
release channel c3;
release channel c4;
}
- 恢复了之后修改temporary file和online redo log file位置
alter database rename file ‘/oracle/oradata/tytest/temp01.dbf’ to ‘/Data/oradata/tytest/temp01.dbf’;
alter database rename file ‘/Data/oradata/tytest/temp02.dbf’ to ‘/Data/oradata/tytest/temp02.dbf’;
select * from v$logfile
alter database rename file ‘/oracle/oradata/tytest/redo03.log’ to ‘/Data/oradata/tytest/redo03.log’;
alter database rename file ‘/oracle/oradata/tytest/redo02.log’ to ‘/Data/oradata/tytest/redo02.log’;
alter database rename file ‘/oracle/oradata/tytest/redo01.log’ to ‘/Data/oradata/tytest/redo01.log’;
-
设置目标端归档目录
SQL> alter system set log_archive_dest_1=‘location=/Data/archlog’ scope=both;
SQL>shutdown immediate
SQL>startup mount;
SQL>alter database archivelog; -
恢复归档日志
查询至回复前最大的seq 号
select * from v$archived_log 查询最大的号 2193
把主库check point后的归档日志全部copy到备机
之后在rman里执行 catalog start with ‘/Data/archlog/’;
rman>recover database until sequence 2194;
不够的归档要从主机里copy过来
rman>
recover database using backup controlfile;
- alter database open resetlogs;
注:TEMP表空间和redolog是不需要专门恢复的,系统好了自动就能生成,大小和之前数据库的一样
- 建立监听