+ -
当前位置:首页 → 问答吧 → 重建物理备库案例两则

重建物理备库案例两则

时间:2011-09-07

来源:互联网

上周末两个生产库的物理备库都出现了问题,周末分别重建了一把,两库出的问题一样,创建的方法也不同,以下是详细信息;

场景1
备库b上的监控脚本失效,从7月8号就开始与主库不一致,直到上周末才发现;查看alertlog,发现archive gap相差很多,且很多在主库上都已不存在,考虑主库数据更新比较频繁,决定重新创建备库;
但是主库server磁盘容量有限,此时只剩200g左右,而数据库大小有600g,使用rman备份来创建备库不太合适,于是采用rman的copy命令替代;
具体方法为:对主库中的数据文件,先使用copy命令将其放到磁盘上,然后scp传输至备库,接着删除磁盘上的copy以腾出磁盘空间,重复这一步骤,直到所有文件都传输至备库为止;
使用pl/sql生成相应脚本
declare
begin
  dbms_output.put_line('rman target / ');
  for i in (select file#,name from v$datafile) loop
    dbms_output.put_line('copy datafile '||i.file#||' to ''/data/oracle/copy/'||substr(i.name,instr(i.name,'/',-1,1)+1)||''';');
    dbms_output.put_line('host ''scp /data/oracle/copy/'||substr(i.name,instr(i.name,'/',-1,1)+1)||' *.*.*.*:/data/oracle/oradata/standby'';');
    dbms_output.put_line('host ''rm /data/oracle/copy/'||substr(i.name,instr(i.name,'/',-1,1)+1)||''';');
  end loop;
end;
/
输出结果如下
rman target /
copy datafile 1 to '/data/oracle/copy/system.dbf';
host 'scp /data/oracle/copy/ system.dbf  *.*.*.*:/data/oracle/oradata/standby';
host 'rm /data/oracle/copy/ system.dbf ';
在主库开一个screen窗口,运行以上命令,传输完毕后即可开始recover备库
注:
1、从copy第一个数据文件起生成的redo log都需要保存完整,备库recover的时候需要用到
2、运行前需要配置主备库的ssh用户等价,否则每次scp都要输入密码;

场景2
生产库上的另一套dataguard系统出现archive gap,有别与第一个案例,虽然相应的日志文件在主库也已不存在,但这次发现时间比较早,备库较之主库只延迟了两天,无须推倒重建,在此采用incremental recover的方式恢复备库。
先确定备库的current scn,以此在主库上执行incremental backup,将备份传至备库,使用recover noredo方式恢复备库
具体步骤为:
1、
查看物理备库的scn
SQL> select to_char(current_scn) from v$database;

TO_CHAR(CURRENT_SCN)
----------------------------------------
20032338311
2、
在主库执行incremental备份
run
{allocate channel d1 type disk;
allocate channel d2 type disk;
allocate channel d3 type disk;
allocate channel d4 type disk;
backup as compressed backupset incremental from SCN 20032338311 database format '/data/oracle/backup/rman/standby_%d_%T_%U.bak'
include current controlfile for standby filesperset=5  tag 'FOR STANDBY';
release channel d1;
release channel d2;
release channel d3;
release channel d4;
}
3、
将备份集传输到备库的/data/oracle/backup/rman目录
4、
RMAN>catalog start with '/data/oracle/backup/rman';
run {
allocate channel dsk0 type disk;
allocate channel dsk1 type disk;
allocate channel dsk2 type disk;
restore standby controlfile to '/u01/app/oracle/control01.ctl';
recover database noredo;
}
5、
关闭standby数据库
将/u01/app/oracle/control01.ctl覆盖现有的控制文件
6、
启动物理备库检查
SQL> startup mount
SQL> select to_char(current_scn) from v$database;

TO_CHAR(CURRENT_SCN)
----------------------------------------
20133423174
SQL> SELECT * FROM V$ARCHIVE_GAP;

no rows selected
为备库增加standby redolog
开启recover进程
SQL> alter database recover managed standby database disconnect from session using current logfile;
然后观察alertlog一段时间,确保不会有错误发生
7、
如果备份用不到了,则现在可以删除
RMAN> DELETE BACKUP TAG ‘FOR STANDBY’;

作者: myownstars   发布时间: 2011-09-07

顶原创

作者: maolinxie   发布时间: 2011-09-07

热门下载

更多