从Oracle RMAN备份恢复大约60%的时间失败(noarchivelog模式)

时间:2017-02-06 13:29:47

标签: oracle restore oracle12c rman

我有一个奇怪的情况,恢复最近创建的Oracle RMAN备份有时会起作用,而在其他时候则不行。

我们使用Oracle 12c。数据库以noarchivelog模式运行。

全文:我们有一个大的CI设置,一个节点可以拿起一个工作,从repo构建自己并运行测试。对于某些测试,需要进行数据库构建。为了加快测试速度,我们

  • 首次尝试从备份还原数据库。
  • 如果失败,我们将删除数据库重建shell和数据。重新创建备份,然后开始测试。

当然,理念是大部分时间恢复都能正常工作,实际上恢复大约有40%的时间可以正常工作,而有时它会失败并且数据库会重建。这个正在发生的节点和单个节点之间似乎没有任何关联,它可以工作一次然后不起作用。

我们使用以下脚本进行备份

rman target=/ << EOF
RUN {
    CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;
    SHUTDOWN IMMEDIATE;
    STARTUP MOUNT;
    BACKUP DATABASE;
}
EXIT;
EOF

以及以下要恢复

rman target=/ << EOF
RUN {
    SHUTDOWN IMMEDIATE;
    STARTUP MOUNT;
    RESTORE DATABASE;
    RECOVER DATABASE;
    ALTER DATABASE OPEN RESETLOGS;
}
EXIT;
EOF

当事情发生严重时,它会在RECOVER步骤中发生。

错误并不总是一样的。以下是我见过的一些

这个似乎是最近最常见的

04:23:10 channel ORA_DISK_1: restore complete, elapsed time: 00:00:15
04:23:10 Finished restore at 06-02-2017 04:23:10
04:23:10 
04:23:10 Starting recover at 06-02-2017 04:23:10
04:23:10 using channel ORA_DISK_1
04:23:11 
04:23:11 starting media recovery
04:23:11 
04:23:11 archived log for thread 1 with sequence 52 is already on disk as file /oracle/oradata/DB1/redoDB11.log
04:23:11 archived log for thread 1 with sequence 53 is already on disk as file /oracle/oradata/DB1/redoDB12.log
04:23:11 archived log for thread 1 with sequence 54 is already on disk as file /oracle/oradata/DB1/redoDB13.log
04:23:11 RMAN-08187: WARNING: media recovery until SCN 1662458 complete
04:23:11 Finished recover at 06-02-2017 04:23:11
04:23:11 
04:23:15 RMAN-00571: ===========================================================
04:23:15 RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
04:23:15 RMAN-00571: ===========================================================
04:23:15 RMAN-03002: failure of sql statement command at 02/06/2017 04:23:14
04:23:15 ORA-01147: SYSTEM tablespace file 1 is offline
04:23:15 ORA-01110: data file 1: '/oracle/oradata/DB1/DB1_system.dbf'
04:23:15 
04:23:15 RMAN> 
04:23:15 
04:23:15 Recovery Manager complete.

另一个错误

09:49:17 Finished restore at 27-01-2017 09:49:14
09:49:17 
09:49:17 Starting recover at 27-01-2017 09:49:14
09:49:17 using channel ORA_DISK_1
09:49:17 
09:49:17 starting media recovery
09:49:17 
09:49:17 archived log for thread 1 with sequence 52 is already on disk as file /oracle/oradata/DB1/redoDB11.log
09:49:17 archived log for thread 1 with sequence 53 is already on disk as file /oracle/oradata/DB1/redoDB12.log
09:49:17 archived log for thread 1 with sequence 54 is already on disk as file /oracle/oradata/DB1/redoDB13.log
09:49:17 RMAN-08187: WARNING: media recovery until SCN 1755105 complete
09:49:17 Finished recover at 27-01-2017 09:49:15
09:49:17 
09:49:17 RMAN-00571: ===========================================================
09:49:17 RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
09:49:17 RMAN-00571: ===========================================================
09:49:17 RMAN-03002: failure of sql statement command at 01/27/2017 09:49:16
09:49:17 ORA-01147: SYSTEM tablespace file 1 is offline
09:49:17 ORA-01110: data file 1: '/oracle/oradata/DB1/DB1_system.dbf'
09:49:17 
09:49:17 RMAN> 

