前往小程序,Get更优阅读体验!
立即前往
发布
社区首页 >专栏 >Oracle数据库工程师手记:备份恢复双城记(一)

Oracle数据库工程师手记:备份恢复双城记(一)

作者头像
SQLplusDB
发布2022-08-19 20:58:39
发布2022-08-19 20:58:39
77100
代码可运行
举报
运行总次数:0
代码可运行

编者按:

本文作者系大连健哥、 POSTGRESQL、ORACLE 数据库资深从业人员、IT 技术的深度爱好者。相信科学改变人类、技术创造未来。个人主页:https://www.cnblogs.com/gaojian/,经其本人授权发布。

【免责声明】本号文章仅代表个人观点,与任何公司无关。

有的时候,客户会有这样一种需求:他需要把数据库整体移行(移植)到另外一个硬件服务器上,但是,客户希望,尽可能地减少对 数据库用户的影响,当新数据库启用之前,客户希望他的数据库用户仍然能够访问数据库。

其实,最适合的方法,就是建立 Data Guard 了,无论原来的数据库有什么变更,都可以通过 redo 数据, 同步到新的数据库上。但是有的用户,对 Data Guard 的构筑过程不够熟悉,担心出现各种问题,那么就需要找到一些别的方法。

有的客户,会期待用自己所熟悉的备份、恢复的方法,在两个数据库服务器硬件之间进行腾挪,实现利用全备份+ 增分备份的方式,实现最小化停机时间,来完成迁移。想象一下,普通的备份恢复是什么样子,比如:

代码语言:javascript
代码运行次数:0
复制
rman>run{
       restore database;<br>       recover database;
}

然而,我现在需要的,却是这么一种方式:

在 dest 数据库,用第一次的备份,进行 restore。

继续在 source 数据库 和 dest 数据库直接,不断传递备份文件。

用第二次的备份,进行 recover,

用第三次的备份,再进行 recover,

......

用最后一次的备份,进行 recover,

用最新的 archive log ,进行 recover。

那么,在dest 端,从 rman 执行的就是类似这样的命令:

代码语言:javascript
代码运行次数:0
复制
rman>restore database;
rman>recover database;
rman>recover database;

能否可以实现呢,我把步骤细化一番,进行试验。在真正开始用在两个服务器之间进行腾挪之前,我先用一台机器模拟一下。我的设想是这样的:

首先,进行 level 0 的备份。紧接着,进行控制文件的备份。

然后,对数据库进行一些操作,然后,执行 level 1 增分备份。

然后,切换日志。

然后,对数据库进行一些操作,然后,再执行一轮 level 1 增分备份。

然后,切换日志。

然后,对数据库进行一些操作,然后,再执行一轮 level 1 增分备份。

然后,切换日志。

至此,备份完成。

然后,开始进行恢复测试,删除数据库的数据文件、online redo,并且把 archive log 挪走。

statup nomount 启动,恢复前面的 控制文件 (restore controlfile),将数据库设置为 mount 状态。

执行 restore database;

由于控制文件是比较陈旧的,所以,它没有上面三次 level 1 的增分备份的信息,

所以,

a)我用 catalog 命令,依次进行:catalog start with '增分备份所在的目录';

b)紧接着执行 recover database;

重复上述 a) b) 三次。

然后,还缺少最后的 archive log, 我再注册 archive log,然后执行最后一次的 recover database;

最后,执行 alter database open resetlogs;

具体的过程是这样的:

第一次,执行 level 0 备份:

代码语言:javascript
代码运行次数:0
复制
RMAN> backup incremental level 0 database format '/refresh/home/bak00/%U';
RMAN> backup current controlfile format '/refresh/home/bak00/control.bks';

得到的备份信息:

代码语言:javascript
代码运行次数:0
复制
RMAN> list backup;
 
List of Backup Sets
===================
 
BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -----------------
7       Incr 0  1.00G      DISK        00:00:13     20210403_07:07:31
        BP Key: 7   Status: AVAILABLE  Compressed: NO  Tag: TAG20210403T070718
        Piece Name: /refresh/home/bak00/06vrbk56_1_1
  List of Datafiles in backup set 7
  File LV Type Ckp SCN    Ckp Time          Name
  ---- -- ---- ---------- ----------------- ----
  1    0  Incr 991822     20210403_07:07:18 /refresh/home/app/11.2.0.4/oracle/oradata/orcl11204/system01.dbf
  2    0  Incr 991822     20210403_07:07:18 /refresh/home/app/11.2.0.4/oracle/oradata/orcl11204/sysaux01.dbf
  3    0  Incr 991822     20210403_07:07:18 /refresh/home/app/11.2.0.4/oracle/oradata/orcl11204/undotbs01.dbf
  4    0  Incr 991822     20210403_07:07:18 /refresh/home/app/11.2.0.4/oracle/oradata/orcl11204/users01.dbf
 
BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -----------------
8       Incr 0  9.36M      DISK        00:00:01     20210403_07:07:34
        BP Key: 8   Status: AVAILABLE  Compressed: NO  Tag: TAG20210403T070718
        Piece Name: /refresh/home/bak00/07vrbk5l_1_1
  SPFILE Included: Modification time: 20210403_06:50:46
  SPFILE db_unique_name: ORCL11204
  Control File Included: Ckp SCN: 991827       Ckp time: 20210403_07:07:33
 
BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -----------------
9       Full    9.33M      DISK        00:00:01     20210403_07:08:09
        BP Key: 9   Status: AVAILABLE  Compressed: NO  Tag: TAG20210403T070808
        Piece Name: /refresh/home/bak00/control.bks
  Control File Included: Ckp SCN: 991848       Ckp time: 20210403_07:08:08
 
RMAN>

注意这里得到的 level 0 增分备份的 checkpoint time: 20210403_07:07:18。

然后执行更新操作:

代码语言:javascript
代码运行次数:0
复制
SQL> create table tab001 as select * from dba_objects;

这时,进行 level 1 增分备份(第一回):

代码语言:javascript
代码运行次数:0
复制
RMAN> backup incremental level 1 database format '/refresh/home/bak01/%U';

然后,执行日志切换(这里是为了查看后来的恢复操作时需要哪些 archive log)(第一回):

代码语言:javascript
代码运行次数:0
复制
SQL> alter system switch logfile;
SQL> alter system switch logfile;

此时,得到的备份信息和 archive log 信息如下:

代码语言:javascript
代码运行次数:0
复制
RMAN> list backup;
 
using target database control file instead of recovery catalog
 
List of Backup Sets
===================
 
BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -----------------
7       Incr 0  1.00G      DISK        00:00:13     20210403_07:07:31
        BP Key: 7   Status: AVAILABLE  Compressed: NO  Tag: TAG20210403T070718
        Piece Name: /refresh/home/bak00/06vrbk56_1_1
  List of Datafiles in backup set 7
  File LV Type Ckp SCN    Ckp Time          Name
  ---- -- ---- ---------- ----------------- ----
  1    0  Incr 991822     20210403_07:07:18 /refresh/home/app/11.2.0.4/oracle/oradata/orcl11204/system01.dbf
  2    0  Incr 991822     20210403_07:07:18 /refresh/home/app/11.2.0.4/oracle/oradata/orcl11204/sysaux01.dbf
  3    0  Incr 991822     20210403_07:07:18 /refresh/home/app/11.2.0.4/oracle/oradata/orcl11204/undotbs01.dbf
  4    0  Incr 991822     20210403_07:07:18 /refresh/home/app/11.2.0.4/oracle/oradata/orcl11204/users01.dbf
 
BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -----------------
8       Incr 0  9.36M      DISK        00:00:01     20210403_07:07:34
        BP Key: 8   Status: AVAILABLE  Compressed: NO  Tag: TAG20210403T070718
        Piece Name: /refresh/home/bak00/07vrbk5l_1_1
  SPFILE Included: Modification time: 20210403_06:50:46
  SPFILE db_unique_name: ORCL11204
  Control File Included: Ckp SCN: 991827       Ckp time: 20210403_07:07:33
 
BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -----------------
9       Full    9.33M      DISK        00:00:01     20210403_07:08:09
        BP Key: 9   Status: AVAILABLE  Compressed: NO  Tag: TAG20210403T070808
        Piece Name: /refresh/home/bak00/control.bks
  Control File Included: Ckp SCN: 991848       Ckp time: 20210403_07:08:08
 
BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -----------------
10      Incr 1  9.84M      DISK        00:00:00     20210403_07:09:37
        BP Key: 10   Status: AVAILABLE  Compressed: NO  Tag: TAG20210403T070936
        Piece Name: /refresh/home/bak01/09vrbk9h_1_1
  List of Datafiles in backup set 10
  File LV Type Ckp SCN    Ckp Time          Name
  ---- -- ---- ---------- ----------------- ----
  1    1  Incr 991965     20210403_07:09:37 /refresh/home/app/11.2.0.4/oracle/oradata/orcl11204/system01.dbf
  2    1  Incr 991965     20210403_07:09:37 /refresh/home/app/11.2.0.4/oracle/oradata/orcl11204/sysaux01.dbf
  3    1  Incr 991965     20210403_07:09:37 /refresh/home/app/11.2.0.4/oracle/oradata/orcl11204/undotbs01.dbf
  4    1  Incr 991965     20210403_07:09:37 /refresh/home/app/11.2.0.4/oracle/oradata/orcl11204/users01.dbf
 
BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -----------------
11      Incr 1  9.36M      DISK        00:00:01     20210403_07:09:39
        BP Key: 11   Status: AVAILABLE  Compressed: NO  Tag: TAG20210403T070936
        Piece Name: /refresh/home/bak01/0avrbk9i_1_1
  SPFILE Included: Modification time: 20210403_06:50:46
  SPFILE db_unique_name: ORCL11204
  Control File Included: Ckp SCN: 991965       Ckp time: 20210403_07:09:37
 
RMAN> list archivelog all;
 
List of Archived Log Copies for database with db_unique_name ORCL11204
=====================================================================
 
Key     Thrd Seq     S Low Time
------- ---- ------- - -----------------
3       1    1       A 20210403_06:50:09
        Name: /refresh/home/app/11.2.0.4/oracle/product/11.2.0.4/dbhome_4/dbs/arch1_1_1068879009.dbf
 
4       1    2       A 20210403_07:10:22
        Name: /refresh/home/app/11.2.0.4/oracle/product/11.2.0.4/dbhome_4/dbs/arch1_2_1068879009.dbf
 
 
RMAN>

接下来,再进行第二次的 level 1 的增分备份:

对数据库进行一些变更(第二回):

代码语言:javascript
代码运行次数:0
复制
SQL> create table tab002 as select * from dba_objects;

执行level 1 增分备份(第二回):

代码语言:javascript
代码运行次数:0
复制
RMAN> backup incremental level 1 database format '/refresh/home/bak02/%U';

再次日志切换(第二回):

代码语言:javascript
代码运行次数:0
复制
SQL> alter system switch logfile;
SQL> alter system switch logfile;

查看备份信息和 archive log 信息:

代码语言:javascript
代码运行次数:0
复制
RMAN> list backup;
 
List of Backup Sets
===================
 
BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -----------------
7       Incr 0  1.00G      DISK        00:00:13     20210403_07:07:31
        BP Key: 7   Status: AVAILABLE  Compressed: NO  Tag: TAG20210403T070718
        Piece Name: /refresh/home/bak00/06vrbk56_1_1
  List of Datafiles in backup set 7
  File LV Type Ckp SCN    Ckp Time          Name
  ---- -- ---- ---------- ----------------- ----
  1    0  Incr 991822     20210403_07:07:18 /refresh/home/app/11.2.0.4/oracle/oradata/orcl11204/system01.dbf
  2    0  Incr 991822     20210403_07:07:18 /refresh/home/app/11.2.0.4/oracle/oradata/orcl11204/sysaux01.dbf
  3    0  Incr 991822     20210403_07:07:18 /refresh/home/app/11.2.0.4/oracle/oradata/orcl11204/undotbs01.dbf
  4    0  Incr 991822     20210403_07:07:18 /refresh/home/app/11.2.0.4/oracle/oradata/orcl11204/users01.dbf
 
BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -----------------
8       Incr 0  9.36M      DISK        00:00:01     20210403_07:07:34
        BP Key: 8   Status: AVAILABLE  Compressed: NO  Tag: TAG20210403T070718
        Piece Name: /refresh/home/bak00/07vrbk5l_1_1
  SPFILE Included: Modification time: 20210403_06:50:46
  SPFILE db_unique_name: ORCL11204
  Control File Included: Ckp SCN: 991827       Ckp time: 20210403_07:07:33
 
BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -----------------
9       Full    9.33M      DISK        00:00:01     20210403_07:08:09
        BP Key: 9   Status: AVAILABLE  Compressed: NO  Tag: TAG20210403T070808
        Piece Name: /refresh/home/bak00/control.bks
  Control File Included: Ckp SCN: 991848       Ckp time: 20210403_07:08:08
 
BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -----------------
10      Incr 1  9.84M      DISK        00:00:00     20210403_07:09:37
        BP Key: 10   Status: AVAILABLE  Compressed: NO  Tag: TAG20210403T070936
        Piece Name: /refresh/home/bak01/09vrbk9h_1_1
  List of Datafiles in backup set 10
  File LV Type Ckp SCN    Ckp Time          Name
  ---- -- ---- ---------- ----------------- ----
  1    1  Incr 991965     20210403_07:09:37 /refresh/home/app/11.2.0.4/oracle/oradata/orcl11204/system01.dbf
  2    1  Incr 991965     20210403_07:09:37 /refresh/home/app/11.2.0.4/oracle/oradata/orcl11204/sysaux01.dbf
  3    1  Incr 991965     20210403_07:09:37 /refresh/home/app/11.2.0.4/oracle/oradata/orcl11204/undotbs01.dbf
  4    1  Incr 991965     20210403_07:09:37 /refresh/home/app/11.2.0.4/oracle/oradata/orcl11204/users01.dbf
 
BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -----------------
11      Incr 1  9.36M      DISK        00:00:01     20210403_07:09:39
        BP Key: 11   Status: AVAILABLE  Compressed: NO  Tag: TAG20210403T070936
        Piece Name: /refresh/home/bak01/0avrbk9i_1_1
  SPFILE Included: Modification time: 20210403_06:50:46
  SPFILE db_unique_name: ORCL11204
  Control File Included: Ckp SCN: 991965       Ckp time: 20210403_07:09:37
 
BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -----------------
12      Incr 1  9.93M      DISK        00:00:00     20210403_07:12:57
        BP Key: 12   Status: AVAILABLE  Compressed: NO  Tag: TAG20210403T071257
        Piece Name: /refresh/home/bak02/0bvrbkfp_1_1
  List of Datafiles in backup set 12
  File LV Type Ckp SCN    Ckp Time          Name
  ---- -- ---- ---------- ----------------- ----
  1    1  Incr 992145     20210403_07:12:57 /refresh/home/app/11.2.0.4/oracle/oradata/orcl11204/system01.dbf
  2    1  Incr 992145     20210403_07:12:57 /refresh/home/app/11.2.0.4/oracle/oradata/orcl11204/sysaux01.dbf
  3    1  Incr 992145     20210403_07:12:57 /refresh/home/app/11.2.0.4/oracle/oradata/orcl11204/undotbs01.dbf
  4    1  Incr 992145     20210403_07:12:57 /refresh/home/app/11.2.0.4/oracle/oradata/orcl11204/users01.dbf
 
BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -----------------
13      Incr 1  9.36M      DISK        00:00:01     20210403_07:12:59
        BP Key: 13   Status: AVAILABLE  Compressed: NO  Tag: TAG20210403T071257
        Piece Name: /refresh/home/bak02/0cvrbkfq_1_1
  SPFILE Included: Modification time: 20210403_06:50:46
  SPFILE db_unique_name: ORCL11204
  Control File Included: Ckp SCN: 992145       Ckp time: 20210403_07:12:57
RMAN> list archivelog all;
 
using target database control file instead of recovery catalog
List of Archived Log Copies for database with db_unique_name ORCL11204
=====================================================================
 
Key     Thrd Seq     S Low Time
------- ---- ------- - -----------------
3       1    1       A 20210403_06:50:09
        Name: /refresh/home/app/11.2.0.4/oracle/product/11.2.0.4/dbhome_4/dbs/arch1_1_1068879009.dbf
 
4       1    2       A 20210403_07:10:22
        Name: /refresh/home/app/11.2.0.4/oracle/product/11.2.0.4/dbhome_4/dbs/arch1_2_1068879009.dbf
 
5       1    3       A 20210403_07:10:28
        Name: /refresh/home/app/11.2.0.4/oracle/product/11.2.0.4/dbhome_4/dbs/arch1_3_1068879009.dbf
 
6       1    4       A 20210403_07:13:37
        Name: /refresh/home/app/11.2.0.4/oracle/product/11.2.0.4/dbhome_4/dbs/arch1_4_1068879009.dbf
 
RMAN>

再来一回(第三回):

数据库变更(第三回):

代码语言:javascript
代码运行次数:0
复制
SQL> create table tab003 as select * from dba_objects;

level 1 增分备份(第三回):

代码语言:javascript
代码运行次数:0
复制
RMAN> backup incremental level 1 database format '/refresh/home/bak03/%U';

日志切换(第三回):

代码语言:javascript
代码运行次数:0
复制
SQL> alter system switch logfile;
SQL> alter system switch logfile;

再次查看备份信息和 archive log 信息:

代码语言:javascript
代码运行次数:0
复制
RMAN> list backup;
 
List of Backup Sets
===================
 
 
BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -----------------
7       Incr 0  1.00G      DISK        00:00:13     20210403_07:07:31
        BP Key: 7   Status: AVAILABLE  Compressed: NO  Tag: TAG20210403T070718
        Piece Name: /refresh/home/bak00/06vrbk56_1_1
  List of Datafiles in backup set 7
  File LV Type Ckp SCN    Ckp Time          Name
  ---- -- ---- ---------- ----------------- ----
  1    0  Incr 991822     20210403_07:07:18 /refresh/home/app/11.2.0.4/oracle/oradata/orcl11204/system01.dbf
  2    0  Incr 991822     20210403_07:07:18 /refresh/home/app/11.2.0.4/oracle/oradata/orcl11204/sysaux01.dbf
  3    0  Incr 991822     20210403_07:07:18 /refresh/home/app/11.2.0.4/oracle/oradata/orcl11204/undotbs01.dbf
  4    0  Incr 991822     20210403_07:07:18 /refresh/home/app/11.2.0.4/oracle/oradata/orcl11204/users01.dbf
 
BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -----------------
8       Incr 0  9.36M      DISK        00:00:01     20210403_07:07:34
        BP Key: 8   Status: AVAILABLE  Compressed: NO  Tag: TAG20210403T070718
        Piece Name: /refresh/home/bak00/07vrbk5l_1_1
  SPFILE Included: Modification time: 20210403_06:50:46
  SPFILE db_unique_name: ORCL11204
  Control File Included: Ckp SCN: 991827       Ckp time: 20210403_07:07:33
 
BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -----------------
9       Full    9.33M      DISK        00:00:01     20210403_07:08:09
        BP Key: 9   Status: AVAILABLE  Compressed: NO  Tag: TAG20210403T070808
        Piece Name: /refresh/home/bak00/control.bks
  Control File Included: Ckp SCN: 991848       Ckp time: 20210403_07:08:08
 
BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -----------------
10      Incr 1  9.84M      DISK        00:00:00     20210403_07:09:37
        BP Key: 10   Status: AVAILABLE  Compressed: NO  Tag: TAG20210403T070936
        Piece Name: /refresh/home/bak01/09vrbk9h_1_1
  List of Datafiles in backup set 10
  File LV Type Ckp SCN    Ckp Time          Name
  ---- -- ---- ---------- ----------------- ----
  1    1  Incr 991965     20210403_07:09:37 /refresh/home/app/11.2.0.4/oracle/oradata/orcl11204/system01.dbf
  2    1  Incr 991965     20210403_07:09:37 /refresh/home/app/11.2.0.4/oracle/oradata/orcl11204/sysaux01.dbf
  3    1  Incr 991965     20210403_07:09:37 /refresh/home/app/11.2.0.4/oracle/oradata/orcl11204/undotbs01.dbf
  4    1  Incr 991965     20210403_07:09:37 /refresh/home/app/11.2.0.4/oracle/oradata/orcl11204/users01.dbf
 
BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -----------------
11      Incr 1  9.36M      DISK        00:00:01     20210403_07:09:39
        BP Key: 11   Status: AVAILABLE  Compressed: NO  Tag: TAG20210403T070936
        Piece Name: /refresh/home/bak01/0avrbk9i_1_1
  SPFILE Included: Modification time: 20210403_06:50:46
  SPFILE db_unique_name: ORCL11204
  Control File Included: Ckp SCN: 991965       Ckp time: 20210403_07:09:37
 
BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -----------------
12      Incr 1  9.93M      DISK        00:00:00     20210403_07:12:57
        BP Key: 12   Status: AVAILABLE  Compressed: NO  Tag: TAG20210403T071257
        Piece Name: /refresh/home/bak02/0bvrbkfp_1_1
  List of Datafiles in backup set 12
  File LV Type Ckp SCN    Ckp Time          Name
  ---- -- ---- ---------- ----------------- ----
  1    1  Incr 992145     20210403_07:12:57 /refresh/home/app/11.2.0.4/oracle/oradata/orcl11204/system01.dbf
  2    1  Incr 992145     20210403_07:12:57 /refresh/home/app/11.2.0.4/oracle/oradata/orcl11204/sysaux01.dbf
  3    1  Incr 992145     20210403_07:12:57 /refresh/home/app/11.2.0.4/oracle/oradata/orcl11204/undotbs01.dbf
  4    1  Incr 992145     20210403_07:12:57 /refresh/home/app/11.2.0.4/oracle/oradata/orcl11204/users01.dbf
 
BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -----------------
13      Incr 1  9.36M      DISK        00:00:01     20210403_07:12:59
        BP Key: 13   Status: AVAILABLE  Compressed: NO  Tag: TAG20210403T071257
        Piece Name: /refresh/home/bak02/0cvrbkfq_1_1
  SPFILE Included: Modification time: 20210403_06:50:46
  SPFILE db_unique_name: ORCL11204
  Control File Included: Ckp SCN: 992145       Ckp time: 20210403_07:12:57
 
BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -----------------
14      Incr 1  9.82M      DISK        00:00:00     20210403_07:15:56
        BP Key: 14   Status: AVAILABLE  Compressed: NO  Tag: TAG20210403T071555
        Piece Name: /refresh/home/bak03/0dvrbklc_1_1
  List of Datafiles in backup set 14
  File LV Type Ckp SCN    Ckp Time          Name
  ---- -- ---- ---------- ----------------- ----
  1    1  Incr 992322     20210403_07:15:56 /refresh/home/app/11.2.0.4/oracle/oradata/orcl11204/system01.dbf
  2    1  Incr 992322     20210403_07:15:56 /refresh/home/app/11.2.0.4/oracle/oradata/orcl11204/sysaux01.dbf
  3    1  Incr 992322     20210403_07:15:56 /refresh/home/app/11.2.0.4/oracle/oradata/orcl11204/undotbs01.dbf
  4    1  Incr 992322     20210403_07:15:56 /refresh/home/app/11.2.0.4/oracle/oradata/orcl11204/users01.dbf
 
BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -----------------
15      Incr 1  9.36M      DISK        00:00:01     20210403_07:15:58
        BP Key: 15   Status: AVAILABLE  Compressed: NO  Tag: TAG20210403T071555
        Piece Name: /refresh/home/bak03/0evrbkld_1_1
  SPFILE Included: Modification time: 20210403_06:50:46
  SPFILE db_unique_name: ORCL11204
  Control File Included: Ckp SCN: 992323       Ckp time: 20210403_07:15:57
 
RMAN>
 
RMAN> list archivelog all;
 
using target database control file instead of recovery catalog
List of Archived Log Copies for database with db_unique_name ORCL11204
=====================================================================
 
Key     Thrd Seq     S Low Time
------- ---- ------- - -----------------
3       1    1       A 20210403_06:50:09
        Name: /refresh/home/app/11.2.0.4/oracle/product/11.2.0.4/dbhome_4/dbs/arch1_1_1068879009.dbf
 
4       1    2       A 20210403_07:10:22
        Name: /refresh/home/app/11.2.0.4/oracle/product/11.2.0.4/dbhome_4/dbs/arch1_2_1068879009.dbf
 
5       1    3       A 20210403_07:10:28
        Name: /refresh/home/app/11.2.0.4/oracle/product/11.2.0.4/dbhome_4/dbs/arch1_3_1068879009.dbf
 
6       1    4       A 20210403_07:13:37
        Name: /refresh/home/app/11.2.0.4/oracle/product/11.2.0.4/dbhome_4/dbs/arch1_4_1068879009.dbf
 
7       1    5       A 20210403_07:13:41
        Name: /refresh/home/app/11.2.0.4/oracle/product/11.2.0.4/dbhome_4/dbs/arch1_5_1068879009.dbf
 
8       1    6       A 20210403_07:16:41
        Name: /refresh/home/app/11.2.0.4/oracle/product/11.2.0.4/dbhome_4/dbs/arch1_6_1068879009.dbf
 
RMAN>

再作一点变更吧,并且把 online redo 切换出来,再记录一下 datafile 和 online redo 的位置,然后停机。

代码语言:javascript
代码运行次数:0
复制
SQL> create table tab004 as select * from dba_objects;
 
Table created.
 
SQL> alter system switch logfile;
 
System altered.
 
SQL> select * from v$log;
 
    GROUP#    THREAD#  SEQUENCE#      BYTES  BLOCKSIZE    MEMBERS ARC
---------- ---------- ---------- ---------- ---------- ---------- ---
STATUS           FIRST_CHANGE# FIRST_TIM NEXT_CHANGE# NEXT_TIME
---------------- ------------- --------- ------------ ---------
         1          1          7   52428800        512          1 YES
ACTIVE                  992359 03-APR-21       992471 03-APR-21
 
         2          1          8   52428800        512          1 NO
CURRENT                 992471 03-APR-21   2.8147E+14
 
         3          1          6   52428800        512          1 YES
INACTIVE                992355 03-APR-21       992359 03-APR-21
 
 
SQL> select member from v$logfile;
 
