最近一直在忙于写shell脚本,忽略了oracle的基础的回顾,正好做了个rman的恢复,记录一下加深印象!
oracle全库备份的理想状态下在mount时做全备,这样不需要去做考虑一致性问题。仅仅是理想而已。
将数据库开为归档模式下,进行全备,脚本如下
log_file=/paic/hq/bk/restore/home/op11202/xionglang/investdw/full_backup_${ORACLE_SID}_`date '+%Y%m%d_%H%M%S'`.log
export log_file
rman target / << EOF > ${log_file} 2>&1
sql 'alter system switch logfile';
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;
allocate channel c8 type disk;
BACKUP as compressed backupset full DATABASE plus archivelog FORMAT '/paic/hq/bk/restore/home/op11202/xionglang/investdw/full_%T-%d-%u-%p' filesperset=10;
backup as copy current controlfile format '/paic/hq/bk/restore/home/op11202/xionglang/investdw/ctrl_%t-%s-%p.f';
release channel c1;
release channel c2;
release channel c3;
release channel c4;
release channel c5;
release channel c6;
release channel c7;
release channel c8;
}
EOF
echo "Backup finished at `date '+%Y%m%d_%H%M%S'`" >> ${log_file}
1.生成一份原开发/测试库的pfile
2.利用步骤1中的pfile,启动到nomount
3.rman target /
RMAN> Restore controlfile from ‘/xxxx/xxxx/*****.f’; /xxxx/xxxx/*****.f为生产dg库的controlfile的备份
RMAN> Alter database mount;
RMAN> Catalog start with ‘/xxxx/xxxx/’; 注册备份片到恢复出来的控制文件里
4.后台执行如下restore脚本。如果恢复出来了归档日志restore database之后需要recover database;
(注意incarnation相关报错)
5.恢复完成以后,shutdown实例,修改pfile里的db_name为原测试库SID 启动到nomount
6.使用create controlfile set database 命令重建控制文件
7.alter database open resetlogs;
8.添加临时文件
恢复脚本:
log_file=/paic/dev/oracle/11g/odsz11g/xionglang/xionglang/d1gccrep/restore_${ORACLE_SID}_`date '+%Y%m%d_%H%M%S'`.log
export log_file
rman target / << EOF > ${log_file} 2>&1
run
{
allocate channel c1 type disk ;
allocate channel c2 type disk