还有一个

11:17:55 starting media recovery
11:17:55 media recovery failed
11:17:55 RMAN-00571: ===========================================================
11:17:55 RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
11:17:55 RMAN-00571: ===========================================================
11:17:55 RMAN-03002: failure of recover command at 01/27/2017 11:17:55
11:17:55 ORA-00283: recovery session canceled due to errors
11:17:55 RMAN-11003: failure during parse/execution of SQL statement: alter database recover if needed
11:17:55  start until cancel
11:17:55 ORA-00283: recovery session canceled due to errors
11:17:55 ORA-16433: The database or pluggable database must be opened in read/write mode.
11:17:55 
11:17:55 RMAN> 

另一个与上述三个不同的是,这个在RESTORE上失败

09:14:11 Starting restore at 06-02-2017 09:14:11
09:14:11 allocated channel: ORA_DISK_1
09:14:11 channel ORA_DISK_1: SID=12 device type=DISK
09:14:12 
09:14:12 creating datafile file number=1 name=/oracle/oradata/DB1/DB1_system.dbf
09:14:12 RMAN-00571: ===========================================================
09:14:12 RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
09:14:12 RMAN-00571: ===========================================================
09:14:12 RMAN-03002: failure of restore command at 02/06/2017 09:14:12
09:14:12 ORA-01180: can not create datafile 1
09:14:12 ORA-01110: data file 1: '/oracle/oradata/DB1/DB1_system.dbf'
09:14:12 
09:14:12 RMAN> 

非常感谢任何帮助。谢谢!

1 个答案:

答案 0 :(得分:1)

为了理解为什么会出现错误,重要的是要了解每个部分对您的脚本的意义:

RESTORE DATABASE;
RECOVER DATABASE;
ALTER DATABASE OPEN RESETLOGS;

RESTORE DATABASE;将备份集中的数据文件复制回数据库位置。

,如果数据库在执行备份时已关闭且一致(干净地关闭),则备份是一致的。

RECOVER DATABASE;首先尝试通过应用备份存档重做日志,归档重做日志和/或重做日志来使备份保持一致。然后,它将尝试从备份时间点向前滚动数据库,直到最近的重做日志。由于您在NOARCHIVELOG模式下运行,因此此步骤只会产生您所看到的错误。

ALTER DATABASE OPEN RESETLOGS;使您的数据库联机。 RESETLOGS清除重做日志,并且在完全恢复后需要它(如果数据库无法前滚并应用备份存档日志,存档日志和重做日志中的所有重做)。

考虑到这一点,您的脚本应如下所示:

RUN {
    SHUTDOWN IMMEDIATE;
    STARTUP MOUNT;
    RESTORE DATABASE;
    ALTER DATABASE OPEN RESETLOGS;
}

作为旁注,您还应该从RMAN配置spfile + controlfile自动备份。备份数据库时会自动执行此备份。

RMAN> CONFIGURE CONTROLFILE AUTOBACKUP ON;
RMAN> CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '%F';

正如JSapkoka所说,你也应该首先恢复spfile和controlfile,完整的恢复脚本看起来像这样:

RUN {
    SHUTDOWN IMMEDIATE;
    STARTUP NOMOUNT;
    SET CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO 'autobackup_format';
    RESTORE SPFILE FROM AUTOBACKUP;
    SHUTDOWN IMMEDIATE;
    STARTUP NOMOUNT;
    RESTORE CONTROLFILE FROM AUTOBACKUP;
    ALTER DATABASE MOUNT;
    RESTORE DATABASE;
    ALTER DATABASE OPEN RESETLOGS;
}