MEMBER
--------------------------------------------------------------------------------
/refresh/home/app/11.2.0.4/oracle/oradata/orcl11204/redo03.log
/refresh/home/app/11.2.0.4/oracle/oradata/orcl11204/redo02.log
/refresh/home/app/11.2.0.4/oracle/oradata/orcl11204/redo01.log
 
SQL> select name from v$datafile;
 
NAME
--------------------------------------------------------------------------------
/refresh/home/app/11.2.0.4/oracle/oradata/orcl11204/system01.dbf
/refresh/home/app/11.2.0.4/oracle/oradata/orcl11204/sysaux01.dbf
/refresh/home/app/11.2.0.4/oracle/oradata/orcl11204/undotbs01.dbf
/refresh/home/app/11.2.0.4/oracle/oradata/orcl11204/users01.dbf
 
SQL>
 
SQL> shutdown immediate;

好了,现在我可以开始进行恢复的试验了:

把数据文件和online redo 统统挪走:

代码语言:javascript
代码运行次数:0
复制
-bash-4.1$ pwd
/refresh/home/app/11.2.0.4/oracle/oradata/orcl11204
-bash-4.1$ ls -lrt
total 1520276
-rw-rw---- 1 oracle oracle  20979712 Apr  3 06:50 temp01.dbf
-rw-rw---- 1 oracle oracle  52429312 Apr  3 07:16 redo03.log
-rw-rw---- 1 oracle oracle  52429312 Apr  3 07:17 redo01.log
-rw-rw---- 1 oracle oracle  52429312 Apr  3 07:20 redo02.log
-rw-rw---- 1 oracle oracle 817897472 Apr  3 07:20 system01.dbf
-rw-rw---- 1 oracle oracle  31465472 Apr  3 07:20 undotbs01.dbf
-rw-rw---- 1 oracle oracle 524296192 Apr  3 07:20 sysaux01.dbf
-rw-rw---- 1 oracle oracle   5251072 Apr  3 07:20 users01.dbf
-rw-rw---- 1 oracle oracle   9748480 Apr  3 07:20 control02.ctl
-rw-rw---- 1 oracle oracle   9748480 Apr  3 07:20 control01.ctl
-bash-4.1$ cd ..
-bash-4.1$ mv orcl11204 orcl11204.bak
-bash-4.1$ mkdir orcl11204

再把 archive log 挪走:

代码语言:javascript
代码运行次数:0
复制
-bash-4.1$ mkdir -p /refresh/home/arc
-bash-4.1$ mv  /refresh/home/app/11.2.0.4/oracle/product/11.2.0.4/dbhome_4/dbs/arc* /refresh/home/arc
-bash-4.1$ ls -lrt /refresh/home/app/11.2.0.4/oracle/product/11.2.0.4/dbhome_4/dbs
total 9544
-rw-r--r-- 1 oracle oracle    2851 May 15  2009 init.ora
-rw-r----- 1 oracle oracle      24 Aug 24  2017 lkORCL1120
-rw-r----- 1 oracle oracle    1536 Aug 24  2017 orapworcl11204
-rw-r----- 1 oracle oracle      24 Aug 24  2017 lkORCL11204
-rw-r----- 1 oracle oracle    3584 Apr  3 06:50 spfileorcl11204.ora
-rw-rw---- 1 oracle oracle 9748480 Apr  3 07:15 snapcf_orcl11204.f
-rw-rw---- 1 oracle oracle    1544 Apr  3 07:20 hc_orcl11204.dat

下面,nomount 模式启动,然后恢复出旧的控制文件,这是为了模拟将来在新机器上只有旧的控制文件的操作。

代码语言:javascript
代码运行次数:0
复制
-bash-4.1$ rman target /
 
Recovery Manager: Release 11.2.0.4.0 - Production on Sat Apr 3 07:22:59 2021
 
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.
 
connected to target database (not started)
 
RMAN> startup nomount;
 
 
RMAN> restore controlfile from '/refresh/home/bak00/control.bks';
 
Starting restore at 20210403_07:25:03
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=1 device type=DISK
 
channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/refresh/home/app/11.2.0.4/oracle/oradata/orcl11204/control01.ctl
output file name=/refresh/home/app/11.2.0.4/oracle/oradata/orcl11204/control02.ctl
Finished restore at 20210403_07:25:04
 
RMAN> alter database mount;
 
database mounted
released channel: ORA_DISK_1
 
RMAN>

可以看到,因为控制文件的信息比较陈旧,它只有第一次level 0 备份的信息:

代码语言:javascript
代码运行次数:0
复制
RMAN> list backup;
 
 
List of Backup Sets
===================
 
 
BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -----------------
7       Incr 0  1.00G      DISK        00:00:13     20210403_07:07:31
        BP Key: 7   Status: AVAILABLE  Compressed: NO  Tag: TAG20210403T070718
        Piece Name: /refresh/home/bak00/06vrbk56_1_1
  List of Datafiles in backup set 7
  File LV Type Ckp SCN    Ckp Time          Name
  ---- -- ---- ---------- ----------------- ----
  1    0  Incr 991822     20210403_07:07:18 /refresh/home/app/11.2.0.4/oracle/oradata/orcl11204/system01.dbf
  2    0  Incr 991822     20210403_07:07:18 /refresh/home/app/11.2.0.4/oracle/oradata/orcl11204/sysaux01.dbf
  3    0  Incr 991822     20210403_07:07:18 /refresh/home/app/11.2.0.4/oracle/oradata/orcl11204/undotbs01.dbf
  4    0  Incr 991822     20210403_07:07:18 /refresh/home/app/11.2.0.4/oracle/oradata/orcl11204/users01.dbf
 
BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -----------------
8       Incr 0  9.36M      DISK        00:00:01     20210403_07:07:34
        BP Key: 8   Status: AVAILABLE  Compressed: NO  Tag: TAG20210403T070718
        Piece Name: /refresh/home/bak00/07vrbk5l_1_1
  SPFILE Included: Modification time: 20210403_06:50:46
  SPFILE db_unique_name: ORCL11204
  Control File Included: Ckp SCN: 991827       Ckp time: 20210403_07:07:33
 
RMAN> list archivelog all;
 
specification does not match any archived log in the repository
 
RMAN>

执行 restore 操作:

代码语言:javascript
代码运行次数:0
复制
RMAN> restore database;
 
Starting restore at 20210403_07:26:13
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=1 device type=DISK
 
channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00001 to /refresh/home/app/11.2.0.4/oracle/oradata/orcl11204/system01.dbf
channel ORA_DISK_1: restoring datafile 00002 to /refresh/home/app/11.2.0.4/oracle/oradata/orcl11204/sysaux01.dbf
channel ORA_DISK_1: restoring datafile 00003 to /refresh/home/app/11.2.0.4/oracle/oradata/orcl11204/undotbs01.dbf
channel ORA_DISK_1: restoring datafile 00004 to /refresh/home/app/11.2.0.4/oracle/oradata/orcl11204/users01.dbf
channel ORA_DISK_1: reading from backup piece /refresh/home/bak00/06vrbk56_1_1
channel ORA_DISK_1: piece handle=/refresh/home/bak00/06vrbk56_1_1 tag=TAG20210403T070718
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:07
Finished restore at 20210403_07:26:21
 
RMAN>

然后,我开始把第一回的 level 1 增分备份信息注册回来,执行 recover database:

代码语言:javascript
代码运行次数:0
复制
RMAN> catalog start with '/refresh/home/bak01';
 
searching for all files that match the pattern /refresh/home/bak01
 
List of Files Unknown to the Database
=====================================
File Name: /refresh/home/bak01/0avrbk9i_1_1
File Name: /refresh/home/bak01/control.bks
File Name: /refresh/home/bak01/09vrbk9h_1_1
 
Do you really want to catalog the above files (enter YES or NO)? yes
cataloging files...
cataloging done
 
List of Cataloged Files
=======================
File Name: /refresh/home/bak01/0avrbk9i_1_1
File Name: /refresh/home/bak01/control.bks
File Name: /refresh/home/bak01/09vrbk9h_1_1

可以看到,备份的信息增加了:

代码语言:javascript
代码运行次数:0
复制
RMAN> list backup;
 
List of Backup Sets
===================
 
BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -----------------
7       Incr 0  1.00G      DISK        00:00:13     20210403_07:07:31
        BP Key: 7   Status: AVAILABLE  Compressed: NO  Tag: TAG20210403T070718
        Piece Name: /refresh/home/bak00/06vrbk56_1_1
  List of Datafiles in backup set 7
  File LV Type Ckp SCN    Ckp Time          Name
  ---- -- ---- ---------- ----------------- ----
  1    0  Incr 991822     20210403_07:07:18 /refresh/home/app/11.2.0.4/oracle/oradata/orcl11204/system01.dbf
  2    0  Incr 991822     20210403_07:07:18 /refresh/home/app/11.2.0.4/oracle/oradata/orcl11204/sysaux01.dbf
  3    0  Incr 991822     20210403_07:07:18 /refresh/home/app/11.2.0.4/oracle/oradata/orcl11204/undotbs01.dbf
  4    0  Incr 991822     20210403_07:07:18 /refresh/home/app/11.2.0.4/oracle/oradata/orcl11204/users01.dbf
 
BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -----------------
8       Incr 0  9.36M      DISK        00:00:01     20210403_07:07:34
        BP Key: 8   Status: AVAILABLE  Compressed: NO  Tag: TAG20210403T070718
        Piece Name: /refresh/home/bak00/07vrbk5l_1_1
  SPFILE Included: Modification time: 20210403_06:50:46
  SPFILE db_unique_name: ORCL11204
  Control File Included: Ckp SCN: 991827       Ckp time: 20210403_07:07:33
 
BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -----------------
9       Incr 1  9.36M      DISK        00:00:00     20210403_07:09:38
        BP Key: 9   Status: AVAILABLE  Compressed: NO  Tag: TAG20210403T070936
        Piece Name: /refresh/home/bak01/0avrbk9i_1_1
  SPFILE Included: Modification time: 20210403_06:50:46
  SPFILE db_unique_name: ORCL11204
  Control File Included: Ckp SCN: 991965       Ckp time: 20210403_07:09:37
 
BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -----------------
10      Full    9.33M      DISK        00:00:00     20210403_06:29:06
        BP Key: 10   Status: AVAILABLE  Compressed: NO  Tag: TAG20210403T062906
        Piece Name: /refresh/home/bak01/control.bks
  Control File Included: Ckp SCN: 989812       Ckp time: 20210403_06:29:06
 
BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -----------------
11      Incr 1  9.84M      DISK        00:00:00     20210403_07:09:37
        BP Key: 11   Status: AVAILABLE  Compressed: NO  Tag: TAG20210403T070936
        Piece Name: /refresh/home/bak01/09vrbk9h_1_1
  List of Datafiles in backup set 11
  File LV Type Ckp SCN    Ckp Time          Name
  ---- -- ---- ---------- ----------------- ----
  1    1  Incr 991965     20210403_07:09:37 /refresh/home/app/11.2.0.4/oracle/oradata/orcl11204/system01.dbf
  2    1  Incr 991965     20210403_07:09:37 /refresh/home/app/11.2.0.4/oracle/oradata/orcl11204/sysaux01.dbf
  3    1  Incr 991965     20210403_07:09:37 /refresh/home/app/11.2.0.4/oracle/oradata/orcl11204/undotbs01.dbf
  4    1  Incr 991965     20210403_07:09:37 /refresh/home/app/11.2.0.4/oracle/oradata/orcl11204/users01.dbf
 
RMAN> list archivelog all;
 
specification does not match any archived log in the repository
 
RMAN>

那么,我可以进行第一次的 recover database 的操作了:

代码语言:javascript
代码运行次数:0
复制
RMAN> recover database;
 
Starting recover at 20210403_07:27:21
using channel ORA_DISK_1
channel ORA_DISK_1: starting incremental datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
destination for restore of datafile 00001: /refresh/home/app/11.2.0.4/oracle/oradata/orcl11204/system01.dbf
destination for restore of datafile 00002: /refresh/home/app/11.2.0.4/oracle/oradata/orcl11204/sysaux01.dbf
destination for restore of datafile 00003: /refresh/home/app/11.2.0.4/oracle/oradata/orcl11204/undotbs01.dbf
destination for restore of datafile 00004: /refresh/home/app/11.2.0.4/oracle/oradata/orcl11204/users01.dbf
channel ORA_DISK_1: reading from backup piece /refresh/home/bak01/09vrbk9h_1_1
channel ORA_DISK_1: piece handle=/refresh/home/bak01/09vrbk9h_1_1 tag=TAG20210403T070936
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
 
starting media recovery
 
unable to find archived log
archived log thread=1 sequence=1
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 04/03/2021 07:27:23
RMAN-06054: media recovery requesting unknown archived log for thread 1 with sequence 1 and starting SCN of 991848
 
RMAN>

出 warnnig 其实很正常,因为只要不是指定 set until time/scn/archive log, Oracle 肯定要往下一直找 archive log的。

recover database 的执行过程,确实用到了第一回 level 1 增分备份的备份集合:09vrbk9h_1_1。

但是注意看我的 level 0 的备份信息的 Ckp Time:

