暂无图片
暂无图片
9
暂无图片
暂无图片
暂无图片

Oracle RAC 12.2 CDB rman备份异机恢复到12.2单实例环境

原创 柚子身上依 2024-04-22
1330

适用范围

建议 12.2.0.1 及以上版本使用

方案概述

Oracle rac 12.2 cdb环境的rman备份需要恢复到12.2单实例环境上进行测试使用,不完全恢复即可,备份在源端和目标端都配置了共享nfs,挂载的路径分别为/rac/rman/test1和/baktmp/rman/test1。源端每周日进行0级全量备份,周一到周六进行1级增量备份

实施步骤

1.查看备份脚本

– 全量备份脚本

$ cat rman_0_level_full.sh
#!/bin/sh
source /home/oracle/.bash_profile
export ORACLE_SID=test1
DAY_TAG=`date +"%Y-%m-%d"`
backdir1=/rac/rman/test1
rman target / nocatalog msglog /rac/rman/test1/log/fullback_$DAY_TAG.log<<EOF
run{
crosscheck backup;
delete noprompt expired backup;
allocate channel d1 type disk;
allocate channel d2 type disk;
allocate channel d3 type disk;
allocate channel d4 type disk;
allocate channel d5 type disk;
allocate channel d6 type disk;
#crosscheck archivelog all;
#delete noprompt expired archivelog all;
#crosscheck backup;
#delete noprompt expired backup;
backup incremental level 0 as compressed backupset database format '$backdir1/full_%d_%T_%t_%s_%p';
sql 'alter system archive log current';
backup as compressed backupset filesperset 10 format '$backdir1/arch_%d_%T_%t_%s_%p' archivelog all delete all input;
backup current controlfile format '$backdir1/ctl_%d_%T_%t_%s_%p';
release channel d1;
release channel d2;
release channel d3;
release channel d4;
release channel d5;
release channel d6;
#report obsolete;
delete noprompt obsolete;
}
EOF

– 增量备份脚本

$ cat rman_1_level_incremental.sh
#!/bin/sh
source /home/oracle/.bash_profile
export ORACLE_SID=test1
DAY_TAG=`date +"%Y-%m-%d"`
backdir1=/rac/rman/test1
rman target / nocatalog msglog /rac/rman/test1/log/inc_back_$DAY_TAG.log<<EOF
run{
crosscheck backup;
delete noprompt expired backup;
allocate channel d1 type disk;
allocate channel d2 type disk;
allocate channel d3 type disk;
allocate channel d4 type disk;
allocate channel d5 type disk;
allocate channel d6 type disk;
#crosscheck archivelog all;
#delete noprompt expired archivelog all;
#crosscheck backup;
#delete noprompt expired backup;
backup incremental level 1 as compressed backupset database format '$backdir1/inc_%d_%T_%t_%s_%p';
sql 'alter system archive log current';
backup as compressed backupset filesperset 10 format '$backdir1/arch_%d_%T_%t_%s_%p' archivelog all delete all input;
backup current controlfile format '$backdir1/ctl_%d_%T_%t_%s_%p';
release channel d1;
release channel d2;
release channel d3;
release channel d4;
release channel d5;
release channel d6;
#report obsolete;
#delete noprompt obsolete;
}
EOF

2.异机恢复

12.2.0.1 软件已经存在不需要安装

2.1.授予备份文件相关权限及创建相关目录

# cd /baktmp/rman/test1
# chmod 777 *20240407* *20240408*
# mkdir -p /data/test/tempfile
# mkdir -p /data/test/datafile
# mkdir -p /data/test/onlinelog/
# chown oracle.dba -R /data/test

2.2.创建参数文件并启动到nomount

$ cat inittest.ora
db_name=test
shared_pool_size=5368709120
compatible='12.2.0.1.0'
enable_pluggable_database=true

启动到nomount

$ export ORACLE_SID=test
$ sqlplus / as sysdba
SQL> startup nomount;

2.3.恢复控制文件

$ rman target /
RMAN> restore controlfile from  '/baktmp/rman/TEST1/ctl_TEST_20240408_1165174769_27019_1';
RMAN> alter database mount;

2.4.catalog备份\检查备份\删除无效备份

RMAN> catalog start with '/baktmp/rman/test1';
RMAN> crosscheck backup;
RMAN> delete noprompt expired backup;

2.4.恢复数据文件

$ cat restore.sh
#!/bin/sh
rman target / log=/home/oracle/rman_restore.log <<EOF
run{
allocate channel c1 type disk;
allocate channel c2 type disk;
allocate channel c3 type disk;
allocate channel c4 type disk;
allocate channel c5 type disk;
allocate channel c6 type disk;
allocate channel c7 type disk;
set newname for database to '/data/test/datafile/%U';
restore database;
switch datafile all;
recover database;
release channel c1;
release channel c2;
release channel c3;
release channel c4;
release channel c5;
release channel c6;
release channel c7;
}
exit
EOF

