oracle异机恢复
前提
源主机信息
版本: oracle 11g
实例: orcl
端口: 1521
备份内容:
- 数据文件
- 控制文件
- 启动文件
- 归档日志
备份控制文件trace : alter database backup controlfile to trace as "/backup/contro.trace";
备份文件:
- /backup/
- initorcl.ora
- dataFile
- arch_h3133g3o_1_1_ORCL_20220720_1110556792
- arch_h4133g3o_1_1_ORCL_20220720_1110556792
- arch_h5133g4h_1_1_ORCL_20220720_1110556817
- ctl_h6133g4i_1_1_ORCL_20220720_1110556818
- db_data_D-ORCL_I-1615444244_TS-SYSAUX_FNO-2_gv133g3d.dbf
- db_data_D-ORCL_I-1615444244_TS-SYSTEM_FNO-1_h0133g3d.dbf
- db_data_D-ORCL_I-1615444244_TS-UNDOTBS1_FNO-3_h1133g3k.dbf
- db_data_D-ORCL_I-1615444244_TS-USERS_FNO-4_h2133g3k.dbf
恢复主机
版本 oracle 11g
实例: han
端口: 1521
挂载目录:
- /fcdmOracle
- init.ora
- dataFile
- arch_h3133g3o_1_1_ORCL_20220720_1110556792
- arch_h4133g3o_1_1_ORCL_20220720_1110556792
- arch_h5133g4h_1_1_ORCL_20220720_1110556817
- ctl_h6133g4i_1_1_ORCL_20220720_1110556818
- db_data_D-ORCL_I-1615444244_TS-SYSAUX_FNO-2_gv133g3d.dbf
- db_data_D-ORCL_I-1615444244_TS-SYSTEM_FNO-1_h0133g3d.dbf
- db_data_D-ORCL_I-1615444244_TS-UNDOTBS1_FNO-3_h1133g3k.dbf
- db_data_D-ORCL_I-1615444244_TS-USERS_FNO-4_h2133g3k.dbf
流程
目录权限
chown -R oracle:oinstall /fcdmOracle
修改启动文件
// 拷贝启动文件到目录
cp /fcdmOracle/init.ora $ORACLE_HOME/dbs/inithan.ora
vim $ORACLE_HOME/dbs/inithan.ora
han.__db_cache_size=1811939328
han.__java_pool_size=33554432
han.__large_pool_size=50331648
han.__oracle_base='/opt/app/oracle'#ORACLE_BASE set from environment
han.__pga_aggregate_target=822083584
han.__sga_target=2466250752
han.__shared_io_pool_size=0
han.__shared_pool_size=536870912
han.__streams_pool_size=0
*.audit_file_dest='/opt/app/oracle/admin/han/adump'
*.audit_trail='db'
*.compatible='11.2.0.4.0'
*.control_files='/opt/app/oracle/oradata/han/control01.ctl','/opt/app/oracle/fast_recovery_area/han/control02.ctl'
*.db_block_size=8192
*.db_domain=''
*.db_name='orcl'
*.db_recovery_file_dest='/opt/app/oracle/fast_recovery_area'
*.db_recovery_file_dest_size=4385144832
*.diagnostic_dest='/opt/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=orcltestXDB)'
*.open_cursors=300
*.pga_aggregate_target=819986432
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.sga_target=2459959296
*.undo_tablespace='UNDOTBS1'
/// 注意 开始db_name 先别转换
创建目录
# echo $ORACLE_BASE
mkdir -p $ORACLE_BASE/admin/han/adump
mkdir -p $ORACLE_BASE/oradata/han/
mkdir -p $ORACLE_BASE/fast_recovery_area/han
启动数据库到mount状态
su - oracle
export ORACLE_SID=han
sqlplus / as sysdba
startup nomount;
恢复控制文件
su - oracle
export ORACLE_SID=han
rman target /
restore controlfile from '/fcdmOracle/dataFile/ctl_ii13raoi_1_1_ORCL_20220729_1111337746';
alter database mount;
# 查看备份集
crosscheck backup;
# 注册备份集
catalog start with '/fcdmOracle/dataFile';
# 删除无效备份
-- 删除无效的备份信息
list backup;
list copy;
CROSSCHECK COPY;
CROSSCHECK BACKUP;
report obsolete;
delete expired copy;
delete expired BACKUP;
list backup;
list copy;
report schema;
修改redo文件
su - oracle
sqlplus / as sysdba
set linesize 400 pagesize 1000
col MEMBER for a60
select member from v$logfile;
select 'alter database rename file '||chr(39)||member||chr(39)||' to ' ||chr(39)|| '/fcdmOracle/han'||substr(member,instr(member,'/',-1))||chr(39)|| ';' RENAME_REDO_FILE from v$logfile;
使用源库的全备进行恢复
su - oracle
export ORACLE_SID=han
rman target /
switch database to copy;
exit;
修改数据库名
vim $ORACLE_HOME/dbs/inithan.ora
修改数据库名为新名称
db_name='han'
生成新实例的控制文件
export ORACLE_SID=han
sqlplus / as sysdba
shutdown immediate;
startup nomount;
-- 根据源库的信息重新创建控制文件 (重建控制文件,如下一定要使用SET DATABASE参数 )
CREATE CONTROLFILE REUSE SET DATABASE "han" RESETLOGS ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 '/fcdmOracle/oradata/han/redo01.log' SIZE 50M BLOCKSIZE 512,
GROUP 2 '/fcdmOracle/oradata/han/redo02.log' SIZE 50M BLOCKSIZE 512,
GROUP 3 '/fcdmOracle/oradata/han/redo03.log' SIZE 50M BLOCKSIZE 512
DATAFILE
'/fcdmOracle/dataFile/db_data_D-ORCL_I-1615444244_TS-SYSAUX_FNO-2_ib13ranf.dbf',
'/fcdmOracle/dataFile/db_data_D-ORCL_I-1615444244_TS-SYSTEM_FNO-1_ic13ranf.dbf',
'/fcdmOracle/dataFile/db_data_D-ORCL_I-1615444244_TS-UNDOTBS1_FNO-3_id13rann.dbf',
'/fcdmOracle/dataFile/db_data_D-ORCL_I-1615444244_TS-USERS_FNO-4_ie13ranp.dbf'
CHARACTER SET AL32UTF8;
// 创建完成后已经mount
alter database mount;
#在新实例生成新的redo日志组
// 创建路径
mkdir -p /fcdmOracle/oradata/han/
alter database clear logfile group 1;
alter database clear logfile group 2;
alter database clear logfile group 3;
对目标库进行recover新实例恢复数据库,由于控制文件重建之后没有任何信息,需要重新注册catalog 才能进行数据的recover
rman target /
catalog start with '/fcdmOracle/dataFile';
recover database until SCN 6430800;
exit;
打开resetlogs
export ORACLE_SID=han
sqlplus / as sysdba
alter database open resetlogs;
创建临时表空间
select * from v$tempfile;
alter tablespace temp add tempfile '/fcdmOracle/dataFile/temp01.dbf' size 200m autoextend on next 10m maxsize 10g;
select name from v$datafile;
为新实例数据库创建spfile
create spfile from pfile;
select name from v$datafile;
shutdown immediate;
startup;
修改监听文件
vim
# tnsnames.ora Network Configuration File: /opt/app/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.
TEST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = providerBack)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = han)
)
)
test = (DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.110.72)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = han)
)
)