Oracle RMAN异机迁移恢复
介绍
RMAN备份异机恢复几点说明:
(1)RMAN异机恢复的时候,db name必须相同。
(2)如果恢复的路径和源库不一致,就需要在restorel时用set命令指定新位置。
准备异机恢复环境
安装的测试数据库 ORACLE 数据库软件并创建跟源数据库同名和数据库 SID 并修改数据库 DBID 跟源数据库 DBID 一样,
创建跟源数据库服务器相同的数据文件目录、日志文件目录、控制文件目录。
从生产库上全备文件复制到目录库
恢复数据库需要准备的文件:rman 完整备份(包括数据文件、日志文件、控制文件、 参数文件),记录源数据库的 DBID
总结步骤:
1,scp 全备文件到测试库,在备份库上查询好参数文件控制文件归档路径等信息
2,关闭测试库,启动到 nomount 状态,恢复参数文件控制文件
3,启动到 mount 状态,restore、recover 操作
4,打开数据库 alter database open resetlogs;
步骤
生产库:
模拟数据
conn hfedu01/hfedu01
create table hfedu001 (id number(10),name varchar2(10));
insert into hfedu001 values(1,‘hfedu01’);
insert into hfedu001 values(2,‘hfedu02’);
insert into hfedu001 values(3,‘hfedu03’);
insert into hfedu001 values(4,‘hfedu04’);
insert into hfedu001 values(5,‘hfedu05’);
commit;
alter system switch logfile;
alter system checkpoint;
archive log list
select * from hfedu01.hfedu001;
使用rman备份数据库
mkdir /backup/full
rman target /
backup tag hfedu7full format ‘/backup/full/hfedu7_full_fgzcdb_%s_%p_%t’ (database);
backup tag hfedu7ctl format ‘/backup/full/hfedu7_ctl_fgzcdb_%s_%p_%t’ (current controlfile);
backup tag itpux7pfile format ‘/backup/full/hfedu7_pfile_fgzcdb_%s_%p_%t’ (spfile);
记录数据库的bbid
sqlplus / as sysdba
select name ,dbid from v$database; --[bbid= 797496974]
set time on
21:28:00 SYS@hfzcdb> --记录时间
drop table hfedu01.hfedu001;
alter system switch logfile;
alter system checkpoint;
拷贝备份到还原库
scp -r full 172.30.21.98:/backup/
还原库
创建目录,最好是创建同样路径目录
mkdir -p /oradata/hfzcdb
chown -R oracle:dba /oradata/hfzcdb
chmod -R 775 /oradata
mkdir /archive
chown -R oracle:dba /archive
chmod -R 775 /archive
创建数据库目录
su - oracle
mkdir -p /oracle/app/oracle/admin/hfzcdb/adump
mkdir -p /oracle/app/oracle/admin/hfzcdb/dpdump
mkdir -p /oracle/app/oracle/admin/hfzcdb/pfile
mkdir -p /oracle/app/oracle/admin/hfzcdb/scripts
mkdir -p /backup/full
chown -R oracle:dba /oracle/app/oracle/admin/hfzcdb
chmod 775 /oracle/app/oracle/admin/hfzcdb
设置环境变量
export ORACLE_SID=hfzcdb
恢复参数文件
rman target /
startup nomount
set dbid=797496974
restore spfile from '/backup/full/hfedu7_pfile_fgzcdb_5_1_1133213159';
恢复控制文件,恢复数据库
RMAN> shutdown immediate
export ORACLE_SID=hfzcdb
sqlplus / as sysdba
startup nomount;
SQL> show parameter control;
NAME TYPE VALUE\------------------------------
control_file_record_keep_time integer 7
control_files string /oradata/hfzcdb/control01.ctl, /oradata/hfzcdb/control02.ctl
control_management_pack_access string DIAGNOSTIC+TUNING
rman target /
restore controlfile from '/backup/full/hfedu7_ctl_fgzcdb_3_1_1133213110';
恢复数据库
RMAN> alter database mount;
RMAN> restore database;
RMAN> run
{
set until time='2023-04-03 21:28:00';
recover database;
}
--unable to find archived log
--archived log thread=1 sequence=21
--RMAN-00571: ===========================================================
--RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
--RMAN-00571: ===========================================================
--RMAN-03002: failure of recover command at 04/03/2023 21:49:32
--RMAN-06054: media recovery requesting unknown archived log for thread 1 with sequence 21 and starting SCN of 1417139
#mkdir -p /archive/HFZCDB/archivelog/2023_04_03
生产库:
cd /archive/HFZCDB/archivelog/2023_04_03/
scp o1_mf_1_21_l2oo4nfm_.arc 172.30.21.98:$PWD
还原库:
rman target /run
{
set until time='2023-04-03 21:28:00';
recover database;
}
打开数据库
export ORACLE_SID=hfzcdb
sqlplus / as sysdba
alter database open resetlogs;
select * from hfedu01.hfedu001;
使用exp导出数据,进行增量恢复
源库
cd /backup/
exp hfedu01/hfedu01 file=hfedu01.dmp log=hfedu01.log tables=hfedu001
scp hfedu01.* 172.30.21.191:/backup/
生产库:
cd /backup/
imp hfedu01/hfedu01 file=hfedu01.dmp full=yes
sqlplus / as sysdba
select * from hfedu01.hfedu001;
–结束*/