进行恢复

nohup sh restore.sh &

2.5.重命名tempfile

tempfile可以通过rman脚本直接修改

run{
set newname for database to '/data/test/tempfile/%U';
switch tempfile all;
}

或者生成rename的sql文本进行修改

 select 'alter database rename file '''||name||''' to '''||'/data/test/tempfile/'|substr(name,instr(name,'temp'))||''';' r_tempfile from v$tempfile;

2.6.redo file 调整

生成rename的sql文本进行修改

select 'alter database rename file '''||member||''' to '''||'/data/test/onlinelog/'||substr(member,instr(member,'group_'))||''';' r_redofile from v$logfile;

上面sql拼接生成的rename的文本,可以拿过来执行进行rename操作

2.7.不完全恢复resetlogs启库

$ sqlplus / as sysdba
SQL> alter database open resetlogs;

2.8.删除thread 2 redo log

$ sqlplus / as sysdba
SQL> alter database disable thread 2;
SQL> alter database drop logfile group 5;
SQL> alter database drop logfile group 6;
SQL> alter database drop logfile group 7;
SQL> alter database drop logfile group 9;

2.9.启动监听并注册本地监听

$ lsnrctl start
$ sqlplus / as sysdba
SQL> alter system set local_listener='(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.10.8)(PORT=1521))';
SQL> alter system register;

2.10.修改max_string_size为extend

$ sqlplus / as sysdba
SQL> alter system set max_string_size = extended scope=spile;
SQL> shut immeidate;
SQL> startup;
SQL> alter pluggable database all open;
SQL> alter pluggable database all save state;

3.遇到问题

3.1.启动nomount报错

startup nomount pfile='/data/oracle/product/12.2.0.1/dbhome_1/dbs/inittest.ora';
ORA-00371: not enough shared pool memory, should be at least 503735201 bytes

inittest.ora参数文件添加shared_pool_size=5368709120 后重启到nomount

shared_pool_size=5368709120

3.2.权限不足无法找到备份文件

RMAN> restore controlfile from  '/baktmp/rman/TEST1/ctl_TEST_20240408_1165174769_27019_1';

Starting restore at 08-APR-24
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=633 device type=DISK

RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of restore command at 04/08/2024 15:53:41
RMAN-06172: no AUTOBACKUP found or specified handle is not a valid copy or piece

RMAN> 

赋权限解决

# cd /baktmp/rman/test1
# chmod 777 *20240407* *20240408*

3.3.ORA-00723

RMAN> alter database mount;

RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of sql statement command at 04/08/2024 16:39:38
ORA-00723: Initialization parameter COMPATIBLE must be explicitly set

inittest.ora参数文件添加compatible=‘12.2.0.1.0’ 后重启到mount

compatible='12.2.0.1.0'

3.4.ORA-65093

SQL> startup mount;
ORACLE instance started.

Total System Global Area 5536480720 bytes
Fixed Size                   19525072 bytes
Variable Size                 5435817984 bytes
Database Buffers           67108864 bytes
Redo Buffers                   14028800 bytes
ORA-65093: multitenant container database not set up properly

inittest.ora参数文件添加enable_pluggable_database=true 后重启到mount

enable_pluggable_database=true

3.5.恢复日志中找备份文件先报错后failover路径成功

channel c4: errors found reading piece handle=/rac/rman/test1/full_TEST_20240407_1165096836_27003_1
channel c4: failover to piece handle=/baktmp/rman/test1/full_TEST_20240407_1165096836_27003_1 tag=TAG20240407T220049
channel c4: restored backup piece 1
channel c4: restore complete, elapsed time: 03:49:23

恢复之前执行crosscheck可以解决此报错

RMAN> crosscheck backup;

3.6.启动pdb报错

ORA-14694: database must in UPGRADE mode to begin MAX_STRING_SIZE migration

由于rman恢复的时候备份集中已经包含utl32k.sql脚本的结果了,所以只需要修改 max_string_size 参数为extended后重启即可,参数默认值是standard

$ sqlplus / as sysdba
SQL> alter system set max_string_size = extended scope=spile;
SQL> shut immeidate;
SQL> startup;
SQL> alter pluggable database all open;

4.其他说明

CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 60 DAYS;

rman保留备份60天的策略对于pdbseed不适用,目前发现每次全量备份完毕会删除上次全备份生成的pdbseed备份片,可能和pdb$seed是read only的有关,具体没细究

最后修改时间:2024-05-08 08:49:47
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论