正式环境备份脚本:
https://app.yinxiang.com/fx/c88c06c9-d5fb-41fb-8be4-6abffe302d2f
由于我们正式环境没有保存归档日志,在还原之前我们需要先执行以下脚本:
run
{
allocate channel d2 type disk;
backup archivelog from time 'sysdate-3' format '/opt/backups/oracle/rman_bak/arch_%I_%T_%u';
delete noprompt obsolete device type disk;
crosscheck backup;
delete noprompt expired backup;
release channel d2;
}
接着查询一下备份文件列表,找到最后一次全量备份和归档日志的存储路径:
RMAN>backup list;
复制一份spfile.ora文件到目标机器
SQL> create pfile='/opt/app/oracle/product/12.2.0.1/dbhome_1/dbs/initorcl.ora' from spfile='/opt/app/oracle/product/12.2.0.1/dbhome_1/dbs/spfileorcl.ora';
修改ora文件里面的信息,主要是路径修改成目标机器上的路径,需要注释掉local_listener
查询控制文件备份
RMAN> LIST BACKUP OF CONTROLFILE;
开始在目标库中恢复备份
设置数据库
export ORACLE_SID=orcl
登录rman
rman target /
设置dbid
–DBID的值可以登录主库的 RMAN 查看到,也可以在 RMAN 的 CONTROLFILE AUTO BACKUP 生成的文件名中看到
RMAN> SET DBID 1554704928;
RMAN> STARTUP FORCE NOMOUNT PFILE='/opt/app/oracle/product/12.2.0.1/dbhome_1/dbs/initorcl.ora';
恢复控制文件
RMAN> restore controlfile from '/opt/backups/oracle-32/rman_bak/orcl/fhv52taa';
RMAN> ALTER DATABASE MOUNT;
// 删除过期备份
RMAN> crosscheck backup;
RMAN> delete noprompt expired backup;
RMAN> catalog start with '/opt/backups/oracle-32/rman_bak/orcl';
RMAN> restore database;
Starting restore at 15-JUL-20
using channel ORA_DISK_1
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of restore command at 07/15/2020 10:10:48
RMAN-06026: some targets not found - aborting restore
RMAN-06023: no backup or copy of datafile 11 found to restore
RMAN-06023: no backup or copy of datafile 10 found to restore
RMAN-06023: no backup or copy of datafile 9 found to restore
RMAN-06023: no backup or copy of datafile 8 found to restore
RMAN-06023: no backup or copy of datafile 6 found to restore
RMAN-06023: no backup or copy of datafile 5 found to restore
发现报错了,是由于没有数据库文件导致的,我们再去正式环境把数据库文件拷过来,再执行以下代码
run
{
set newname for datafile 1 to "/opt/app/oracle/oradata/orcl/o1_mf_system_gz6movgp_.dbf";
set newname for datafile 3 to "/opt/app/oracle/oradata/orcl/o1_mf_sysaux_gz6mpyno_.dbf";
set newname for datafile 4 to "/opt/app/oracle/oradata/orcl/o1_mf_undotbs1_gz6mqqsh_.dbf";
set newname for datafile 5 to "/opt/app/oracle/oradata/orcl/o1_mf_system_gz6ms8v3_.dbf";
set newname for datafile 6 to "/opt/app/oracle/oradata/orcl/o1_mf_sysaux_gz6ms8v2_.dbf";
set newname for datafile 7 to "/opt/app/oracle/oradata/orcl/o1_mf_users_gz6mqrx0_.dbf";
set newname for datafile 8 to "/opt/app/oracle/oradata/orcl/o1_mf_undotbs1_gz6ms8v4_.dbf";
set newname for datafile 9 to "/opt/app/oracle/oradata/orcl/o1_mf_system_gz6mzs5l_.dbf";
set newname for datafile 10 to "/opt/app/oracle/oradata/orcl/o1_mf_sysaux_gz6mzs5q_.dbf";
set newname for datafile 11 to "/opt/app/oracle/oradata/orcl/o1_mf_undotbs1_gz6mzs5r_.dbf";
set newname for datafile 12 to "/opt/app/oracle/oradata/orcl/o1_mf_users_gz6mzz3h_.dbf";
set newname for datafile 13 to "/opt/app/oracle/oradata/orcl/zyscm.dbf";
set newname for datafile 14 to "/opt/app/oracle/oradata/orcl/PDB/zyscm.dbf";
restore database ;
switch datafile all;
}
如果还不行的话,就把缺少的那些文件的备份也拷贝一份过来
执行介质恢复,先查询我们要恢复的备份的scn
RMAN> list backup of archivelog all;
或者使用list backup查询当前备份scn
RMAN> recover database until scn 70232764;
Starting recover at 15-JUL-20
using channel ORA_DISK_1
starting media recovery
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 07/15/2020 10:35:05
RMAN-06053: unable to perform media recovery because of missing log
RMAN-06025: no backup of archived log for thread 1 with sequence 3185 and starting SCN of 69948688 found to restore
RMAN-06025: no backup of archived log for thread 1 with sequence 3184 and starting SCN of 69898993 found to restore
RMAN-06025: no backup of archived log for thread 1 with sequence 3183 and starting SCN of 69863733 found to restore
RMAN-06025: no backup of archived log for thread 1 with sequence 3182 and starting SCN of 69816104 found to restore
RMAN-06025: no backup of archived log for thread 1 with sequence 3181 and starting SCN of 69766497 found to restore
RMAN-06025: no backup of archived log for thread 1 with sequence 3180 and starting SCN of 69739203 found to restore
RMAN-06025: no backup of archived log for thread 1 with sequence 3179 and starting SCN of 69705005 found to restore
RMAN-06025: no backup of archived log for thread 1 with sequence 3178 and starting SCN of 69665012 found to restore
RMAN-06025: no backup of archived log for thread 1 with sequence 3177 and starting SCN of 69645672 found to restore
RMAN-06025: no backup of archived log for thread 1 with sequence 3176 and starting SCN of 69640803 found to restore
RMAN-06025: no backup of archived log for thread 1 with sequence 3175 and starting SCN of 69640598 found to restore
RMAN-06025: no backup of archived log for thread 1 with sequence 3174 and starting SCN of 69640351 found to restore
RMAN-06025: no backup of archived log for thread 1 with sequence 3173 and starting SCN of 69640071 found to restore
RMAN-06025: no backup of archived log for thread 1 with sequence 3172 and starting SCN of 69639853 found to restore
RMAN-06025: no backup of archived log for thread 1 with sequence 3171 and starting SCN of 69633188 found to restore
RMAN-06025: no backup of archived log for thread 1 with sequence 3170 and starting SCN of 69617482 found to restore
RMAN-06025: no backup of archived log for thread 1 with sequence 3169 and starting SCN of 69598944 found to restore
RMAN-06025: no backup of archived log for thread 1 with sequence 3168 and starting SCN of 69575736 found to restore
RMAN-06025: no backup of archived log for thread 1 with sequence 3167 and starting SCN of 69502761 found to restore
RMAN-06025: no backup of archived log for thread 1 with sequence 3166 and starting SCN of 69433808 found to restore
RMAN-06025: no backup of archived log for thread 1 with sequence 3165 and starting SCN of 69380765 found to restore
RMAN-06025: no backup of archived log for thread 1 with sequence 3164 and starting SCN of 69344636 found to restore
RMAN-06025: no backup of archived log for thread 1 with sequence 3163 and starting SCN of 69315987 found to restore
RMAN-06025: no backup of archived log for thread 1 with sequence 3162 and starting SCN of 69298260 found to restore
RMAN-06025: no backup of archived log for thread 1 with sequence 3161 and starting SCN of 69298040 found to restore
RMAN-06025: no backup of archived log for thread 1 with sequence 3160 and starting SCN of 69297802 found to restore
RMAN-06025: no backup of archived log for thread 1 with sequence 3159 and starting SCN of 69297538 found to restore
又发现报错,这里我查到是缺少archived文件,我们再从源机器上copy一份过来
正式环境的文件在
/u01/oracle/fast_recovery_area/orcl/ORCL/archivelog
目录下,仔细看下缺少哪些文件copy过来就行了
select group#, sequence#, bytes, members, status from v$log;
这是查询当前使用的log的seq的sql
然后就可以了,如果不行,就删掉控制文件,把上面的流程再执行一遍
RMAN> recover database until scn 70232764;
Starting recover at 15-JUL-20
using channel ORA_DISK_1
starting media recovery
media recovery complete, elapsed time: 00:00:01
Finished recover at 15-JUL-20
RMAN> alter database open resetlogs;
参考文件
http://blog.itpub.net/26506993/viewspace-1873417/
https://dbatricksworld.com/rman-06026-some-targets-not-found-aborting-restore-rman-06023-no-backup-or-copy-of-datafile-x-found-to-restore/