代码语言:javascript
代码运行次数:0
复制
BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -----------------
7       Incr 0  1.00G      DISK        00:00:13     20210403_07:07:31
        BP Key: 7   Status: AVAILABLE  Compressed: NO  Tag: TAG20210403T070718
        Piece Name: /refresh/home/bak00/06vrbk56_1_1
  List of Datafiles in backup set 7
  File LV Type Ckp SCN    Ckp Time          Name
  ---- -- ---- ---------- ----------------- ----
  1    0  Incr 991822     20210403_07:07:18 /refresh/home/app/11.2.0.4/oracle/oradata/orcl11204/system01.dbf
  2    0  Incr 991822     20210403_07:07:18 /refresh/home/app/11.2.0.4/oracle/oradata/orcl11204/sysaux01.dbf
  3    0  Incr 991822     20210403_07:07:18 /refresh/home/app/11.2.0.4/oracle/oradata/orcl11204/undotbs01.dbf
  4    0  Incr 991822     20210403_07:07:18 /refresh/home/app/11.2.0.4/oracle/oradata/orcl11204/users01.dbf

Level 0 备份当时的 log 显示:

代码语言:javascript
代码运行次数:0
复制
channel ORA_DISK_1: starting piece 1 at 20210403_07:07:18
channel ORA_DISK_1: finished piece 1 at 20210403_07:07:33

可以近似地认为,Level 0 备份,包含了 07:07:18开始,截止至 07:07:33 的内容。

而 archive log 的信息显示:

代码语言:javascript
代码运行次数:0
复制
Key     Thrd Seq     S Low Time
------- ---- ------- - -----------------
3       1    1       A 20210403_06:50:09
        Name: /refresh/home/app/11.2.0.4/oracle/product/11.2.0.4/dbhome_4/dbs/arch1_1_1068879009.dbf
 
4       1    2       A 20210403_07:10:22
        Name: /refresh/home/app/11.2.0.4/oracle/product/11.2.0.4/dbhome_4/dbs/arch1_2_1068879009.dbf

thread 1 with sequence 1 的 archive log,它包含的变更内容的时间范围涵盖 06:50:09 -- 07:10:22。

我执行了 level 1 的增分备份所对应的那一部分 recover databse,然而 rman 似乎只记得 第一次 level 0 增分时的状况,它在向我要求:thread 1 with sequence 1 的 archive log !换句话说,数据库无视了已经利用Level 1 增分备份的执行成功的状况,它仍然在寻找用从 Level 0 备份执行 restore database 之后的 SCN 来计算的内容。

为了看得更清楚一些,再把第二回 level 1 增分备份注册,然后执行 restore database:

代码语言:javascript
代码运行次数:0
复制
RMAN> catalog start with '/refresh/home/bak02';
 
searching for all files that match the pattern /refresh/home/bak02
 
List of Files Unknown to the Database
=====================================
File Name: /refresh/home/bak02/0bvrbkfp_1_1
File Name: /refresh/home/bak02/0cvrbkfq_1_1
 
Do you really want to catalog the above files (enter YES or NO)? yes
cataloging files...
cataloging done
 
List of Cataloged Files
=======================
File Name: /refresh/home/bak02/0bvrbkfp_1_1
File Name: /refresh/home/bak02/0cvrbkfq_1_1
 
RMAN> recover database;
 
Starting recover at 20210403_07:28:26
using channel ORA_DISK_1
channel ORA_DISK_1: starting incremental datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
destination for restore of datafile 00001: /refresh/home/app/11.2.0.4/oracle/oradata/orcl11204/system01.dbf
destination for restore of datafile 00002: /refresh/home/app/11.2.0.4/oracle/oradata/orcl11204/sysaux01.dbf
destination for restore of datafile 00003: /refresh/home/app/11.2.0.4/oracle/oradata/orcl11204/undotbs01.dbf
destination for restore of datafile 00004: /refresh/home/app/11.2.0.4/oracle/oradata/orcl11204/users01.dbf
channel ORA_DISK_1: reading from backup piece /refresh/home/bak02/0bvrbkfp_1_1
channel ORA_DISK_1: piece handle=/refresh/home/bak02/0bvrbkfp_1_1 tag=TAG20210403T071257
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
 
starting media recovery
 
unable to find archived log
archived log thread=1 sequence=1
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 04/03/2021 07:28:28
RMAN-06054: media recovery requesting unknown archived log for thread 1 with sequence 1 and starting SCN of 991848
 
RMAN>

仍然没有变化,还在要 archived log for thread 1 with sequence 1 !

再把第三回的 level 1 增分备份注册上来:

代码语言:javascript
代码运行次数:0
复制
RMAN> catalog start with '/refresh/home/bak03';
 
searching for all files that match the pattern /refresh/home/bak03
 
List of Files Unknown to the Database
=====================================
File Name: /refresh/home/bak03/0evrbkld_1_1
File Name: /refresh/home/bak03/0dvrbklc_1_1
 
Do you really want to catalog the above files (enter YES or NO)? yes
cataloging files...
cataloging done
 
List of Cataloged Files
=======================
File Name: /refresh/home/bak03/0evrbkld_1_1
File Name: /refresh/home/bak03/0dvrbklc_1_1
 
RMAN> recover database;
 
Starting recover at 20210403_07:30:19
using channel ORA_DISK_1
channel ORA_DISK_1: starting incremental datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
destination for restore of datafile 00001: /refresh/home/app/11.2.0.4/oracle/oradata/orcl11204/system01.dbf
destination for restore of datafile 00002: /refresh/home/app/11.2.0.4/oracle/oradata/orcl11204/sysaux01.dbf
destination for restore of datafile 00003: /refresh/home/app/11.2.0.4/oracle/oradata/orcl11204/undotbs01.dbf
destination for restore of datafile 00004: /refresh/home/app/11.2.0.4/oracle/oradata/orcl11204/users01.dbf
channel ORA_DISK_1: reading from backup piece /refresh/home/bak03/0dvrbklc_1_1
channel ORA_DISK_1: piece handle=/refresh/home/bak03/0dvrbklc_1_1 tag=TAG20210403T071555
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
 
starting media recovery
 
unable to find archived log
archived log thread=1 sequence=1
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 04/03/2021 07:30:20
RMAN-06054: media recovery requesting unknown archived log for thread 1 with sequence 1 and starting SCN of 991848
 
RMAN>

结果仍然没有改变。通过 SQL ,看看 vdatafile,和 vdataile_header,可以看出问题来:

代码语言:javascript
代码运行次数:0
复制
SQL> alter session set nls_date_format='yyyymmdd_hh24:mi:ss';
 
Session altered.
 
SQL> select file#,checkpoint_change#,checkpoint_time from v$datafile;
 
     FILE# CHECKPOINT_CHANGE# CHECKPOINT_TIME
---------- ------------------ -----------------
         1             991822 20210403_07:07:18 ***
         2             991822 20210403_07:07:18 ***
         3             991822 20210403_07:07:18 ***
         4             991822 20210403_07:07:18 ***
 
SQL>
 
SQL> select file#,checkpoint_change#,checkpoint_time from v$datafile_header;
 
     FILE# CHECKPOINT_CHANGE# CHECKPOINT_TIME
---------- ------------------ -----------------
         1             992322 20210403_07:15:56
         2             992322 20210403_07:15:56
         3             992322 20210403_07:15:56
         4             992322 20210403_07:15:56
 
SQL>

vdatafile 反映的是 controlfile 中的结果,而 vdatafile_header 反映的是数据文件中的实际情况。虽然,我每一次的 recover database 都改变了 datafile,但是由于我已经执行过了 restore database,数据库就以执行 restore database 时,它的控制文件中记录的内容,来决定要哪些 archive log。没办法了,只好注册所有的 archive log, 再次执行 recover database。

代码语言:javascript
代码运行次数:0
复制
RMAN> catalog start with '/refresh/home/arc';
 
using target database control file instead of recovery catalog
searching for all files that match the pattern /refresh/home/arc
 
List of Files Unknown to the Database
=====================================
File Name: /refresh/home/arc/arch1_2_1068879009.dbf
File Name: /refresh/home/arc/arch1_7_1068879009.dbf
File Name: /refresh/home/arc/arch1_5_1068879009.dbf
File Name: /refresh/home/arc/arch1_4_1068879009.dbf
File Name: /refresh/home/arc/arch1_3_1068879009.dbf
File Name: /refresh/home/arc/arch1_1_1068879009.dbf
File Name: /refresh/home/arc/arch1_6_1068879009.dbf
 
Do you really want to catalog the above files (enter YES or NO)? yes
cataloging files...
cataloging done
 
List of Cataloged Files
=======================
File Name: /refresh/home/arc/arch1_2_1068879009.dbf
File Name: /refresh/home/arc/arch1_7_1068879009.dbf
File Name: /refresh/home/arc/arch1_5_1068879009.dbf
File Name: /refresh/home/arc/arch1_4_1068879009.dbf
File Name: /refresh/home/arc/arch1_3_1068879009.dbf
File Name: /refresh/home/arc/arch1_1_1068879009.dbf
File Name: /refresh/home/arc/arch1_6_1068879009.dbf
 
RMAN> list archivelog all;
 
List of Archived Log Copies for database with db_unique_name ORCL11204
=====================================================================
 
Key     Thrd Seq     S Low Time
------- ---- ------- - -----------------
8       1    1       A 20210403_06:50:09
        Name: /refresh/home/arc/arch1_1_1068879009.dbf
 
3       1    2       A 20210403_07:10:22
        Name: /refresh/home/arc/arch1_2_1068879009.dbf
 
7       1    3       A 20210403_07:10:28
        Name: /refresh/home/arc/arch1_3_1068879009.dbf
 
6       1    4       A 20210403_07:13:37
        Name: /refresh/home/arc/arch1_4_1068879009.dbf
 
5       1    5       A 20210403_07:13:41
        Name: /refresh/home/arc/arch1_5_1068879009.dbf
 
9       1    6       A 20210403_07:16:41
        Name: /refresh/home/arc/arch1_6_1068879009.dbf
 
4       1    7       A 20210403_07:16:46
        Name: /refresh/home/arc/arch1_7_1068879009.dbf
 
 
RMAN> recover database;
 
Starting recover at 20210403_07:37:40
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=19 device type=DISK
 
starting media recovery
 
archived log for thread 1 with sequence 1 is already on disk as file /refresh/home/arc/arch1_1_1068879009.dbf
archived log for thread 1 with sequence 2 is already on disk as file /refresh/home/arc/arch1_2_1068879009.dbf
archived log for thread 1 with sequence 3 is already on disk as file /refresh/home/arc/arch1_3_1068879009.dbf
archived log for thread 1 with sequence 4 is already on disk as file /refresh/home/arc/arch1_4_1068879009.dbf
archived log for thread 1 with sequence 5 is already on disk as file /refresh/home/arc/arch1_5_1068879009.dbf
archived log for thread 1 with sequence 6 is already on disk as file /refresh/home/arc/arch1_6_1068879009.dbf
archived log for thread 1 with sequence 7 is already on disk as file /refresh/home/arc/arch1_7_1068879009.dbf
archived log file name=/refresh/home/arc/arch1_1_1068879009.dbf thread=1 sequence=1
archived log file name=/refresh/home/arc/arch1_2_1068879009.dbf thread=1 sequence=2
archived log file name=/refresh/home/arc/arch1_3_1068879009.dbf thread=1 sequence=3
archived log file name=/refresh/home/arc/arch1_4_1068879009.dbf thread=1 sequence=4
archived log file name=/refresh/home/arc/arch1_5_1068879009.dbf thread=1 sequence=5
archived log file name=/refresh/home/arc/arch1_6_1068879009.dbf thread=1 sequence=6
archived log file name=/refresh/home/arc/arch1_7_1068879009.dbf thread=1 sequence=7
unable to find archived log
archived log thread=1 sequence=8
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 04/03/2021 07:37:41
RMAN-06054: media recovery requesting unknown archived log for thread 1 with sequence 8 and starting SCN of 992471
 
RMAN>
 
 
RMAN> alter database open resetlogs;
 
database opened
 
RMAN>
 
 
SQL> alter session set nls_date_format='yyyymmdd_hh24:mi:ss';
 
Session altered.
 
SQL> select file#,checkpoint_change#,checkpoint_time from v$datafile;
 
     FILE# CHECKPOINT_CHANGE# CHECKPOINT_TIME
---------- ------------------ -----------------
         1             992475 20210403_07:38:25
         2             992475 20210403_07:38:25
         3             992475 20210403_07:38:25
         4             992475 20210403_07:38:25
 
SQL> select file#,checkpoint_change#,checkpoint_time from v$datafile_header;
 
     FILE# CHECKPOINT_CHANGE# CHECKPOINT_TIME
---------- ------------------ -----------------
         1             992475 20210403_07:38:25
         2             992475 20210403_07:38:25
         3             992475 20210403_07:38:25
         4             992475 20210403_07:38:25
 
SQL>

我真的失败了吗?其实也没有,只要我保留最新的控制文件,再来多次执行 recover database, 不就可以成功了吗?换句话说,在两个机器之间,我执行最后一次 recover 之前,我把 source 端的控制文件备份出来,恢复到 dest 端,由于它包含了全部的备份新,我再执行 recover ,应该可以成功的。

请拭目以待我的下一次两个机器之间的备份恢复试验。

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2021-04-26,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 SQL和数据库技术 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档