Oracle中的B树索引

B树索引是Oracle的默认的索引类型。因为表中的行标识符(rowid)和相关的列值存储在一个平衡的树状结构的索引块中,所以该索引类型被称为B树索引。使用Oracle的B树索引有以下几个原因.
.提高SQL语句的性能
.强制执行主键和唯一键约束的唯一性
.减少通过主键和外键约束关联的父表和子表间潜在的锁定问题

Oracle如何使用B树索引
为了充分理解B树索引的内部实现,以便在建立数据库应用程序时能做出明智的索引决定。将举例说明,首先创建测试表cust

SQL> create table cust(
  2  cust_id number,
  3  last_name varchar2(30),
  4  first_name varchar2(30));

Table created.

在last_name列上创建B树索引

SQL> create index cust_idx1 on cust(last_name);

Index created.

向表cust中插入数据

SQL> insert into cust(cust_id,last_name,first_name)
  2  select rownum rn ,a.last_name,a.first_name from hr.employees a
  3  union
  4  select rownum+(107*1) rn ,a.last_name,a.first_name from hr.employees a
  5  union
  6  select rownum+(107*2) rn ,a.last_name,a.first_name from hr.employees a
  7  union
  8  select rownum+(107*4) rn ,a.last_name,a.first_name from hr.employees a
  9  union
 10  select rownum+(107*5) rn ,a.last_name,a.first_name from hr.employees a
 11  union
 12  select rownum+(107*6) rn ,a.last_name,a.first_name from hr.employees a
 13  union
 14  select rownum+(107*7) rn ,a.last_name,a.first_name from hr.employees a
 15  union
 16  select rownum+(107*8) rn ,a.last_name,a.first_name from hr.employees a
 17  union
 18  select rownum+(107*9) rn ,a.last_name,a.first_name from hr.employees a
 19  union
 20  select rownum+(107*10) rn ,a.last_name,a.first_name from hr.employees a;

1070 rows created.

SQL> commit;

Commit complete.

SQL> select distinct last_name,first_name from cust where rownum<11;

LAST_NAME                      FIRST_NAME
------------------------------ ------------------------------
Austin                         David
Banda                          Amit
Atkinson                       Mozhe
Bissot                         Laura
Ande                           Sundar
Bates                          Elizabeth
Bell                           Sarah
Bernstein                      David
Baer                           Hermann
Baida                          Shelli

10 rows selected.

插入数据后,确保该表的统计信息是最新的,以便为查询优化器提供足够的信息,从而做出如何检索数据的更好决定,执行如下命令收集表的统计信息:

SQL> exec dbms_stats.gather_table_stats(ownname=>'JY',tabname=>'CUST',cascade=>true);

PL/SQL procedure successfully completed.

不建议使用analyze语句(带compute和estimate子句)来收集统计信息。提供此功能只是为了向后兼容。

当向表中插入数据时,Oracle将分配由物理数据库块组成的区。Oracle还将为索引分配数据块。对于每个插入到表中的记录,Oracle还将创建一个包含rowid和列值的索引条目(本例中是rowid和last_name列的值)。每个索引项的rowid指向存储该表的列值的数据文件和数据块号。

当从一个表及其对应的索引选择数据时,存在三种情况。
.SQL查询所需的所有表的数据都在索引结构中。因此,只需要访问索引块。不需要从表中读取数据块。
.查询所需的所有信息没有都包含在索引块中。因此,查询优化器选择既访问索引块也要访问表块来检索需要的数据,以满足查询条件。
.查询优化器选择不访问索引。因此只访问表块。

场景1.所有的数据位于索引块中
这里将介绍两种情况。在每种情况下,执行查询需要的所有数据,包括返回给用户的数据,以及在where子句中被评估的数据,都位于该索引中。
.索引范围扫描(index range scan):如果优化器确定它使用索引结构检索查询所需的多个行时是有效的,那么就使用这种扫描。索引范围扫描被广泛用于各种各样的情况。

.索引快速全扫描(index fast full scan):如果优化器确定表中的大部分行需要进行检索,那么就使用这种扫描。但所有需要的信息都存储在索引中。由于索引结构通常比表结构小,优化器确定全索引扫描(比全表扫描)更高效。这种情况对统计(count)值的查询是很常见的。

首先演示的是索引范围扫描。在这种情况下,运行下面的查询:

select last_name from cust where last_name='Austin';

为了在该查询中返回数据,Oracle最小需要读取多少块,也就是说为了满足此查询,访问物理块最有效的方式是什么,优化器可以选择读取表结构的每个块。然而,这会导致很大的IO开销,因此,它不是检索数据的最优化方法。

对于这个例子,检索数据最有效的方法是使用索引结构。要返回包含last_name列中值为Austin的行,Oracle将需要读取3个索引块。通过使用Oracle的autotrace(自动跟踪)实用程序,可以确认。

SQL> set autotrace on
SQL> select last_name from cust where last_name='Austin';

LAST_NAME
------------------------------
Austin
Austin
Austin
Austin
Austin
Austin
Austin
Austin
Austin
Austin

10 rows selected.


Execution Plan
----------------------------------------------------------
Plan hash value: 3472749082

------------------------------------------------------------------------------
| Id  | Operation        | Name      | Rows  | Bytes | Cost (%CPU)| Time     |
------------------------------------------------------------------------------
|   0 | SELECT STATEMENT |           |    10 |    80 |     1   (0)| 00:00:01 |
|*  1 |  INDEX RANGE SCAN| CUST_IDX1 |    10 |    80 |     1   (0)| 00:00:01 |
------------------------------------------------------------------------------


Predicate Information (identified by operation id):
---------------------------------------------------

   1 - access("LAST_NAME"='Austin')

此输出显示,Oracle只需要使用cust_idx1索引来检索数据,以满足查询的结果集。不需要访问表中的数据块,只需要访问索引块。这对于给定的查询,这是特别高效的索引策略。当索引包含查询所需的所有列值时,它被称为覆盖索引。

下面列出为这个例子使用自动跟踪所显示的统计信息:

Statistics
----------------------------------------------------------
          1  recursive calls
          0  db block gets
          3  consistent gets
          0  physical reads
          0  redo size
        653  bytes sent via SQL*Net to client
        624  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
         10  rows processed

一致获取(consistent gets)的值表示有三个读内存操作。数据库块获取(db block gets)加一致获取等于总的内存读取操作。由于索引块已经在内存中,因此返回此查询的结果集不需要物理读取。此外,有10行进行了处理,这与cust表中last_name为Austin的记录数相符。

下面显示导致执行索引快速全扫描的一个例子。

select count(last_name) from cust;

使用set autotrace on生成执行计划。下面是相应的输出:

SQL> select count(last_name) from cust;

COUNT(LAST_NAME)
----------------
            1070


Execution Plan
----------------------------------------------------------
Plan hash value: 2246355899

-----------------------------------------------------------------------------------
| Id  | Operation             | Name      | Rows  | Bytes | Cost (%CPU)| Time     |
-----------------------------------------------------------------------------------
|   0 | SELECT STATEMENT      |           |     1 |     8 |     3   (0)| 00:00:01 |
|   1 |  SORT AGGREGATE       |           |     1 |     8 |            |          |
|   2 |   INDEX FAST FULL SCAN| CUST_IDX1 |  1070 |  8560 |     3   (0)| 00:00:01 |
-----------------------------------------------------------------------------------

此输出显示,确定表内的计数只用到了索引结构。在这种情况下,优化器确定采取索引快速全扫描比全表扫描更高效。

Statistics
----------------------------------------------------------
         48  recursive calls
          0  db block gets
         91  consistent gets
          0  physical reads
          0  redo size
        559  bytes sent via SQL*Net to client
        624  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
          3  sorts (memory)
          0  sorts (disk)
          1  rows processed


场景2.索引中不包含所有信息
考虑这样一种情况:假设需要从cust表获得更多信息。首先,回顾一下前面的查询语句,并且还要在查询结果中返回first_name列。现在,要获得新增的数据元素,就需要访问表本身。下面是新的查询语句:

select last_name,first_name from cust where last_name='Austin';

使用set autotrace on,并执行前面的查询语句:

SQL> alter system flush buffer_cache;

System altered.

SQL> select last_name,first_name from cust where last_name='Austin';

LAST_NAME                      FIRST_NAME
------------------------------ ------------------------------
Austin                         David
Austin                         David
Austin                         David
Austin                         David
Austin                         David
Austin                         David
Austin                         David
Austin                         David
Austin                         David
Austin                         David

10 rows selected.


Execution Plan
----------------------------------------------------------
Plan hash value: 2100940648

-------------------------------------------------------------------------------------------------
| Id  | Operation                           | Name      | Rows  | Bytes | Cost (%CPU)| Time     |
-------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT                    |           |    10 |   150 |     1   (0)| 00:00:01 |
|   1 |  TABLE ACCESS BY INDEX ROWID BATCHED| CUST      |    10 |   150 |     1   (0)| 00:00:01 |
|*  2 |   INDEX RANGE SCAN                  | CUST_IDX1 |    10 |       |     1   (0)| 00:00:01 |
-------------------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   2 - access("LAST_NAME"='Austin')

此输出信息指示,cust_idx1索引是通过一次索引范围扫描(index range scan)访问的。索引范围扫描标识出满足此查询结果所需的索引块。此外,表是过table access by index rowid batched来读取的。通过索引的rowid访问表,表示Oracle利用存储在索引中的rowid找到表块包含的相应行。把rowid映射到相应的表块,这些块中含有last_name值为Austin的数据。由于我们清空了buffer cache了,这样查询共执行了6次物理读取,9次内存读取。

Statistics
----------------------------------------------------------
          0  recursive calls
          0  db block gets
          9  consistent gets
          6  physical reads
          0  redo size
        896  bytes sent via SQL*Net to client
        624  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
         10  rows processed

场景3.只有表块被访问
在某些情况下,即使有索引存在,Oracle也会确定只使用表块比通过索引访问更为有效。当Oracle检查表内的每一行时,这被称为全表扫描。
例如,执行此查询:

SQL> select * from cust;

下面是相应的执行计划和统计信息:

Execution Plan
----------------------------------------------------------
Plan hash value: 260468903

--------------------------------------------------------------------------
| Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |
--------------------------------------------------------------------------
|   0 | SELECT STATEMENT  |      |  1070 | 19260 |     3   (0)| 00:00:01 |
|   1 |  TABLE ACCESS FULL| CUST |  1070 | 19260 |     3   (0)| 00:00:01 |
--------------------------------------------------------------------------


Statistics
----------------------------------------------------------
        204  recursive calls
          9  db block gets
        389  consistent gets
         20  physical reads
       1080  redo size
      38869  bytes sent via SQL*Net to client
       1405  bytes received via SQL*Net from client
         73  SQL*Net roundtrips to/from client
         33  sorts (memory)
          0  sorts (disk)
       1070  rows processed

此输出显示,需要一致读取(consistent gets)389个块以及数据库块获取(db block gets)9个块和物理读取20个块。Oracle检索表中的每一行以返回满足查询所需的结果。在这种情况下,必须读取表中已使用的所有块,Oracle无法使用索引来加快数据检索。

DM7使用DMRAMN执行备份集恢复

使用DMRAMN执行备份集恢复
使用RECOVER命令完成数据库恢复工作,可以是基于备份集的恢复工作,也可以是使用本地归档日志的恢复工作。如果还原后,数据已经处于一致性状态了,则可以使用更新DB_MAGIC方式恢复,前提是不需要重做日志。语法如下:

RECOVER DATABASE '' []
[USE DB_MAGIC ] [UNTIL TIME '< 时间串>'] [UNTIL LSN ]; |
RECOVER DATABASE '' FROM BACKUPSET '< 备份集目录>'[DEVICE TYPE DISK|TAPE[PARMS '< 介质参数>']] [IDENTIFIED BY
< 密码> [ENCRYPT WITH < 加密算法>]]
; |
RECOVER DATABASE '' UPDATE DB_MAGIC;
 ::=
WITH ARCHIVEDIR '< 归档日志目录>'{,'< 归档日志目录>'}

DATABASE:指定还原库目标的dm.ini文件路径。
USE DB_MAGIC:指定本地归档日志对应数据库的DB_MAGIC,若不指定,则默认使用目标恢复数据库的DB_MAGIC。
UNTIL TIME:恢复数据库到指定的时间点。
UNTIL LSN:恢复数据库到指定的LSN。
BACKUPSET:指定用于还原目标数据库的备份集目录。
DEVICE TYPE:指存储备份集的介质类型,支持DISK和TAPE,默认为DISK。DISK表示存储备份集到磁盘,TAPE表示存储到磁带。
PARMS:介质参数,供第三方存储介质(TAPE类型)管理使用。
IDENTIFIED BY:指定备份时使用的加密密码,供还原过程解密使用。
ENCRYPT WITH:指定备份时使用的加密算法,供还原过程解密使用,若未指定,则使用默认算法。
WITH ARCHIVEDIR:本地归档日志搜索目录,若未指定,则仅使用目标库配置本地归档目录,RAC环境还会取REMOTE归档目录。

数据库恢复有三种方式:更新DB_MAGIC恢复、从备份集恢复和从归档恢复。

从备份集恢复
如果备份集在备份过程中生成了日志,且这些日志在备份集中有完整备份(如联机数据库备份),在执行数据库还原后,可以重做备份集中备份的日志,将数据库恢复到备份时的状态,即从备份集恢复。完整的示例如下:
1) 启动DIsql联机备份数据库。

SQL> backup database full to db_full_bak_recover_bakset backupset '/dm_home/dmdba/dmdbms/data/jydm/bak/db_full_bak_recover_bakset_backupset';
executed successfully
used time: 00:00:07.673. Execute id is 247.
SQL> select permanent_magic;

LINEID     PERMANENT_MAGIC
---------- ---------------
1          1250320462

used time: 48.106(ms). Execute id is 282.
SQL> select db_magic from v$rlog;

LINEID     DB_MAGIC
---------- -----------
1          708657636

used time: 37.277(ms). Execute id is 315.

2) 准备目标库,可以使用备份库,也可以重新生成库。这里是在别一台服务器上创建新库,重新生成库操作如下:

[dmdba@dmks ~]$ dminit path=/dm_home/dmdbms/data db_name=dameng_for_recover auto_overwrite=1 port_num=5336
initdb V7.1.6.46-Build(2018.02.08-89107)ENT
db version: 0x7000a
file dm.key not found, use default license!
License will expire in 14 day(s) on 2020-06-30

 log file path: /dm_home/dmdbms/data/dameng_for_recover/dameng_for_recover01.log


 log file path: /dm_home/dmdbms/data/dameng_for_recover/dameng_for_recover02.log

write to dir [/dm_home/dmdbms/data/dameng_for_recover].
create dm database success. 2020-06-16 16:03:18


[root@dmks root]# ./dm_service_installer.sh  -i /dm_home/dmdbms/data/dameng_for_recover/dm.ini -p dmrc -t dmserver
Move the service script file(/dm_home/dmdbms/bin/DmServicedmrc to /etc/rc.d/init.d/DmServicedmrc)
Finished to create the service (DmServicedmrc)

[root@dmks root]# service DmServicedmrc start
Starting DmServicedmrc: [ OK ]


[dmdba@dmks ~]$ disql SYSDBA/SYSDBA@localhost:5336

Server[localhost:5336]:mode is normal, state is open
login used time: 10.727(ms)
disql V7.1.6.46-Build(2018.02.08-89107)ENT
Connected to: DM 7.1.6.46
SQL> select permanent_magic;

LINEID     PERMANENT_MAGIC
---------- ---------------
1          450923536

used time: 1.042(ms). Execute id is 5.
SQL> select db_magic from v$rlog;

LINEID     DB_MAGIC
---------- -----------
1          1009602608

used time: 1.332(ms). Execute id is 6.

3)将备份集复制到目标库所在主机上

[dmdba@shard1 bak]$ scp -r db_full_bak_recover_bakset_backupset/ dmdba@10.138.130.187:/dm_home/dmdbms/backup/
dmdba@10.138.130.187's password:
db_full_bak_recover_bakset_backupset.bak                                                                                                                                                                  100%  211MB 105.3MB/s   00:02
db_full_bak_recover_bakset_backupset_1.bak                                                                                                                                                                100%  225KB 225.0KB/s   00:00
db_full_bak_recover_bakset_backupset.meta                                                                                                                                                                 100%   93KB  92.5KB/s   00:00
[dmdba@shard1 bak]$

4)启动RMAN,校验备份。

RMAN> check backupset '/dm_home/dmdbms/backup/db_full_bak_recover_bakset_backupset';
check backupset '/dm_home/dmdbms/backup/db_full_bak_recover_bakset_backupset';
CMD END.CODE:[0]
check backupset successfully.
time used: 6.293(ms)

5)还原数据库。

RMAN> restore database '/dm_home/dmdbms/data/dameng_for_recover/dm.ini' from backupset '/dm_home/dmdbms/backup/db_full_bak_recover_bakset_backupset';
restore database '/dm_home/dmdbms/data/dameng_for_recover/dm.ini' from backupset '/dm_home/dmdbms/backup/db_full_bak_recover_bakset_backupset';
checking if the database under system path [/dm_home/dmdbms/data/dameng_for_recover] is running...[4].
checking if the database under system path [/dm_home/dmdbms/data/dameng_for_recover] is running...[3].
checking if the database under system path [/dm_home/dmdbms/data/dameng_for_recover] is running...[2].
checking if the database under system path [/dm_home/dmdbms/data/dameng_for_recover] is running...[1].
checking if the database under system path [/dm_home/dmdbms/data/dameng_for_recover] is running...[0].
checking if the database under system path [/dm_home/dmdbms/data/dameng_for_recover] is running, write dmrman info.
RESTORE DATABASE  CHECK......
RESTORE DATABASE , dbf collect......
RESTORE DATABASE , dbf refresh ......
RESTORE BACKUPSET [/dm_home/dmdbms/backup/db_full_bak_recover_bakset_backupset] START......
total 22 packages processed...
RESTORE DATABASE , UPDATE ctl file......
RESTORE DATABASE , REBUILD key file......
RESTORE DATABASE , CHECK db info......
RESTORE DATABASE , UPDATE db info......
total 24 packages processed!
CMD END.CODE:[0]
restore successfully.
time used: 29564.812(ms)

6)恢复数据库。

RMAN> recover database '/dm_home/dmdbms/data/dameng_for_recover/dm.ini' from backupset '/dm_home/dmdbms/backup/db_full_bak_recover_bakset_backupset';
recover database '/dm_home/dmdbms/data/dameng_for_recover/dm.ini' from backupset '/dm_home/dmdbms/backup/db_full_bak_recover_bakset_backupset';
checking if the database under system path [/dm_home/dmdbms/data/dameng_for_recover] is running...[4].
checking if the database under system path [/dm_home/dmdbms/data/dameng_for_recover] is running...[3].
checking if the database under system path [/dm_home/dmdbms/data/dameng_for_recover] is running...[2].
checking if the database under system path [/dm_home/dmdbms/data/dameng_for_recover] is running...[1].
checking if the database under system path [/dm_home/dmdbms/data/dameng_for_recover] is running...[0].
checking if the database under system path [/dm_home/dmdbms/data/dameng_for_recover] is running, write dmrman info.
EP[0] max_lsn: 19945240
RESTORE RLOG  CHECK......
RESTORE RLOG ,gen tmp file......
RESTORE RLOG FROM BACKUPSET [/dm_home/dmdbms/backup/db_full_bak_recover_bakset_backupset] START......
total 0 packages processed...
total 2 packages processed!
CMD END.CODE:[0]

EP[0] Recover LSN from 19945241 to 19947077.
Recover from archive log finished, time used:0.322s.
recover successfully!
time used: 7027.238(ms)

7)检查db_magic,db_maigc从708657636变成了1572156104

[root@dmks init.d]# service DmServicedmrc start
Starting DmServicedmrc: [ OK ]

[dmdba@dmks ~]$ disql SYSDBA/xxzx7817600@localhost:5336

Server[localhost:5336]:mode is normal, state is open
login used time: 12.530(ms)
disql V7.1.6.46-Build(2018.02.08-89107)ENT
Connected to: DM 7.1.6.46
SQL> select permanent_magic;

LINEID     PERMANENT_MAGIC
---------- ---------------
1          1250320462

used time: 1.288(ms). Execute id is 4.
SQL> select db_magic from v$rlog;

LINEID     DB_MAGIC
---------- -----------
1          1572156104

used time: 1.845(ms). Execute id is 5.

8)检查数据

SQL>  select * from t1;

LINEID     ID          NAME
---------- ----------- ----
1          1           jy
2          2           hy

used time: 1.286(ms). Execute id is 5.

DM7使用DMRAMN执行更新DB_MAGIC恢复

使用DMRAMN执行更新DB_MAGIC恢复
使用RECOVER命令完成数据库恢复工作,可以是基于备份集的恢复工作,也可以是使用本地归档日志的恢复工作。如果还原后,数据已经处于一致性状态了,则可以使用更新DB_MAGIC方式恢复,前提是不需要重做日志。语法如下:

RECOVER DATABASE '' []
[USE DB_MAGIC ] [UNTIL TIME '< 时间串>'] [UNTIL LSN ]; |
RECOVER DATABASE '' FROM BACKUPSET '< 备份集目录>'[DEVICE TYPE DISK|TAPE[PARMS '< 介质参数>']] [IDENTIFIED BY
< 密码> [ENCRYPT WITH < 加密算法>]]
; |
RECOVER DATABASE '' UPDATE DB_MAGIC;
 ::=
WITH ARCHIVEDIR '< 归档日志目录>'{,'< 归档日志目录>'}

DATABASE:指定还原库目标的dm.ini文件路径。
USE DB_MAGIC:指定本地归档日志对应数据库的DB_MAGIC,若不指定,则默认使用目标恢复数据库的DB_MAGIC。
UNTIL TIME:恢复数据库到指定的时间点。
UNTIL LSN:恢复数据库到指定的LSN。
BACKUPSET:指定用于还原目标数据库的备份集目录。
DEVICE TYPE:指存储备份集的介质类型,支持DISK和TAPE,默认为DISK。DISK表示存储备份集到磁盘,TAPE表示存储到磁带。
PARMS:介质参数,供第三方存储介质(TAPE类型)管理使用。
IDENTIFIED BY:指定备份时使用的加密密码,供还原过程解密使用。
ENCRYPT WITH:指定备份时使用的加密算法,供还原过程解密使用,若未指定,则使用默认算法。
WITH ARCHIVEDIR:本地归档日志搜索目录,若未指定,则仅使用目标库配置本地归档目录,RAC环境还会取REMOTE归档目录。

数据库恢复有三种方式:更新DB_MAGIC恢复、从备份集恢复和从归档恢复,

更新DB_MAGIC恢复
当备份集为脱机备份即备份过程中无日志生成,那么此时还原后的数据库中数据与备份时数据状态一致。在不需要重做归档日志恢复数据的情况下,可以直接更新DB_MAGIC完成数据库恢复。完整的示例如下:

1) 启动RMAN备份数据库,保证服务器处于脱机状态。

RMAN> backup database '/dm_home/dmdba/dmdbms/data/jydm/dm.ini' full backupset '/dm_home/dmdba/dmdbms/data/jydm/bak/db_full_bak_recover_dbmagic';
backup database '/dm_home/dmdba/dmdbms/data/jydm/dm.ini' full backupset '/dm_home/dmdba/dmdbms/data/jydm/bak/db_full_bak_recover_dbmagic';
file dm.key not found, use default license!
checking if the database under system path [/dm_home/dmdba/dmdbms/data/jydm] is running...[4].
checking if the database under system path [/dm_home/dmdba/dmdbms/data/jydm] is running...[3].
checking if the database under system path [/dm_home/dmdba/dmdbms/data/jydm] is running...[2].
checking if the database under system path [/dm_home/dmdba/dmdbms/data/jydm] is running...[1].
checking if the database under system path [/dm_home/dmdba/dmdbms/data/jydm] is running...[0].
checking if the database under system path [/dm_home/dmdba/dmdbms/data/jydm] is running, write dmrman info.
EP[0] max_lsn: 19945240
BACKUP DATABASE [jydm], execute......
CMD CHECK LSN......
BACKUP DATABASE [jydm], collect dbf......
CMD CHECK ......
DBF BACKUP SUBS......
total 1 packages processed...
total 7 packages processed...
total 13 packages processed...
total 14 packages processed...
total 15 packages processed...
total 16 packages processed...
total 21 packages processed...
total 22 packages processed...
DBF BACKUP MAIN......
BACKUPSET [/dm_home/dmdba/dmdbms/data/jydm/bak/db_full_bak_recover_dbmagic] END, CODE [0]......
META GENERATING......
total 26 packages processed...
total 26 packages processed!
CMD END.CODE:[0]
backup successfully!
time used: 15113.537(ms)

RMAN> show backupset '/dm_home/dmdba/dmdbms/data/jydm/bak/db_full_bak_recover_dbmagic';
show backupset '/dm_home/dmdba/dmdbms/data/jydm/bak/db_full_bak_recover_dbmagic';




system path:           /dm_home/dmdba/dmdbms/data/jydm
db magic:              708657636
permanent magic:       1250320462
rac node:              1
page check:            0
rlog encrypt:          0
external cipher[id/name]:  0/
external hash[id/name]:  0/
length in char:        0
use new hash:          1
page size:             8 KB
extent size:           16
case sensitive:        1
log page size:         512 B
unicode_flag/charset:  0
data version:          0x7000A
sys version:           V7.1.6.46-Build(2018.02.08-89107)ENT
enable policy:         0
archive flag:          1
blank_pad_mode:        0
crc_check:             TRUE
backupset sig:         BA
backupset version:     4009
database name:         jydm
backup name:           DB_FULL_jydm_20200617_192816_000091
backupset description:
backupset ID :         -1041017958
parent backupset ID:     -1
META file size :       86528
compressed level:      0
encrypt type:          0
parallel num:          1
backup range:          database
mpp_timestamp:         1592393290
ddl_clone:             FALSE
mpp_flag:              FALSE
backup level:          offline
backup type:           full
without log:           FALSE
START_LSN:             19945241
START_SEQ:             7798402
END_LSN:               19945240
END_SEQ:               7798401
base START_LSN:        -1
base END_LSN:          -1
base name:
base backupset:
backup time:           2020-06-17 19:28:25
min trx start lsn:     19945241
min exec ver:          0x0701060C
pkg size:              0x02000000


backupset directory: /dm_home/dmdba/dmdbms/data/jydm/bak/db_full_bak_recover_dbmagic
backupset name:        db_full_bak_recover_dbmagic
backup data file num:  8
backup piece num:      1


$file_seq |$size(KB) |$pos_desc                                               |$content_type
0         |205431    |db_full_bak_recover_dbmagic.bak                         |DATA


$file_seq |$group_id |$group_name                      |$file_id  |$file_path                       |$mirror_path                     |$file_len
1         |0         |SYSTEM                           |0         |/dm_home/dmdba/dmdbms/data/jydm/SYSTEM.DBF|                                 |24117248
2         |1         |ROLL                             |0         |/dm_home/dmdba/dmdbms/data/jydm/ROLL.DBF|                                 |208666624
3         |4         |MAIN                             |0         |/dm_home/dmdba/dmdbms/data/jydm/MAIN.DBF|                                 |197132288
4         |5         |BOOKSHOP                         |0         |/dm_home/dmdba/dmdbms/data/jydm/BOOKSHOP.DBF|                                 |157286400
5         |6         |DMHR                             |0         |/dm_home/dmdba/dmdbms/data/jydm/DMHR.DBF|                                 |134217728
6         |7         |USERS                            |0         |/dm_home/dmdba/dmdbms/data/jydm/users01.dbf|                                 |52428800
7         |9         |SYSAUX                           |0         |/dm_home/dmdba/dmdbms/data/jydm/SYSAWR.DBF|                                 |176160768
8         |10        |FG_PERSON                        |0         |/dm_home/dmdba/dmdbms/data/jydm/FG_PERSON.DBF|                                 |134217728


$file_seq |$file_path                       |$file_len           |$begin_lsn          |$begin_seqno        |$begin_rpag_off     |$end_lsn            |$end_seqno          |$create_time        |$close_time


show backupsets successfully.
time used: 3.792(ms)

将源库的数据库备份集传输到目标主机上

[dmdba@shard1 bak]$ scp -r db_full_bak_recover_dbmagic/ dmdba@10.13.13.187:/dm_home/dmdbms/backup/
dmdba@10.13.13.187's password:
db_full_bak_recover_dbmagic.bak                                                                                                                                                                           100%  201MB 100.3MB/s   00:02
db_full_bak_recover_dbmagic.meta                                                                                                                                                                          100%   85KB  84.5KB/s   00:00
[dmdba@shard1 bak]$

2) 准备目标库,可以使用备份库,也可以重新生成库。这里是在别一台服务器上创建新库,重新生成库操作如下:

./dminit path=/opt/dmdbms/data db_name=DAMENG_FOR_RESTORE auto_overwrite=1

但我这里目标库就是源库

3) 校验备份。

RMAN> check backupset '/dm_home/dmdbms/backup/db_full_bak_recover_dbmagic';
check backupset '/dm_home/dmdbms/backup/db_full_bak_recover_dbmagic';
CMD END.CODE:[0]
check backupset successfully.
time used: 6.093(ms)

4) 还原数据库。

RMAN> restore database '/dm_home/dmdbms/data/dameng_for_recover/dm.ini' from backupset '/dm_home/dmdbms/backup/db_full_bak_recover_dbmagic';
restore database '/dm_home/dmdbms/data/dameng_for_recover/dm.ini' from backupset '/dm_home/dmdbms/backup/db_full_bak_recover_dbmagic';
file dm.key not found, use default license!
checking if the database under system path [/dm_home/dmdbms/data/dameng_for_recover] is running...[4].
checking if the database under system path [/dm_home/dmdbms/data/dameng_for_recover] is running...[3].
checking if the database under system path [/dm_home/dmdbms/data/dameng_for_recover] is running...[2].
checking if the database under system path [/dm_home/dmdbms/data/dameng_for_recover] is running...[1].
checking if the database under system path [/dm_home/dmdbms/data/dameng_for_recover] is running...[0].
checking if the database under system path [/dm_home/dmdbms/data/dameng_for_recover] is running, write dmrman info.
RESTORE DATABASE  CHECK......
RESTORE DATABASE , dbf collect......
RESTORE DATABASE , dbf refresh ......
RESTORE BACKUPSET [/dm_home/dmdbms/backup/db_full_bak_recover_dbmagic] START......
total 22 packages processed...
RESTORE DATABASE , UPDATE ctl file......
RESTORE DATABASE , REBUILD key file......
RESTORE DATABASE , CHECK db info......
RESTORE DATABASE , UPDATE db info......
total 24 packages processed!
CMD END.CODE:[0]
restore successfully.
time used: 49968.844(ms)

5) 恢复数据库。

RMAN> recover database '/dm_home/dmdbms/data/dameng_for_recover/dm.ini' update db_magic;
recover database '/dm_home/dmdbms/data/dameng_for_recover/dm.ini' update db_magic;
checking if the database under system path [/dm_home/dmdbms/data/dameng_for_recover] is running...[4].
checking if the database under system path [/dm_home/dmdbms/data/dameng_for_recover] is running...[3].
checking if the database under system path [/dm_home/dmdbms/data/dameng_for_recover] is running...[2].
checking if the database under system path [/dm_home/dmdbms/data/dameng_for_recover] is running...[1].
checking if the database under system path [/dm_home/dmdbms/data/dameng_for_recover] is running...[0].
checking if the database under system path [/dm_home/dmdbms/data/dameng_for_recover] is running, write dmrman info.
EP[0] max_lsn: 19945240
recover successfully!
time used: 7041.721(ms)

6)检查db_magic值,可以确定在没有指定update db_magic选项时其实也是更新了db_maigc值。db_maigc值从708657636变成了-616506144

[root@dmks init.d]# service DmServicedmrc start
Starting DmServicedmrc: [ OK ]

[dmdba@dmks ~]$ disql SYSDBA/xxzx7817600@localhost:5336

Server[localhost:5336]:mode is normal, state is open
login used time: 11.667(ms)
disql V7.1.6.46-Build(2018.02.08-89107)ENT
Connected to: DM 7.1.6.46

SQL> select permanent_magic;

LINEID     PERMANENT_MAGIC
---------- ---------------
1          1250320462

used time: 0.305(ms). Execute id is 5.
SQL> select db_magic from v$rlog;

LINEID     DB_MAGIC
---------- -----------
1          -616506144

used time: 1.948(ms). Execute id is 6.

DM7使用DMRMAN执行数据库还原和恢复

使用DMRMAN执行数据库还原和恢复
下面介绍在数据文件损坏后如何使用DMRMAN还原和恢复数据库,主要内容包括:
1. 数据库还原
2. 数据库恢复

1. 数据库还原
使用RESTORE命令完成脱机还原操作,在还原语句中指定库级备份集,可以是脱机库级备份集,或是联机库级备份集。数据库的还原包括数据库配置文件还原和数据文件还原,目前可能需要还原的数据库配置文件包括dm.ini、dm.ctl、服务器秘钥文件(dm_service.private或者dm_external.config,若备份库指定usbkey加密,则无秘钥文件)、联机日志文件。语法如下:

RESTORE DATABASE  FROM BACKUPSET '< 备份集目录>'
[DEVICE TYPE DISK|TAPE[PARMS '< 介质参数>']]
[IDENTIFIED BY < 密码> [ENCRYPT WITH < 加密算法>]]
[WITH BACKUPDIR '< 基备份集搜索目录>'{,'< 基备份集搜索目录>'}]
[MAPPED FILE '< 映射文件>'][TASK THREAD < 任务线程数>] [NOT PARALLEL]
[RENAME TO '< 数据库名>'];
::=|
::=''[REUSE DMINI][OVERWRITE]
::= TO '' [OVERWRITE]

DATABASE:指定还原库目标的dm.ini文件路径。
BACKUPSET:指定用于还原目标数据库的备份集目录。若指定为相对路径,会在默认备份目录下搜索备份集。
DEVICE TYPE:指存储备份集的介质类型,支持DISK和TAPE,默认为DISK。DISK表示备份集存储介质为磁盘,TAPE表示存储介质为磁带。
PARMS:介质参数,供第三方存储介质(TAPE类型)管理使用。
IDENTIFIED BY:指定备份时使用的加密密码,供还原过程解密使用。
ENCRYPT WITH:指定备份时使用的加密算法,供还原过程解密使用,若未指定,则使用默认算法。
WITH BACKUPDIR:指定备份集搜索目录。
MAPPED FILE:指定存放还原目标路径的文件,参见3.3.5.2.1 数据库还原。当< 备份集目录>和< 映射文件>指定的路径不一致时,以< 映射文件>指定的路径为主
TASK THREAD:指定还原过程中用于处理解压缩和解密任务的线程个数。若未指定,则默认为4;若指定为0,则调整为1;若指定超过当前系统主机核数,则调整为主机核数。
NOT PARALLEL:指定并行备份集使用非并行方式还原。对于非并行备份集,不论是否指定该关键字,均采用非并行还原。
RENAME TO:指定还原数据库后是否更改库的名字,指定时将还原后的库改为指定的数据库名,默认使用备份集中的db_name作为还原后库的名称。

restore_type:
type1:
1>指定dm.ini还原,要求dm.ini中CTL_PATH必须配置正确,且内容有效;若配置CTL_PATH文件故障,且想利用dm.ini优化配置,则可选择type2还原后,用指定dm.ini覆盖还原后dm.ini,并修改CTL_PATH为当前控制文件路径即可;
2>除dm.ini文件外,其他文件均可不存在;但dm.ini参数配置必须正确,且配置的dm.ctl文件必须是有效的控制文件;
3>数据库配置文件中除已经存在的dm.ini外,先删除控制文件中的数据文件,然后根据overwrite选项,若指定overwrite,其他文件(这些文件不在控制文件中,所以未删除)均采用删除重建的处理,避免存在非法的文件,否则如果这些文件已经存在,则报错;
4>若指定REUSE DMINI,则会将备份集中备份的dm.ini中除路径相关的INI参数外,均拷贝到当前dm.ini上。

type2:
1>所有文件均可不在,system_dbf所在路径需为有效路径,若不存在,restore过程中会自动创建;
2>所有前面提到到数据库配置文件均会在指定的system_dbf所在路径还原,但非单机环境中相关其他文件均不修改或者重建,如MPP中dmmpp.ini、dmmal.ini等;
3>若未指定OVERWRITE,若system_dbf所在路径中存在待还原的库配置文件,则报错;若指定,则将已经存在的文件删除重建;
4>由于RAC环境中dm.ini可能存在多个,且可能不在一个主库上,或者即使在一个主库上也可能不在system_dbf所在路径中,故暂时不支持RAC环境的指定目录还原。

联机日志
上述和中的还原后的联机日志文件至少会有两个,因为源库中的日志文件可能大于等于两个,如果小于两个(被误删的情况)的则补齐为两个。已经存在的联机日志配置,使用原路径,若文件大小非法,则使用缺省大小256M重建;缺少的使用缺省命名和缺省大小256M重建。联机日志文件的命名规则:
1>单机:db_name+(file_id+1).log,其中fil_id + 1,占2个位置,如:db_name=DAMENG,则相应的名称为DAMENG01.log,DAMENG02.log;
2>RAC: rac+(ep_no + 1)_+(file_id+1).log,其中ep_no + 1和file_id+1均占2个位置,如0号节点日志名称为rac01_01.log,rac01_02.log。

使用说明:
通过RESTORE命令还原后的数据库不可用,需进一步执行RECOVER命令,将数据库恢复到备份结束时的状态。数据库备份集分为联机和脱机两种类型。通常情况下,用户会在联机的情况下备份数据库,因此下面以联机数据库备份为例说明使用DMRMAN如何执行数据库还原操作。
1) 联机备份数据库,保证数据库运行在归档模式及OPEN状态。

SQL> backup database '/dm7/data/rac0_config/dm.ini' full to db_rac_full_bak_for_restore backupset '/dm7/backup/db_rac_full_bak_for_restore';
executed successfully
used time: 00:00:01.233. Execute id is 4.

2) 准备目标库。还原目标库可以是已经存在的数据库,也可使用dminit工具初始化一个新库。如下所示:

./dminit path=/opt/dmdbms/data db_name=DAMENG_FOR_RESTORE

如果还原目标库与故障库是同一个,建议先执行故障库的归档修复操作。

3) 校验备份,校验待还原备份集的合法性。校验备份有两种方式,联机和脱机,此处使用脱机校验。

RMAN> check backupset '/dm7/backup/db_rac_full_bak_for_restore';
check backupset '/dm7/backup/db_rac_full_bak_for_restore';
CMD END.CODE:[0]
check backupset successfully.
time used: 12.182(ms)
也可以
SQL> select sf_bakset_check('disk','/dm7/backup/db_rac_full_bak_for_restore');

LINEID     SF_BAKSET_CHECK('disk','/dm7/backup/db_rac_full_bak_for_restore')
---------- -----------------------------------------------------------------
1          1

used time: 14.626(ms). Execute id is 6.

4) 还原数据库。启动DMRMAN,输入以下命令:

RMAN> restore database '/dm7/data/rac0_config/dm.ini' from backupset '/dm7/backup/db_rac_full_bak_for_restore';
restore database '/dm7/data/rac0_config/dm.ini' from backupset '/dm7/backup/db_rac_full_bak_for_restore';
file dm.key not found, use default license!
checking if the RAC database under system path [+DMDATA/data/rac] is running....
EP [0] is checking....
[-12000]:The specified instance has been started

需要停止实例

[dmdba@dmrac1 bin]$ dmrman dcr_ini=/dm7/data/dmdcr.ini
dmrman V7.1.6.46-Build(2018.02.08-89107)ENT
RMAN> restore database '/dm7/data/rac0_config/dm.ini' from backupset '/dm7/backup/db_rac_full_bak_for_restore';
restore database '/dm7/data/rac0_config/dm.ini' from backupset '/dm7/backup/db_rac_full_bak_for_restore';
file dm.key not found, use default license!
checking if the RAC database under system path [+DMDATA/data/rac] is running....
EP [0] is checking....
EP [1] is checking....
RESTORE DATABASE  CHECK......
RESTORE DATABASE , dbf collect......
RESTORE DATABASE , dbf refresh ......
RESTORE BACKUPSET [/dm7/backup/db_rac_full_bak_for_restore] START......
total 5 packages processed...
RESTORE DATABASE , UPDATE ctl file......
RESTORE DATABASE , REBUILD key file......
RESTORE DATABASE , CHECK db info......
RESTORE DATABASE , UPDATE db info......
total 9 packages processed!
CMD END.CODE:[0]
restore successfully.
time used: 12542.797(ms)

2. 数据库恢复

RMAN> recover database '/dm7/data/rac0_config/dm.ini';
recover database '/dm7/data/rac0_config/dm.ini';
checking if the RAC database under system path [+DMDATA/data/rac] is running....
EP [0] is checking....
EP [1] is checking....
EP[0] max_lsn: 72473
EP[0] adjust cur_lsn from [72473] to [73980]
EP 0's ckpt_lsn = 72474
min_ckpt_lsn = 72474
The RAC redo archive log 1 ptx
The RAC redo archive log 2 ptx
The RAC redo archive log 3 ptx
The RAC redo archive log 4 ptx
The RAC redo archive log 5 ptx
The RAC redo archive log 6 ptx
The RAC redo archive log 7 ptx
The RAC redo archive log 8 ptx
The RAC redo archive log 9 ptx
The RAC redo archive log 10 ptx
The RAC redo archive log 11 ptx
The RAC redo archive log 12 ptx
The RAC recover total redo 12 ptx
EP(0) slot ctl page(1, 0, 16) trxid = 9882
EP(1) slot ctl page(1, 0, 17) trxid = 8457
EP[0] Recover LSN from 72474 to 73970.
EP[1] Recover LSN from 73981 to 73980.
Recover from archive log finished, time used:0.029s.
recover successfully!
time used: 3246.961(ms)

启动实例

[root@dmrac1 backup]# service DmServicerac1 start
Starting DmServicerac1: [ OK ]

[root@dmrac2 init.d]# service DmServicerac2 start
Starting DmServicerac2: [ OK ]

 

DM7使用DMRMAN工具执行备份集映射文件导出

使用DMRMAN工具执行备份集映射文件导出
备份集映射文件,又称为mapped file。备份集映射文件导出,是备份管理的主要功能,是将备份集中各数据文件的原始路径或者调整后的路径生成到一个本地文件中,可通过关键字MAPPED FILE应用于表空间和库的还原操作中。本节主要对如何将备份集中数据文件路径导出到本地进行描述。内容包括:
1. 概述
2. 备份集映射文件导出

1. 概述
DMRMAN中使用DUMP命令导出映射文件。不支持导出到DMASM文件系统中。语法如下:

DUMP BACKUPSET '< 备份集目录>'
[DEVICE TYPE< 介质类型> [PARMS '< 介质参数>']]
[DATABASE ''|TO'']
MAPPED FILE '< 映射文件路径>';

备份集目录:待导出映射文件的目标备份集,仅支持库级和表空间级备份。
介质类型:指存储备份集的设备类型,暂支持DISK和TAPE。
介质参数:介质类型为TAPE时,第三方介质管理实现所需的参数字符串。
INI_PATH:备份集还原到目标库的INI路径。若指定,则根据INI对应库的系统目录调整数据文件路径;若不指定,则保持备份集中数据文件的原始路径。
SYSTEM_DIR:数据库目录中SYSTEM.DBF数据文件所在目录,作为数据库系统目录处理。

数据文件路径指定INI_PATH或者SYSTEM_DIR调整策略:若指定INI_PATH,则取出配置中SYSTEM_PATH作为数据库系统目录,若指定SYSTEM_DIR,则直接作为数据库系统目录。对于库备份集,与还原过程(2.1.2.1节)中数据库文件路径构造策略描述一致。对于表空间级备份集仅支持原库还原,若指定INI_PATH或者SYSTEM_DIR,则认为需要构造,构造策略与库备份集中数据文件路径构造策略一致。

映射文件路径:输出到本地的目标映射文件路径。用户指定的文件不能为已经存在的文件,否则报错。文件生成之后,允许手动调整数据文件路径到其他路径,真正使用映射文件时,会再次校验。不支持导出到DMASM文件系统中。

2. 导出备份集映射文件
本节举例说明如何使用DMRMAN的DUMP命令导出备份集数据文件路径到映射文件,主要内容包括:
1. 导出原始路径
2. 导出指定INI_PATH调整后的路径

1.导出原始路径
导出备份集中数据文件的原始路径。

RMAN> dump backupset '/dm7/backup/db_rac_bak_2020060901' device type disk mapped file '/dm7/backup/db_rac_bak_2020060901_mapped.txt';
dump backupset '/dm7/backup/db_rac_bak_2020060901' device type disk mapped file '/dm7/backup/db_rac_bak_2020060901_mapped.txt';
dump mapped file successfully.
time used: 10.006(ms)

[dmdba@dmrac1 backup]$ more db_rac_bak_2020060901_mapped.txt
/**************************************************************/
/***  Delete the unnecessary modified groups                 **/
/***  Modify the data_path or mirror_path only in one group  **/
/**************************************************************/

/**=============================================================**/
/*[rac_SYSTEM_FIL_0]*/
fil_id         = 0
ts_id          = 0
ts_name        = SYSTEM
data_path      = +DMDATA/data/rac/system.dbf
mirror_path    =

/**=============================================================**/
/*[rac_ROLL_FIL_0]*/
fil_id         = 0
ts_id          = 1
ts_name        = ROLL
data_path      = +DMDATA/data/rac/roll.dbf
mirror_path    =

/**=============================================================**/
/*[rac_MAIN_FIL_0]*/
fil_id         = 0
ts_id          = 4
ts_name        = MAIN
data_path      = +DMDATA/data/rac/main.dbf
mirror_path    =

/**=============================================================**/
/*[rac_TS_FOR_DBF_FIL_0]*/
fil_id         = 0
ts_id          = 5
ts_name        = TS_FOR_DBF
data_path      = +DMDATA/data/rac/ts_for_dbf_01.dbf
mirror_path    =

/**=============================================================**/
/*[rac_TS_FOR_DBF_FIL_1]*/
fil_id         = 1
ts_id          = 5
ts_name        = TS_FOR_DBF
data_path      = +DMDATA/data/rac/ts_for_dbf_02.dbf
mirror_path    =

/***************************** END ****************************/

2.导出指定INI_PATH调整后的路径
指定INI_PATH,导出调整后的数据文件路径到映射文件。

RMAN> dump backupset '/dm7/backup/db_rac_bak_2020060901' device type disk database '/dm7/data/rac0_config/dm.ini' mapped file '/dm7/backup/db_rac_bak_2020060901_mapped1.txt';
dump backupset '/dm7/backup/db_rac_bak_2020060901' device type disk database '/dm7/data/rac0_config/dm.ini' mapped file '/dm7/backup/db_rac_bak_2020060901_mapped1.txt';
dump mapped file successfully.
time used: 14.793(ms)

DM7使用DMRMAN工具导入备份集

使用DMRMAN工具导入备份集
导入备份集是备份管理的主要功能,下面主要对如何导入备份集进行描述。内容包括:
1. 概述
2. 导入备份集
1. 概述
DMRMAN中使用LOAD命令导入备份集。
语法如下:

LOAD BACKUPSETSFROM DEVICE TYPE< 介质类型> [PARMS '< 介质参数>'][WITH BACKUPDIR '< 备份集搜索目录>'{,'< 备份集搜索目录>'}] TO BACKUPDIR '< 备份集存放目录>';

介质类型:指存储备份集的设备类型,暂支持DISK和TAPE。
介质参数:介质类型为TAPE时,第三方介质管理实现所需的参数字符串。
备份集存放目录:指从TAPE上导出的备份集meta文件存放到本地磁盘的目标目录,要求为空或不存在。

2. 导入备份集
本节举例说明如何使用DMRMAN的LOAD命令导入备份集,主要内容包括:
1. 导出磁盘上备份集
2. 导出磁带上所有的备份集

1.导出磁盘上备份集
导出磁盘上备份集的meta文件。

RMAN>LOAD BACKUPSETS FROM DEVICE TYPE DISK TO BACKUPDIR '/mnt/dm7src/bak_dir';

2.导出磁带上所有的备份集
导出磁带/dev/nst0上所有备份集的meta文件到目录/mnt/hgfs/dm7src/bak_dir。

RMAN>LOAD BACKUPSETS FROM DEVICE TYPE TAPE TO BACKUPDIR '/mnt/hgfs/dm7src/bak_dir';
LOAD BACKUPSETS FROM DEVICE TYPE TAPE TO BACKUPDIR '/mnt/hgfs/dm7src/bak_dir';
load backupsets failed.error code:-10000
[-10000]:[错误码:-20022]磁带打开失败

退出dmrman,设置环境变量TAPE,值为/dev/nst0。

[root@192 debug]# export TAPE=/dev/nst0
[root@192 debug]#echo $TAPE
/dev/nst0

启动dmrman,再次执行:

[root@192 debug]# ./dmrman
dmrman V7.1.3.141-Build(2014.09.09-48301trunc)
RMAN>LOAD BACKUPSETS FROM DEVICE TYPE TAPE TO BACKUPDIR '/mnt/hgfs/dm7src/bak_dir';
LOAD BACKUPSETS FROM DEVICE TYPE TAPE TO BACKUPDIR '/mnt/hgfs/dm7src/bak_dir';
load meta file [SBT_TEST_T-20140909192629000000-4966] to path [/mnt/hgfs/dm7src/bak_dir/0/0.meta]...
load meta file [SBT_TEST_T-20140909192629000000-4966] to path [/mnt/hgfs/dm7src/bak_dir/0/0.meta]...success
load meta file [SBT_TEST_T2-20140909192746000000-9983] to path [/mnt/hgfs/dm7src/bak_dir/1/1.meta]...
load meta file [SBT_TEST_T2-20140909192746000000-9983] to path [/mnt/hgfs/dm7src/bak_dir/1/1.meta]...success
load backupsets successfully.

退出dmrman,查看本地磁盘目录/mnt/hgfs/dm7src/bak_dir:

[root@192 debug]# ls -1 /mnt/hgfs/dm7src/bak_dir
total 0
drwxrwxrwx 1 root root 0 Sep 11 00:23 0
drwxrwxrwx 1 root root 0 Sep 11 00:23 1
[root@192 debug]# ls -1 /mnt/hgfs/dm7src/bak_dir/0
total 12
-rwxrwxrwx 1 root root 24576 Sep 11 00:23 0.meta
[root@192 debug]# ls -1 /mnt/hgfs/dm7src/bak_dir/1
total 12
-rwxrwxrwx 1 root root 24576 Sep 11 00:23 1.meta

DM7使用DMRMAN工具删除备份集

使用DMRMAN工具删除备份集
备份集删除是备份管理的主要功能,下面主要对如何删除备份进行描述。内容包括:
1. 概述
2. 删除备份集

1. 概述
DMRMAN中使用REMOVE命令删除备份集,可删除指定备份集,也可批量删除备份集。单个备份集删除时并行备份中的子备份集不允许单独删除;在指定备份集搜集目录中,发现存在引用目标备份集作为基备份的需要执行级联删除,默认报错。批量删除备份集时,跳过收集到的单独的子备份集。语法如下:

REMOVE BACKUPSET '< 备份集目录>'
[DEVICE TYPE< 介质类型> [PARMS '< 介质参数>']][< database_bakdir_lst_stmt>][CASCADE];
REMOVE [DATABASE | TABLESPACE[] | TABLE ""."" | ARCHIVELOG|ARCHIVE LOG] BACKUPSETS
[]
{[UNTIL TIME '< 截止时间串>'] | [BEFOREn]}
::= DEVICE TYPE< 介质类型> [PARMS '< 介质参数>']
::= DATABASE '' |
WITH BACKUPDIR '< 备份集搜索目录>' {, '< 备份集搜索目录>' } |
DATABASE '' WITH BACKUPDIR '< 备份集搜索目录>' {, '< 备份集搜索目录>' }

BACKUPSET:指定待删除的备份集目录。
DATABASE:指定数据库dm.ini文件路径,若指定,则该数据库的默认备份目录作为备份集搜索目录之一。
DEVICE TYPE:指存储备份集的介质类型,支持DISK和TAPE,默认DISK。DISK表示备份集存储介质磁盘,TAPE表示存储介质为磁带。若未指定,则DISK和TAPE介质上满足条件备份集均会删除。
PARMS:介质类型为TAPE时,第三方介质管理实现所需的参数字符串。
CASCADE:当目标备份集已经被其他备份集引用为基备份集,默认不允许删除,若指定CASCADE,则递归删除所有引用的增量备份。DATABASE|TABLESPACE|TABLE|ARCHIVELOG|ARCHIVE LOG:指定删除备份集的类型,分别为库级、表空间级、表级备份,以及归档级别,其中ARCHVELOG和ARCHIVE LOG等价。若不指定,全部删除。指定TABLESPACE时,若指定目标表空间名,则仅会删除满足条件的指定表空间名称的表空间备份集,否则,删除所有满足条件的表空间级备份集;指定TABLE时,若指定目标表名,则仅会删除满足条件的指定表名的表备份集;否则,删除所有满足条件的表备份集。
UNTIL TIME:删除备份集生成的最大时间,即删除指定时间之前的备份集,若未指定,则删除所有备份集。
BEFOREn:删除距离当前时间前n天产生的备份集;n取值范围0~365,单位:天。
WITH BACKUPDIR:备份集搜索目录,用于搜索指定目录下的所有备份集。

2. 删除备份集
下面举例说明如何使用DMRMAN的REMOVE命令删除备份集,主要内容包括:
1. 删除特定的备份集
2. 批量删除所有备份集
3. 批量删除指定时间之前的备份集

1.删除特定的备份集
使用REMOVE BACKUPSET…命令可删除特定备份集,每次只能删除一个备份集。若删除备份集已经被引用为其他备份集的基备份且未指定CASCADE,则报错。

RMAN> remove backupset '/dm7/backup/db_rac_bak';
remove backupset '/dm7/backup/db_rac_bak';
CMD END.CODE:[0]
remove backupset successfully.
time used: 30.542(ms)

如果备份集在数据库默认备份目录下还可使用以下方式删除备份集:
RMAN> remove backupset 'DB_rac_FULL_20200608_160009_000828';
remove backupset 'DB_rac_FULL_20200608_160009_000828';
CMD END.CODE:[0]
remove backupset successfully.
time used: 57.206(ms)

如果备份集为其他备份集的基备份且备份集都在数据库默认备份目录下还可使用以下方式删除备份集:

RMAN> backup database '/dm7/data/rac0_config/dm.ini' full backupset '/dm7/backup/db_rac_bak_for_remove_01';
backup database '/dm7/data/rac0_config/dm.ini' full backupset '/dm7/backup/db_rac_bak_for_remove_01';
checking if the RAC database under system path [+DMDATA/data/rac] is running....
EP [0] is checking....
EP [1] is checking....
EP[0] max_lsn: 58852
EP[0] adjust cur_lsn from [58852] to [58867]
BACKUP DATABASE [rac], execute......
CMD CHECK LSN......
BACKUP DATABASE [rac], collect dbf......
CMD CHECK ......
DBF BACKUP SUBS......
total 1 packages processed...
total 2 packages processed...
total 3 packages processed...
total 4 packages processed...
total 5 packages processed...
DBF BACKUP MAIN......
BACKUPSET [/dm7/backup/db_rac_bak_for_remove_01] END, CODE [0]......
META GENERATING......
total 9 packages processed...
total 9 packages processed!
CMD END.CODE:[0]
backup successfully!
time used: 3683.477(ms)

–增量备份之前,启动数据库,以便成功生成增量备份

RMAN> backup database '/dm7/data/rac0_config/dm.ini' increment backupset '/dm7/backup/db_rac_bak_for_remove_01_incr';
backup database '/dm7/data/rac0_config/dm.ini' increment backupset '/dm7/backup/db_rac_bak_for_remove_01_incr';
checking if the RAC database under system path [+DMDATA/data/rac] is running....
EP [0] is checking....
EP [1] is checking....
EP[0] max_lsn: 61871
EP[0] adjust cur_lsn from [61871] to [61888]
BACKUP DATABASE [rac], execute......
CMD CHECK LSN......
BACKUP DATABASE [rac], collect dbf......
CMD CHECK ......
DBF BACKUP SUBS......
total 1 packages processed...
total 2 packages processed...
total 3 packages processed...
total 4 packages processed...
total 5 packages processed...
DBF BACKUP MAIN......
BACKUPSET [/dm7/backup/db_rac_bak_for_remove_01_incr] END, CODE [0]......
META GENERATING......
total 9 packages processed...
total 9 packages processed!
CMD END.CODE:[0]
backup successfully!
time used: 3563.746(ms)


RMAN> remove backupset '/dm7/backup/db_rac_bak_for_remove_01_incr' database '/dm7/data/rac0_config/dm.ini' cascade;
remove backupset '/dm7/backup/db_rac_bak_for_remove_01_incr' database '/dm7/data/rac0_config/dm.ini' cascade;
CMD END.CODE:[0]
remove backupset successfully.
time used: 23.623(ms)

2.批量删除所有备份集
使用REMOVE BACKUPSETS…命令可批量删除备份集。批量删除可选择删除的备份类型,数据库备份、表空间备份、表备份,以及归档备份,不指定则全部删除。下面示例为删除/dm7/backup目录下的所有备份集,可以是联机生成的备份集,也可以脱机DMRMAN工具生成的备份集。

RMAN> backup database '/dm7/data/rac0_config/dm.ini' full backupset '/dm7/backup/db_rac_bak_for_remove_02';
backup database '/dm7/data/rac0_config/dm.ini' full backupset '/dm7/backup/db_rac_bak_for_remove_02';
checking if the RAC database under system path [+DMDATA/data/rac] is running....
EP [0] is checking....
EP [1] is checking....
EP[0] max_lsn: 61871
EP[0] adjust cur_lsn from [61871] to [61888]
BACKUP DATABASE [rac], execute......
CMD CHECK LSN......
BACKUP DATABASE [rac], collect dbf......
CMD CHECK ......
DBF BACKUP SUBS......
total 1 packages processed...
total 2 packages processed...
total 3 packages processed...
total 4 packages processed...
total 5 packages processed...
DBF BACKUP MAIN......
BACKUPSET [/dm7/backup/db_rac_bak_for_remove_02] END, CODE [0]......
META GENERATING......
total 9 packages processed...
total 9 packages processed!
CMD END.CODE:[0]
backup successfully!
time used: 3415.539(ms)

RMAN> remove backupsets with backupdir '/dm7/backup/';
remove backupsets with backupdir '/dm7/backup/';
CMD END.CODE:[-10000],DESC:[Fail in mml(-10000)]
CMD END.CODE:[0]
remove backupset successfully.
time used: 1041.430(ms)

3.批量删除指定时间之前的备份集
REMOVE BACKUPSETS…UNTIL TIME命令用来批量删除指定时间的备份集。通常情况下,用户并不想删除指定目录下所有的备份集,这时可以选择只删除指定时间之前的备份。如何确定删除备份的时间点,需要结合用户的备份计划合理指定。若用户每周做一次完全备份,每天进行增量备份,那么删除的时间可指定为7天前的某个特定时间。假设今天的日期为2020-06-09,要删除7天前/dm7/backup目录下的所有备份在DMRMAN中输入以下命令:

RMAN> remove backupsets with backupdir '/dm7/backup/' until time '2020-06-09 15:20:00';
remove backupsets with backupdir '/dm7/backup/' until time '2020-06-09 15:20:00';
CMD END.CODE:[-10000],DESC:[Fail in mml(-10000)]
CMD END.CODE:[0]
remove backupset successfully.
time used: 1020.600(ms)

DM7使用DMRMAN工具查看备份集

使用DMRMAN工具查看备份集
1. 概述
DMRMAN中使用SHOW命令可以查看备份集的信息,包括:
1. 备份集的数据库信息
2. 备份集的元信息
3. 备份集中文件信息(如备份数据文件DBF和备份片文件)
4. 备份集中表信息(仅对表备份集有效)
若指定具体备份集目录,则会生成相应的备份集链表信息。
语法如下:

SHOW BACKUPSET '< 备份集目录>' [][RECURSIVE] [] []
[];
|SHOW BACKUPSETS [] 
[] [] [];
::= DATABASE '' |
WITH BACKUPDIR '< 备份集搜索目录>'{,'< 备份集搜索目录>'} |
DATABASE '' WITH BACKUPDIR '< 备份集搜索目录>'{, '< 备份集搜索目录>'}
::= DEVICE TYPE DISK|TAPE [PARMS '< 介质参数>']
::= INFO DB[,META][,FILE] [,TABLE]
::= USE DB_MAGIC 
::= TO '< 输出文件路径>' [FORMAT TXT | FORMAT XML]

BACKUPSET:指定显示目标备份集信息,若同时指定RECURSIVE,则显示以该备份集为最新备份集递归显示完整的备份集链表;否则,仅显示指定备份集本身信息。若为完全备份,则仅显示该备份集自身信息。

DATABASE:指定数据库dm.ini文件路径,若指定,则该数据库的默认备份目录作为备份集搜索目录之一。

WITH BACKUPDIR:备份集搜索目录,最大长度为256个字节。若查看完全备份的备份集信息且指定的备份集路径为相对路径可通过设置此参数搜索备份集;若查看的为增量备份集信息,设置该参数除上述功能外还用于搜索基备份集。

: 指定介质类型和介质参数,介质类型支持DISK和TAPE,默认DISK。

:指定显示备份集信息内容,可以组合指定,若未指定,则显示全部。具体说明如下:
1. DB 表示仅显示备份集的数据库信息;
2. META表示仅显示备份集的元信息;
3. FILE表示仅显示备份集中文件信息,如备份数据文件DBF和备份片文件;
4. TABLE 表示显示备份集中表信息,仅对表备份集有效。

:SHOW BACKUPSETS可以指定仅显示指定DB_MAGIC即指定数据库的备份集信息。

:指定备份集信息输出的目标文件路径,若不指定,仅控制台打印。文件格式有两种类型,TXT和XML格式,默认是TXT格式。不支持输出到DMASM文件系统中。指定的文件不能为已经存在的文件,否则报错。

2. 备份信息查看
SHOW命令支持查看单个备份集信息也支持批量查看多个备份集的信息。本节主要举例说明如何执行简单的常用的查看备份集信息操作,包括:
1. 查看指定的备份集信息
2. 批量显示备份集信息
3. 查看指定数据库所有备份集的信息
4. 指定显示部分备份集信息
5. 以xml格式输出备份信息到文件

1.查看指定的备份集信息
SHOW BACKUPSET…命令用于显示特定的备份集信息,每次只能显示一个备份集。当仅需要查看某个特定备份集信息时可以使用此命令。执行
步骤如下:

[dmdba@dmrac1 bin]$ dmrman
dmrman V7.1.6.46-Build(2018.02.08-89107)ENT
RMAN> show backupset '/dm7/backup/db_rac_bak';
show backupset '/dm7/backup/db_rac_bak';




system path:           +DMDATA/data/rac
db magic:              -991931850
permanent magic:       450923536
rac node:              2
page check:            0
rlog encrypt:          0
external cipher[id/name]:  0/
external hash[id/name]:  0/
length in char:        0
use new hash:          1
page size:             8 KB
extent size:           16
case sensitive:        1
log page size:         512 B
unicode_flag/charset:  0
data version:          0x7000A
sys version:           V7.1.6.46-Build(2018.02.08-89107)ENT
enable policy:         0
archive flag:          1
blank_pad_mode:        0
crc_check:             TRUE


backupset sig:         BA
backupset version:     4009
database name:         rac
backup name:           DB_RAC_BAK
backupset description:
backupset ID :         1109894076
parent backupset ID:     -1
META file size :       293376
compressed level:      0
encrypt type:          0
parallel num:          4
backup range:          database
mpp_timestamp:         1590824489
ddl_clone:             FALSE
mpp_flag:              FALSE
backup level:          online
backup type:           full
without log:           FALSE
START_LSN:             51236
START_SEQ:             1870
END_LSN:               51298
END_SEQ:               15673
base START_LSN:        -1
base END_LSN:          -1
base name:
base backupset:
backup time:           2020-05-30 15:41:35
min trx start lsn:     49398
min exec ver:          0x0701060C
pkg size:              0x02000000



RAC EP:            0
RAC status:          OK
RAC begin lsn:       51287
RAC begin seq:       15668
RAC end lsn:         51298
RAC end seq:         15673
RAC base begin lsn:  -1
RAC base begin seq:  -1
RAC base end lsn:    -1
RAC base end seq:    -1

RAC EP:            1
RAC status:          OK
RAC begin lsn:       51236
RAC begin seq:       1870
RAC end lsn:         51235
RAC end seq:         1869
RAC base begin lsn:  -1
RAC base begin seq:  -1
RAC base end lsn:    -1
RAC base end seq:    -1


backupset directory: /dm7/backup/db_rac_bak
backupset name:        db_rac_bak
backup data file num:  1
backup piece num:      1


$file_seq |$size(KB) |$pos_desc                                               |$content_type
0         |8         |db_rac_bak.bak                                          |LOG


$file_seq |$group_id |$group_name                      |$file_id  |$file_path                       |$mirror_path                     |$file_len


$file_seq |$file_path                       |$file_len           |$begin_lsn          |$begin_seqno        |$begin_rpag_off     |$end_lsn            |$end_seqno          |$create_time        |$close_time
1         |                                 |3072                |51286               |15668               |8                   |51298               |15673               |0000-00-00 00:00:00 |0000-00-00 00:00:00




system path:           +DMDATA/data/rac
db magic:              -991931850
permanent magic:       450923536
rac node:              2
page check:            0
rlog encrypt:          0
external cipher[id/name]:  0/
external hash[id/name]:  0/
length in char:        0
use new hash:          1
page size:             8 KB
extent size:           16
case sensitive:        1
log page size:         512 B
unicode_flag/charset:  0
data version:          0x7000A
sys version:           V7.1.6.46-Build(2018.02.08-89107)ENT
enable policy:         0
archive flag:          1
blank_pad_mode:        0
crc_check:             TRUE


backupset sig:         BA
backupset version:     4009
database name:         rac
backup name:           DB_RAC_BAK_2
backupset description:
backupset ID :         66095816
parent backupset ID:     1109894076
META file size :       57856
compressed level:      0
encrypt type:          0
parallel num:          1
backup range:          database
mpp_timestamp:         1590824489
ddl_clone:             FALSE
mpp_flag:              FALSE
backup level:          online
backup type:           full
without log:           FALSE
START_LSN:             51236
START_SEQ:             1870
END_LSN:               51235
END_SEQ:               1869
base START_LSN:        -1
base END_LSN:          -1
base name:
base backupset:
backup time:           2020-05-30 15:41:35
min trx start lsn:     49398
min exec ver:          0x0701060C
pkg size:              0x02000000



RAC EP:            0
RAC status:          OK
RAC begin lsn:       51287
RAC begin seq:       15668
RAC end lsn:         -1
RAC end seq:         -1
RAC base begin lsn:  -1
RAC base begin seq:  -1
RAC base end lsn:    -1
RAC base end seq:    -1

RAC EP:            1
RAC status:          OK
RAC begin lsn:       51236
RAC begin seq:       1870
RAC end lsn:         -1
RAC end seq:         -1
RAC base begin lsn:  -1
RAC base begin seq:  -1
RAC base end lsn:    -1
RAC base end seq:    -1


backupset directory: /dm7/backup/db_rac_bak/db_rac_bak_2
backupset name:        db_rac_bak_2
backup data file num:  1
backup piece num:      1


$file_seq |$size(KB) |$pos_desc                                               |$content_type
0         |85        |db_rac_bak_2.bak                                        |DATA


$file_seq |$group_id |$group_name                      |$file_id  |$file_path                       |$mirror_path                     |$file_len
3         |4         |MAIN                             |0         |+DMDATA/data/rac/main.dbf        |                                 |134217728


$file_seq |$file_path                       |$file_len           |$begin_lsn          |$begin_seqno        |$begin_rpag_off     |$end_lsn            |$end_seqno          |$create_time        |$close_time






system path:           +DMDATA/data/rac
db magic:              -991931850
permanent magic:       450923536
rac node:              2
page check:            0
rlog encrypt:          0
external cipher[id/name]:  0/
external hash[id/name]:  0/
length in char:        0
use new hash:          1
page size:             8 KB
extent size:           16
case sensitive:        1
log page size:         512 B
unicode_flag/charset:  0
data version:          0x7000A
sys version:           V7.1.6.46-Build(2018.02.08-89107)ENT
enable policy:         0
archive flag:          1
blank_pad_mode:        0
crc_check:             TRUE


backupset sig:         BA
backupset version:     4009
database name:         rac
backup name:           DB_RAC_BAK_3
backupset description:
backupset ID :         -1127735780
parent backupset ID:     1109894076
META file size :       57856
compressed level:      0
encrypt type:          0
parallel num:          1
backup range:          database
mpp_timestamp:         1590824489
ddl_clone:             FALSE
mpp_flag:              FALSE
backup level:          online
backup type:           full
without log:           FALSE
START_LSN:             51236
START_SEQ:             1870
END_LSN:               51235
END_SEQ:               1869
base START_LSN:        -1
base END_LSN:          -1
base name:
base backupset:
backup time:           2020-05-30 15:41:35
min trx start lsn:     49398
min exec ver:          0x0701060C
pkg size:              0x02000000



RAC EP:            0
RAC status:          OK
RAC begin lsn:       51287
RAC begin seq:       15668
RAC end lsn:         -1
RAC end seq:         -1
RAC base begin lsn:  -1
RAC base begin seq:  -1
RAC base end lsn:    -1
RAC base end seq:    -1

RAC EP:            1
RAC status:          OK
RAC begin lsn:       51236
RAC begin seq:       1870
RAC end lsn:         -1
RAC end seq:         -1
RAC base begin lsn:  -1
RAC base begin seq:  -1
RAC base end lsn:    -1
RAC base end seq:    -1


backupset directory: /dm7/backup/db_rac_bak/db_rac_bak_3
backupset name:        db_rac_bak_3
backup data file num:  1
backup piece num:      1


$file_seq |$size(KB) |$pos_desc                                               |$content_type
0         |13        |db_rac_bak_3.bak                                        |DATA


$file_seq |$group_id |$group_name                      |$file_id  |$file_path                       |$mirror_path                     |$file_len
4         |5         |TS_FOR_DBF                       |0         |+DMDATA/data/rac/ts_for_dbf_01.dbf|                                 |134217728


$file_seq |$file_path                       |$file_len           |$begin_lsn          |$begin_seqno        |$begin_rpag_off     |$end_lsn            |$end_seqno          |$create_time        |$close_time






system path:           +DMDATA/data/rac
db magic:              -991931850
permanent magic:       450923536
rac node:              2
page check:            0
rlog encrypt:          0
external cipher[id/name]:  0/
external hash[id/name]:  0/
length in char:        0
use new hash:          1
page size:             8 KB
extent size:           16
case sensitive:        1
log page size:         512 B
unicode_flag/charset:  0
data version:          0x7000A
sys version:           V7.1.6.46-Build(2018.02.08-89107)ENT
enable policy:         0
archive flag:          1
blank_pad_mode:        0
crc_check:             TRUE


backupset sig:         BA
backupset version:     4009
database name:         rac
backup name:           DB_RAC_BAK_0
backupset description:
backupset ID :         -287144791
parent backupset ID:     1109894076
META file size :       61952
compressed level:      0
encrypt type:          0
parallel num:          1
backup range:          database
mpp_timestamp:         1590824489
ddl_clone:             FALSE
mpp_flag:              FALSE
backup level:          online
backup type:           full
without log:           FALSE
START_LSN:             51236
START_SEQ:             1870
END_LSN:               51235
END_SEQ:               1869
base START_LSN:        -1
base END_LSN:          -1
base name:
base backupset:
backup time:           2020-05-30 15:41:35
min trx start lsn:     49398
min exec ver:          0x0701060C
pkg size:              0x02000000



RAC EP:            0
RAC status:          OK
RAC begin lsn:       51287
RAC begin seq:       15668
RAC end lsn:         -1
RAC end seq:         -1
RAC base begin lsn:  -1
RAC base begin seq:  -1
RAC base end lsn:    -1
RAC base end seq:    -1

RAC EP:            1
RAC status:          OK
RAC begin lsn:       51236
RAC begin seq:       1870
RAC end lsn:         -1
RAC end seq:         -1
RAC base begin lsn:  -1
RAC base begin seq:  -1
RAC base end lsn:    -1
RAC base end seq:    -1


backupset directory: /dm7/backup/db_rac_bak/db_rac_bak_0
backupset name:        db_rac_bak_0
backup data file num:  2
backup piece num:      1


$file_seq |$size(KB) |$pos_desc                                               |$content_type
0         |5005      |db_rac_bak_0.bak                                        |DATA


$file_seq |$group_id |$group_name                      |$file_id  |$file_path                       |$mirror_path                     |$file_len
1         |0         |SYSTEM                           |0         |+DMDATA/data/rac/system.dbf      |                                 |134217728
5         |5         |TS_FOR_DBF                       |1         |+DMDATA/data/rac/ts_for_dbf_02.dbf|                                 |134217728


$file_seq |$file_path                       |$file_len           |$begin_lsn          |$begin_seqno        |$begin_rpag_off     |$end_lsn            |$end_seqno          |$create_time        |$close_time






system path:           +DMDATA/data/rac
db magic:              -991931850
permanent magic:       450923536
rac node:              2
page check:            0
rlog encrypt:          0
external cipher[id/name]:  0/
external hash[id/name]:  0/
length in char:        0
use new hash:          1
page size:             8 KB
extent size:           16
case sensitive:        1
log page size:         512 B
unicode_flag/charset:  0
data version:          0x7000A
sys version:           V7.1.6.46-Build(2018.02.08-89107)ENT
enable policy:         0
archive flag:          1
blank_pad_mode:        0
crc_check:             TRUE


backupset sig:         BA
backupset version:     4009
database name:         rac
backup name:           DB_RAC_BAK_1
backupset description:
backupset ID :         -1045365472
parent backupset ID:     1109894076
META file size :       57856
compressed level:      0
encrypt type:          0
parallel num:          1
backup range:          database
mpp_timestamp:         1590824489
ddl_clone:             FALSE
mpp_flag:              FALSE
backup level:          online
backup type:           full
without log:           FALSE
START_LSN:             51236
START_SEQ:             1870
END_LSN:               51235
END_SEQ:               1869
base START_LSN:        -1
base END_LSN:          -1
base name:
base backupset:
backup time:           2020-05-30 15:41:35
min trx start lsn:     49398
min exec ver:          0x0701060C
pkg size:              0x02000000



RAC EP:            0
RAC status:          OK
RAC begin lsn:       51287
RAC begin seq:       15668
RAC end lsn:         -1
RAC end seq:         -1
RAC base begin lsn:  -1
RAC base begin seq:  -1
RAC base end lsn:    -1
RAC base end seq:    -1

RAC EP:            1
RAC status:          OK
RAC begin lsn:       51236
RAC begin seq:       1870
RAC end lsn:         -1
RAC end seq:         -1
RAC base begin lsn:  -1
RAC base begin seq:  -1
RAC base end lsn:    -1
RAC base end seq:    -1


backupset directory: /dm7/backup/db_rac_bak/db_rac_bak_1
backupset name:        db_rac_bak_1
backup data file num:  1
backup piece num:      1


$file_seq |$size(KB) |$pos_desc                                               |$content_type
0         |20997     |db_rac_bak_1.bak                                        |DATA


$file_seq |$group_id |$group_name                      |$file_id  |$file_path                       |$mirror_path                     |$file_len
2         |1         |ROLL                             |0         |+DMDATA/data/rac/roll.dbf        |                                 |134217728


$file_seq |$file_path                       |$file_len           |$begin_lsn          |$begin_seqno        |$begin_rpag_off     |$end_lsn            |$end_seqno          |$create_time        |$close_time




show backupsets successfully.
time used: 14.325(ms)

显示的备份集信息分为三类,依次是元数据信息(META INFO)、文件信息(FILE INFO)和数据库信息(DB INFO)。用户可根据自身需要只显示部分备份集信息,本节下文中会有介绍。

2.批量显示备份集信息
SHOW BACKUPSETS…命令用于批量显示指定搜索目录下的备份集信息。如需要查看的多个备份集不在同一个目录下,可通过多次指定WITH BACKUPDIR参数同时查看所有的备份集。操作如下:

RMAN> backup database '/dm7/data/rac0_config/dm.ini';
backup database '/dm7/data/rac0_config/dm.ini';
checking if the RAC database under system path [+DMDATA/data/rac] is running....
EP [0] is checking....
EP [1] is checking....
EP[0] max_lsn: 58852
EP[0] adjust cur_lsn from [58852] to [58867]
BACKUP DATABASE [rac], execute......
CMD CHECK LSN......
BACKUP DATABASE [rac], collect dbf......
CMD CHECK ......
DBF BACKUP SUBS......
total 1 packages processed...
total 2 packages processed...
total 3 packages processed...
total 4 packages processed...
total 5 packages processed...
DBF BACKUP MAIN......
BACKUPSET [+DMDATA/data/rac/bak/DB_rac_FULL_20200608_160009_000828] END, CODE [0]......
META GENERATING......
total 9 packages processed...
total 9 packages processed!
CMD END.CODE:[0]
backup successfully!
time used: 16303.415(ms)
RMAN> backup database '/dm7/data/rac0_config/dm.ini' full backupset '/dm7/backup/db_rac_full_bak_2020060801';
backup database '/dm7/data/rac0_config/dm.ini' full backupset '/dm7/backup/db_rac_full_bak_2020060801';
checking if the RAC database under system path [+DMDATA/data/rac] is running....
EP [0] is checking....
EP [1] is checking....
EP[0] max_lsn: 58852
EP[0] adjust cur_lsn from [58852] to [58867]
BACKUP DATABASE [rac], execute......
CMD CHECK LSN......
BACKUP DATABASE [rac], collect dbf......
CMD CHECK ......
DBF BACKUP SUBS......
total 1 packages processed...
total 2 packages processed...
total 3 packages processed...
total 4 packages processed...
total 5 packages processed...
DBF BACKUP MAIN......
BACKUPSET [/dm7/backup/db_rac_full_bak_2020060801] END, CODE [0]......
META GENERATING......
total 9 packages processed...
total 9 packages processed!
CMD END.CODE:[0]
backup successfully!
time used: 3570.343(ms)


RMAN> show backupsets with backupdir '+DMDATA/data/rac/bak','/dm7/backup';
show backupsets with backupdir '+DMDATA/data/rac/bak' , '/dm7/backup';
CMD END.CODE:[0]








system path:           +DMDATA/data/rac
db magic:              -991931850
permanent magic:       450923536
rac node:              2
page check:            0
rlog encrypt:          0
external cipher[id/name]:  0/
external hash[id/name]:  0/
length in char:        0
use new hash:          1
page size:             8 KB
extent size:           16
case sensitive:        1
log page size:         512 B
unicode_flag/charset:  0
data version:          0x7000A
sys version:           V7.1.6.46-Build(2018.02.08-89107)ENT
enable policy:         0
archive flag:          1
blank_pad_mode:        0
crc_check:             TRUE


backupset sig:         BA
backupset version:     4009
database name:         rac
backup name:           DB_FULL_rac_20200608_160623_000096
backupset description:
backupset ID :         186522112
parent backupset ID:     -1
META file size :       74240
compressed level:      0
encrypt type:          0
parallel num:          1
backup range:          database
mpp_timestamp:         1591603580
ddl_clone:             FALSE
mpp_flag:              FALSE
backup level:          offline
backup type:           full
without log:           FALSE
START_LSN:             58853
START_SEQ:             16611
END_LSN:               58867
END_SEQ:               16610
base START_LSN:        -1
base END_LSN:          -1
base name:
base backupset:
backup time:           2020-06-08 16:06:24
min trx start lsn:     58853
min exec ver:          0x0701060C
pkg size:              0x02000000



RAC EP:            0
RAC status:          OK
RAC begin lsn:       58853
RAC begin seq:       16611
RAC end lsn:         58867
RAC end seq:         16610
RAC base begin lsn:  -1
RAC base begin seq:  -1
RAC base end lsn:    -1
RAC base end seq:    -1

RAC EP:            1
RAC status:          OK
RAC begin lsn:       58868
RAC begin seq:       2492
RAC end lsn:         58867
RAC end seq:         2491
RAC base begin lsn:  -1
RAC base begin seq:  -1
RAC base end lsn:    -1
RAC base end seq:    -1


backupset directory: /dm7/backup/db_rac_full_bak_2020060801
backupset name:        db_rac_full_bak_2020060801
backup data file num:  5
backup piece num:      1


$file_seq |$size(KB) |$pos_desc                                               |$content_type
0         |26103     |db_rac_full_bak_2020060801.bak                          |DATA


$file_seq |$group_id |$group_name                      |$file_id  |$file_path                       |$mirror_path                     |$file_len
1         |0         |SYSTEM                           |0         |+DMDATA/data/rac/system.dbf      |                                 |134217728
2         |1         |ROLL                             |0         |+DMDATA/data/rac/roll.dbf        |                                 |134217728
3         |4         |MAIN                             |0         |+DMDATA/data/rac/main.dbf        |                                 |134217728
4         |5         |TS_FOR_DBF                       |0         |+DMDATA/data/rac/ts_for_dbf_01.dbf|                                 |134217728
5         |5         |TS_FOR_DBF                       |1         |+DMDATA/data/rac/ts_for_dbf_02.dbf|                                 |134217728


$file_seq |$file_path                       |$file_len           |$begin_lsn          |$begin_seqno        |$begin_rpag_off     |$end_lsn            |$end_seqno          |$create_time        |$close_time






system path:           +DMDATA/data/rac
db magic:              -991931850
permanent magic:       450923536
rac node:              2
page check:            0
rlog encrypt:          0
external cipher[id/name]:  0/
external hash[id/name]:  0/
length in char:        0
use new hash:          1
page size:             8 KB
extent size:           16
case sensitive:        1
log page size:         512 B
unicode_flag/charset:  0
data version:          0x7000A
sys version:           V7.1.6.46-Build(2018.02.08-89107)ENT
enable policy:         0
archive flag:          1
blank_pad_mode:        0
crc_check:             TRUE


backupset sig:         BA
backupset version:     4009
database name:         rac
backup name:           DB_FULL_rac_20200608_160009_000828
backupset description:
backupset ID :         1835676274
parent backupset ID:     -1
META file size :       74240
compressed level:      0
encrypt type:          0
parallel num:          1
backup range:          database
mpp_timestamp:         1591603207
ddl_clone:             FALSE
mpp_flag:              FALSE
backup level:          offline
backup type:           full
without log:           FALSE
START_LSN:             58853
START_SEQ:             16611
END_LSN:               58867
END_SEQ:               16610
base START_LSN:        -1
base END_LSN:          -1
base name:
base backupset:
backup time:           2020-06-08 16:00:17
min trx start lsn:     58853
min exec ver:          0x0701060C
pkg size:              0x02000000



RAC EP:            0
RAC status:          OK
RAC begin lsn:       58853
RAC begin seq:       16611
RAC end lsn:         58867
RAC end seq:         16610
RAC base begin lsn:  -1
RAC base begin seq:  -1
RAC base end lsn:    -1
RAC base end seq:    -1

RAC EP:            1
RAC status:          OK
RAC begin lsn:       58868
RAC begin seq:       2492
RAC end lsn:         58867
RAC end seq:         2491
RAC base begin lsn:  -1
RAC base begin seq:  -1
RAC base end lsn:    -1
RAC base end seq:    -1


backupset directory: +DMDATA/data/rac/bak/DB_rac_FULL_20200608_160009_000828
backupset name:        DB_rac_FULL_20200608_160009_000828
backup data file num:  5
backup piece num:      1


$file_seq |$size(KB) |$pos_desc                                               |$content_type
0         |26103     |DB_rac_FULL_20200608_160009_000828.bak                  |DATA


$file_seq |$group_id |$group_name                      |$file_id  |$file_path                       |$mirror_path                     |$file_len
1         |0         |SYSTEM                           |0         |+DMDATA/data/rac/system.dbf      |                                 |134217728
2         |1         |ROLL                             |0         |+DMDATA/data/rac/roll.dbf        |                                 |134217728
3         |4         |MAIN                             |0         |+DMDATA/data/rac/main.dbf        |                                 |134217728
4         |5         |TS_FOR_DBF                       |0         |+DMDATA/data/rac/ts_for_dbf_01.dbf|                                 |134217728
5         |5         |TS_FOR_DBF                       |1         |+DMDATA/data/rac/ts_for_dbf_02.dbf|                                 |134217728


$file_seq |$file_path                       |$file_len           |$begin_lsn          |$begin_seqno        |$begin_rpag_off     |$end_lsn            |$end_seqno          |$create_time        |$close_time






system path:           +DMDATA/data/rac
db magic:              -991931850
permanent magic:       450923536
rac node:              2
page check:            0
rlog encrypt:          0
external cipher[id/name]:  0/
external hash[id/name]:  0/
length in char:        0
use new hash:          1
page size:             8 KB
extent size:           16
case sensitive:        1
log page size:         512 B
unicode_flag/charset:  0
data version:          0x7000A
sys version:           V7.1.6.46-Build(2018.02.08-89107)ENT
enable policy:         0
archive flag:          1
blank_pad_mode:        0
crc_check:             TRUE


backupset sig:         BA
backupset version:     4009
database name:         rac
backup name:           DB_RAC_BAK
backupset description:
backupset ID :         1109894076
parent backupset ID:     -1
META file size :       293376
compressed level:      0
encrypt type:          0
parallel num:          4
backup range:          database
mpp_timestamp:         1590824489
ddl_clone:             FALSE
mpp_flag:              FALSE
backup level:          online
backup type:           full
without log:           FALSE
START_LSN:             51236
START_SEQ:             1870
END_LSN:               51298
END_SEQ:               15673
base START_LSN:        -1
base END_LSN:          -1
base name:
base backupset:
backup time:           2020-05-30 15:41:35
min trx start lsn:     49398
min exec ver:          0x0701060C
pkg size:              0x02000000



RAC EP:            0
RAC status:          OK
RAC begin lsn:       51287
RAC begin seq:       15668
RAC end lsn:         51298
RAC end seq:         15673
RAC base begin lsn:  -1
RAC base begin seq:  -1
RAC base end lsn:    -1
RAC base end seq:    -1

RAC EP:            1
RAC status:          OK
RAC begin lsn:       51236
RAC begin seq:       1870
RAC end lsn:         51235
RAC end seq:         1869
RAC base begin lsn:  -1
RAC base begin seq:  -1
RAC base end lsn:    -1
RAC base end seq:    -1


backupset directory: /dm7/backup/db_rac_bak
backupset name:        db_rac_bak
backup data file num:  1
backup piece num:      1


$file_seq |$size(KB) |$pos_desc                                               |$content_type
0         |8         |db_rac_bak.bak                                          |LOG


$file_seq |$group_id |$group_name                      |$file_id  |$file_path                       |$mirror_path                     |$file_len


$file_seq |$file_path                       |$file_len           |$begin_lsn          |$begin_seqno        |$begin_rpag_off     |$end_lsn            |$end_seqno          |$create_time        |$close_time
1         |                                 |3072                |51286               |15668               |8                   |51298               |15673               |0000-00-00 00:00:00 |0000-00-00 00:00:00




system path:           +DMDATA/data/rac
db magic:              -991931850
permanent magic:       450923536
rac node:              2
page check:            0
rlog encrypt:          0
external cipher[id/name]:  0/
external hash[id/name]:  0/
length in char:        0
use new hash:          1
page size:             8 KB
extent size:           16
case sensitive:        1
log page size:         512 B
unicode_flag/charset:  0
data version:          0x7000A
sys version:           V7.1.6.46-Build(2018.02.08-89107)ENT
enable policy:         0
archive flag:          1
blank_pad_mode:        0
crc_check:             TRUE


backupset sig:         BA
backupset version:     4009
database name:         rac
backup name:           DB_RAC_BAK_2
backupset description:
backupset ID :         66095816
parent backupset ID:     1109894076
META file size :       57856
compressed level:      0
encrypt type:          0
parallel num:          1
backup range:          database
mpp_timestamp:         1590824489
ddl_clone:             FALSE
mpp_flag:              FALSE
backup level:          online
backup type:           full
without log:           FALSE
START_LSN:             51236
START_SEQ:             1870
END_LSN:               51235
END_SEQ:               1869
base START_LSN:        -1
base END_LSN:          -1
base name:
base backupset:
backup time:           2020-05-30 15:41:35
min trx start lsn:     49398
min exec ver:          0x0701060C
pkg size:              0x02000000



RAC EP:            0
RAC status:          OK
RAC begin lsn:       51287
RAC begin seq:       15668
RAC end lsn:         -1
RAC end seq:         -1
RAC base begin lsn:  -1
RAC base begin seq:  -1
RAC base end lsn:    -1
RAC base end seq:    -1

RAC EP:            1
RAC status:          OK
RAC begin lsn:       51236
RAC begin seq:       1870
RAC end lsn:         -1
RAC end seq:         -1
RAC base begin lsn:  -1
RAC base begin seq:  -1
RAC base end lsn:    -1
RAC base end seq:    -1


backupset directory: /dm7/backup/db_rac_bak/db_rac_bak_2
backupset name:        db_rac_bak_2
backup data file num:  1
backup piece num:      1


$file_seq |$size(KB) |$pos_desc                                               |$content_type
0         |85        |db_rac_bak_2.bak                                        |DATA


$file_seq |$group_id |$group_name                      |$file_id  |$file_path                       |$mirror_path                     |$file_len
3         |4         |MAIN                             |0         |+DMDATA/data/rac/main.dbf        |                                 |134217728


$file_seq |$file_path                       |$file_len           |$begin_lsn          |$begin_seqno        |$begin_rpag_off     |$end_lsn            |$end_seqno          |$create_time        |$close_time






system path:           +DMDATA/data/rac
db magic:              -991931850
permanent magic:       450923536
rac node:              2
page check:            0
rlog encrypt:          0
external cipher[id/name]:  0/
external hash[id/name]:  0/
length in char:        0
use new hash:          1
page size:             8 KB
extent size:           16
case sensitive:        1
log page size:         512 B
unicode_flag/charset:  0
data version:          0x7000A
sys version:           V7.1.6.46-Build(2018.02.08-89107)ENT
enable policy:         0
archive flag:          1
blank_pad_mode:        0
crc_check:             TRUE


backupset sig:         BA
backupset version:     4009
database name:         rac
backup name:           DB_RAC_BAK_3
backupset description:
backupset ID :         -1127735780
parent backupset ID:     1109894076
META file size :       57856
compressed level:      0
encrypt type:          0
parallel num:          1
backup range:          database
mpp_timestamp:         1590824489
ddl_clone:             FALSE
mpp_flag:              FALSE
backup level:          online
backup type:           full
without log:           FALSE
START_LSN:             51236
START_SEQ:             1870
END_LSN:               51235
END_SEQ:               1869
base START_LSN:        -1
base END_LSN:          -1
base name:
base backupset:
backup time:           2020-05-30 15:41:35
min trx start lsn:     49398
min exec ver:          0x0701060C
pkg size:              0x02000000



RAC EP:            0
RAC status:          OK
RAC begin lsn:       51287
RAC begin seq:       15668
RAC end lsn:         -1
RAC end seq:         -1
RAC base begin lsn:  -1
RAC base begin seq:  -1
RAC base end lsn:    -1
RAC base end seq:    -1

RAC EP:            1
RAC status:          OK
RAC begin lsn:       51236
RAC begin seq:       1870
RAC end lsn:         -1
RAC end seq:         -1
RAC base begin lsn:  -1
RAC base begin seq:  -1
RAC base end lsn:    -1
RAC base end seq:    -1


backupset directory: /dm7/backup/db_rac_bak/db_rac_bak_3
backupset name:        db_rac_bak_3
backup data file num:  1
backup piece num:      1


$file_seq |$size(KB) |$pos_desc                                               |$content_type
0         |13        |db_rac_bak_3.bak                                        |DATA


$file_seq |$group_id |$group_name                      |$file_id  |$file_path                       |$mirror_path                     |$file_len
4         |5         |TS_FOR_DBF                       |0         |+DMDATA/data/rac/ts_for_dbf_01.dbf|                                 |134217728


$file_seq |$file_path                       |$file_len           |$begin_lsn          |$begin_seqno        |$begin_rpag_off     |$end_lsn            |$end_seqno          |$create_time        |$close_time






system path:           +DMDATA/data/rac
db magic:              -991931850
permanent magic:       450923536
rac node:              2
page check:            0
rlog encrypt:          0
external cipher[id/name]:  0/
external hash[id/name]:  0/
length in char:        0
use new hash:          1
page size:             8 KB
extent size:           16
case sensitive:        1
log page size:         512 B
unicode_flag/charset:  0
data version:          0x7000A
sys version:           V7.1.6.46-Build(2018.02.08-89107)ENT
enable policy:         0
archive flag:          1
blank_pad_mode:        0
crc_check:             TRUE


backupset sig:         BA
backupset version:     4009
database name:         rac
backup name:           DB_RAC_BAK_0
backupset description:
backupset ID :         -287144791
parent backupset ID:     1109894076
META file size :       61952
compressed level:      0
encrypt type:          0
parallel num:          1
backup range:          database
mpp_timestamp:         1590824489
ddl_clone:             FALSE
mpp_flag:              FALSE
backup level:          online
backup type:           full
without log:           FALSE
START_LSN:             51236
START_SEQ:             1870
END_LSN:               51235
END_SEQ:               1869
base START_LSN:        -1
base END_LSN:          -1
base name:
base backupset:
backup time:           2020-05-30 15:41:35
min trx start lsn:     49398
min exec ver:          0x0701060C
pkg size:              0x02000000



RAC EP:            0
RAC status:          OK
RAC begin lsn:       51287
RAC begin seq:       15668
RAC end lsn:         -1
RAC end seq:         -1
RAC base begin lsn:  -1
RAC base begin seq:  -1
RAC base end lsn:    -1
RAC base end seq:    -1

RAC EP:            1
RAC status:          OK
RAC begin lsn:       51236
RAC begin seq:       1870
RAC end lsn:         -1
RAC end seq:         -1
RAC base begin lsn:  -1
RAC base begin seq:  -1
RAC base end lsn:    -1
RAC base end seq:    -1


backupset directory: /dm7/backup/db_rac_bak/db_rac_bak_0
backupset name:        db_rac_bak_0
backup data file num:  2
backup piece num:      1


$file_seq |$size(KB) |$pos_desc                                               |$content_type
0         |5005      |db_rac_bak_0.bak                                        |DATA


$file_seq |$group_id |$group_name                      |$file_id  |$file_path                       |$mirror_path                     |$file_len
1         |0         |SYSTEM                           |0         |+DMDATA/data/rac/system.dbf      |                                 |134217728
5         |5         |TS_FOR_DBF                       |1         |+DMDATA/data/rac/ts_for_dbf_02.dbf|                                 |134217728


$file_seq |$file_path                       |$file_len           |$begin_lsn          |$begin_seqno        |$begin_rpag_off     |$end_lsn            |$end_seqno          |$create_time        |$close_time






system path:           +DMDATA/data/rac
db magic:              -991931850
permanent magic:       450923536
rac node:              2
page check:            0
rlog encrypt:          0
external cipher[id/name]:  0/
external hash[id/name]:  0/
length in char:        0
use new hash:          1
page size:             8 KB
extent size:           16
case sensitive:        1
log page size:         512 B
unicode_flag/charset:  0
data version:          0x7000A
sys version:           V7.1.6.46-Build(2018.02.08-89107)ENT
enable policy:         0
archive flag:          1
blank_pad_mode:        0
crc_check:             TRUE


backupset sig:         BA
backupset version:     4009
database name:         rac
backup name:           DB_RAC_BAK_1
backupset description:
backupset ID :         -1045365472
parent backupset ID:     1109894076
META file size :       57856
compressed level:      0
encrypt type:          0
parallel num:          1
backup range:          database
mpp_timestamp:         1590824489
ddl_clone:             FALSE
mpp_flag:              FALSE
backup level:          online
backup type:           full
without log:           FALSE
START_LSN:             51236
START_SEQ:             1870
END_LSN:               51235
END_SEQ:               1869
base START_LSN:        -1
base END_LSN:          -1
base name:
base backupset:
backup time:           2020-05-30 15:41:35
min trx start lsn:     49398
min exec ver:          0x0701060C
pkg size:              0x02000000



RAC EP:            0
RAC status:          OK
RAC begin lsn:       51287
RAC begin seq:       15668
RAC end lsn:         -1
RAC end seq:         -1
RAC base begin lsn:  -1
RAC base begin seq:  -1
RAC base end lsn:    -1
RAC base end seq:    -1

RAC EP:            1
RAC status:          OK
RAC begin lsn:       51236
RAC begin seq:       1870
RAC end lsn:         -1
RAC end seq:         -1
RAC base begin lsn:  -1
RAC base begin seq:  -1
RAC base end lsn:    -1
RAC base end seq:    -1


backupset directory: /dm7/backup/db_rac_bak/db_rac_bak_1
backupset name:        db_rac_bak_1
backup data file num:  1
backup piece num:      1


$file_seq |$size(KB) |$pos_desc                                               |$content_type
0         |20997     |db_rac_bak_1.bak                                        |DATA


$file_seq |$group_id |$group_name                      |$file_id  |$file_path                       |$mirror_path                     |$file_len
2         |1         |ROLL                             |0         |+DMDATA/data/rac/roll.dbf        |                                 |134217728


$file_seq |$file_path                       |$file_len           |$begin_lsn          |$begin_seqno        |$begin_rpag_off     |$end_lsn            |$end_seqno          |$create_time        |$close_time








show backupsets successfully.
time used: 18.070(ms)

3.查看指定数据库所有备份集的信息
如果指定的备份搜索目录下包含不同数据库的备份集,而我们只想查看某个特定数据库的所有备份集信息,此时可以使用SHOW BACKUPSETS…USE DB_MAGIC命令实现。具体操作如下:

1)备份不同的数据库到不同的目录下。

RMAN> backup database '/dm_home/dmdbms/data/dmks1/dm.ini' backupset '/dm_home/dmdbms/data/bak/db_dmks1_bak_2020060801';
backup database '/dm_home/dmdbms/data/dmks1/dm.ini' backupset '/dm_home/dmdbms/data/bak/db_dmks1_bak_2020060801';
file dm.key not found, use default license!
checking if the database under system path [/dm_home/dmdbms/data/dmks1] is running...[4].
checking if the database under system path [/dm_home/dmdbms/data/dmks1] is running...[3].
checking if the database under system path [/dm_home/dmdbms/data/dmks1] is running...[2].
checking if the database under system path [/dm_home/dmdbms/data/dmks1] is running...[1].
checking if the database under system path [/dm_home/dmdbms/data/dmks1] is running...[0].
checking if the database under system path [/dm_home/dmdbms/data/dmks1] is running, write dmrman info.
EP[0] max_lsn: 61665
BACKUP DATABASE [dmks1], execute......
CMD CHECK LSN......
BACKUP DATABASE [dmks1], collect dbf......
CMD CHECK ......
DBF BACKUP SUBS......
total 1 packages processed...
total 2 packages processed...
total 3 packages processed...
DBF BACKUP MAIN......
BACKUPSET [/dm_home/dmdbms/data/bak/db_dmks1_bak_2020060801] END, CODE [0]......
META GENERATING......
total 7 packages processed...
total 7 packages processed!
CMD END.CODE:[0]
backup successfully!
time used: 8043.221(ms)


RMAN> backup database '/dm_home/dmdbms/data/dmks2/dm.ini' backupset '/dm_home/dmdbms/backup/db_dmks2_bak_2020060801';
backup database '/dm_home/dmdbms/data/dmks2/dm.ini' backupset '/dm_home/dmdbms/backup/db_dmks2_bak_2020060801';
checking if the database under system path [/dm_home/dmdbms/data/dmks2] is running...[4].
checking if the database under system path [/dm_home/dmdbms/data/dmks2] is running...[3].
checking if the database under system path [/dm_home/dmdbms/data/dmks2] is running...[2].
checking if the database under system path [/dm_home/dmdbms/data/dmks2] is running...[1].
checking if the database under system path [/dm_home/dmdbms/data/dmks2] is running...[0].
checking if the database under system path [/dm_home/dmdbms/data/dmks2] is running, write dmrman info.
EP[0] max_lsn: 33904
BACKUP DATABASE [dmks2], execute......
CMD CHECK LSN......
BACKUP DATABASE [dmks2], collect dbf......
CMD CHECK ......
DBF BACKUP SUBS......
total 1 packages processed...
total 2 packages processed...
total 3 packages processed...
DBF BACKUP MAIN......
BACKUPSET [/dm_home/dmdbms/backup/db_dmks2_bak_2020060801] END, CODE [0]......
META GENERATING......
total 7 packages processed...
total 7 packages processed!
CMD END.CODE:[0]
backup successfully!
time used: 8047.711(ms)

2) 查看指定数据库备份集的信息,获取DB_MAGIC信息。

RMAN> show backupset '/dm_home/dmdbms/backup/db_dmks2_bak_2020060801';
show backupset '/dm_home/dmdbms/backup/db_dmks2_bak_2020060801';




system path:           /dm_home/dmdbms/data/dmks2
db magic:              1486708862
permanent magic:       1155586847
rac node:              1
page check:            0
rlog encrypt:          0
external cipher[id/name]:  0/
external hash[id/name]:  0/
length in char:        0
use new hash:          1
page size:             8 KB
extent size:           16
case sensitive:        1
log page size:         512 B
unicode_flag/charset:  0
data version:          0x7000A
sys version:           V7.1.6.46-Build(2018.02.08-89107)ENT
enable policy:         0
archive flag:          0
blank_pad_mode:        0
crc_check:             TRUE


backupset sig:         BA
backupset version:     4009
database name:         dmks2
backup name:           DB_FULL_dmks2_20200608_165451_000348
backupset description:
backupset ID :         -479813328
parent backupset ID:     -1
META file size :       66048
compressed level:      0
encrypt type:          0
parallel num:          1
backup range:          database
mpp_timestamp:         1591606486
ddl_clone:             FALSE
mpp_flag:              FALSE
backup level:          offline
backup type:           full
without log:           FALSE
START_LSN:             33905
START_SEQ:             14010
END_LSN:               33904
END_SEQ:               14009
base START_LSN:        -1
base END_LSN:          -1
base name:
base backupset:
backup time:           2020-06-08 16:54:53
min trx start lsn:     33905
min exec ver:          0x0701060C
pkg size:              0x02000000


backupset directory: /dm_home/dmdbms/backup/db_dmks2_bak_2020060801
backupset name:        db_dmks2_bak_2020060801
backup data file num:  3
backup piece num:      1


$file_seq |$size(KB) |$pos_desc                                               |$content_type
0         |5606      |db_dmks2_bak_2020060801.bak                             |DATA


$file_seq |$group_id |$group_name                      |$file_id  |$file_path                       |$mirror_path                     |$file_len
1         |0         |SYSTEM                           |0         |/dm_home/dmdbms/data/dmks2/SYSTEM.DBF|                                 |22020096
2         |1         |ROLL                             |0         |/dm_home/dmdbms/data/dmks2/ROLL.DBF|                                 |134217728
3         |4         |MAIN                             |0         |/dm_home/dmdbms/data/dmks2/MAIN.DBF|                                 |134217728


$file_seq |$file_path                       |$file_len           |$begin_lsn          |$begin_seqno        |$begin_rpag_off     |$end_lsn            |$end_seqno          |$create_time        |$close_time


show backupsets successfully.
time used: 6.251(ms)

通过查看备份集信息可知,数据库/dm_home/dmdbms/data/dmks2的DB_MAGIC值为-1486708862

3) 查看指定目录下数据库/dm_home/dmdbms/data/dmks2的所有备份集信息。

RMAN> show backupsets with backupdir '/dm_home/dmdbms/backup' use db_magic 1486708862;
show backupsets with backupdir '/dm_home/dmdbms/backup' use db_magic 1486708862;
CMD END.CODE:[0]
[602]:no backupsets searched in specified directories

4.指定查看备份集的元数据信息

SHOW BACKUPSET...INFO META命令用于查看备份集的元数据信息。操作步骤如下:
RMAN> show backupset '/dm_home/dmdbms/backup/db_dmks2_bak_2020060801' info meta;
show backupset '/dm_home/dmdbms/backup/db_dmks2_bak_2020060801' info meta;




backupset sig:         BA
backupset version:     4009
database name:         dmks2
backup name:           DB_FULL_dmks2_20200608_165451_000348
backupset description:
backupset ID :         -479813328
parent backupset ID:     -1
META file size :       66048
compressed level:      0
encrypt type:          0
parallel num:          1
backup range:          database
mpp_timestamp:         1591606486
ddl_clone:             FALSE
mpp_flag:              FALSE
backup level:          offline
backup type:           full
without log:           FALSE
START_LSN:             33905
START_SEQ:             14010
END_LSN:               33904
END_SEQ:               14009
base START_LSN:        -1
base END_LSN:          -1
base name:
base backupset:
backup time:           2020-06-08 16:54:53
min trx start lsn:     33905
min exec ver:          0x0701060C
pkg size:              0x02000000


show backupsets successfully.
time used: 5.915(ms)

这里获取的是单个备份集的元数据信息,也可以使用SHOW BACKUPSETS…INFO META命令批量获取元数据信息。同样地,我们可以使用类似的命令指定获取备份集的数据库信息、文件信息和表信息,或这些信息的任意组合。

5.以xml格式输出备份信息到文件
DMRMAN可以将显示的备份集信息输出到文件,目前支持的格式包括TXT和XML,默认为TXT文件格式。使用SHOW BACKUPSETS…TO ‘file_path’ FORMAT XML命令可将备份信息以XML格式显示并输出到文件,如下所示:

RMAN> show backupset '/dm_home/dmdbms/backup/db_dmks2_bak_2020060801' to '/home/dmdba/db_dmks2.txt' format xml;
show backupset '/dm_home/dmdbms/backup/db_dmks2_bak_2020060801' to '/home/dmdba/db_dmks2.txt' format xml;
< ?xml version="1.0" encoding="UTF-8"?>

        
                
                /dm_home/dmdbms/backup/db_dmks2_bak_2020060801
                DISK
                
                        BA
                        4009
                        dmks2
                        DB_FULL_dmks2_20200608_165451_000348
                        
                        -479813328
                        -1
                        66048
                        0
                        0
                        1
                        database
                        1591606486
                        FALSE
                        FALSE
                        offline
                        full
                        FALSE
                        33905
                        14010
                        33904
                        14009
                        -1
                        -1
                        
                        
                        2020-06-08 16:54:53
                        33905
                        0x0701060C
                        0x02000000
                
                
                        /dm_home/dmdbms/backup/db_dmks2_bak_2020060801
                        db_dmks2_bak_2020060801
                        3
                        1
                        
                                0
                                5740032
                                db_dmks2_bak_2020060801.bak
                                DATA
                        
                        
                                1
                                0
                                SYSTEM
                                0
                                /dm_home/dmdbms/data/dmks2/SYSTEM.DBF
                                
                                22020096
                        
                        
                                2
                                1
                                ROLL
                                0
                                /dm_home/dmdbms/data/dmks2/ROLL.DBF
                                
                                134217728
                        
                        
                                3
                                4
                                MAIN
                                0
                                /dm_home/dmdbms/data/dmks2/MAIN.DBF
                                
                                134217728
                        
                
                
                        /dm_home/dmdbms/data/dmks2
                        -1486708862
                        -1155586847
                        1
                        0
                        0
                        0
                        
                        0
                        
                        0
                        1
                        8192
                        16
                        TRUE
                        512
                        0
                        0
                        0x7000A
                        V7.1.6.46-Build(2018.02.08-89107)ENT 
                        FALSE
                        FALSE
                        0
                        TRUE
                
                
        

show backupsets successfully.
time used: 7.438(ms)

DM7使用DMRMAN工具执行加密备份与设置跟踪日志

使用DMRMAN工具执行加密备份与设置跟踪日志
下面介绍使用DMRMAN工具执行加密备份与设置跟踪日志
1.加密备份
DMRMAN同DIsql工具一样可使用加密的方式备份数据库,没有权限的用户无法访问加密的备份集。

DMRMAN备份命令中通过指定IDENTIFIED BY…WITH ENCRYPTION…ENCRYPT WITH…命令执行加密备份。

加密备份过程中参数IDENTIFIED BY必须指定,参数WITH ENCRYPTION和参数ENCRYPT WITH可不指定。加密备份时不指定WITH ENCRYPTION参数,该参数默认为1,不指定ENCRYPT WITH参数,该参数默认值为AES256_CFB。例如,以下两种加密备份命令都是合法的:

RMAN> backup  database 'E:\dmdbms\data\jydm\dm.ini' full backupset 'E:\dmdbms\backup\db_jydm_bak_for_encrypt_01' identified by "abcd123456";
backup database 'E:\dmdbms\data\jydm\dm.ini' full backupset 'E:\dmdbms\backup\db_jydm_bak_for_encrypt_01' identified by ******;
checking if the database under system path [E:\dmdbms\data\jydm] is running...[4].
checking if the database under system path [E:\dmdbms\data\jydm] is running...[3].
checking if the database under system path [E:\dmdbms\data\jydm] is running...[2].
checking if the database under system path [E:\dmdbms\data\jydm] is running...[1].
checking if the database under system path [E:\dmdbms\data\jydm] is running...[0].
checking if the database under system path [E:\dmdbms\data\jydm] is running, write dmrman info.
EP[0] max_lsn: 904411
BACKUP DATABASE [jydm], execute......
CMD CHECK LSN......
BACKUP DATABASE [jydm], collect dbf......
CMD CHECK ......
DBF BACKUP SUBS......
total 1 packages processed...
total 2 packages processed...
total 3 packages processed...
total 4 packages processed...
total 5 packages processed...
total 6 packages processed...
total 7 packages processed...
total 8 packages processed...
DBF BACKUP MAIN......
BACKUPSET [E:\dmdbms\backup\db_jydm_bak_for_encrypt_01] END, CODE [0]......
META GENERATING......
total 9 packages processed...
total 9 packages processed!
CMD END.CODE:[0]
backup successfully!
time used: 8271.759(ms)

RMAN> backup  database 'E:\dmdbms\data\jydm\dm.ini' full backupset 'E:\dmdbms\backup\db_jydm_bak_for_encrypt_02' identified by "abcd123456" encrypt with rc4;
backup database 'E:\dmdbms\data\jydm\dm.ini' full backupset 'E:\dmdbms\backup\db_jydm_bak_for_encrypt_02' identified by ****** encrypt with ******;
checking if the database under system path [E:\dmdbms\data\jydm] is running...[4].
checking if the database under system path [E:\dmdbms\data\jydm] is running...[3].
checking if the database under system path [E:\dmdbms\data\jydm] is running...[2].
checking if the database under system path [E:\dmdbms\data\jydm] is running...[1].
checking if the database under system path [E:\dmdbms\data\jydm] is running...[0].
checking if the database under system path [E:\dmdbms\data\jydm] is running, write dmrman info.
EP[0] max_lsn: 904411
BACKUP DATABASE [jydm], execute......
CMD CHECK LSN......
BACKUP DATABASE [jydm], collect dbf......
CMD CHECK ......
DBF BACKUP SUBS......
total 1 packages processed...
total 2 packages processed...
total 3 packages processed...
total 4 packages processed...
total 5 packages processed...
total 6 packages processed...
total 7 packages processed...
total 8 packages processed...
DBF BACKUP MAIN......
BACKUPSET [E:\dmdbms\backup\db_jydm_bak_for_encrypt_02] END, CODE [0]......
META GENERATING......
total 9 packages processed...
total 9 packages processed!
CMD END.CODE:[0]
backup successfully!
time used: 7166.572(ms)

若指定了加密密码,但加密类型WITH ENCRYPTION参数指定为0,则为非加密备份,如下所示:

RMAN> backup  database 'E:\dmdbms\data\jydm\dm.ini' full backupset 'E:\dmdbms\backup\db_jydm_bak_for_encrypt_03' identified by "abcd123456" with encryption 0;
backup database 'E:\dmdbms\data\jydm\dm.ini' full backupset 'E:\dmdbms\backup\db_jydm_bak_for_encrypt_03' identified by ****** with encryption *;
checking if the database under system path [E:\dmdbms\data\jydm] is running...[4].
checking if the database under system path [E:\dmdbms\data\jydm] is running...[3].
checking if the database under system path [E:\dmdbms\data\jydm] is running...[2].
checking if the database under system path [E:\dmdbms\data\jydm] is running...[1].
checking if the database under system path [E:\dmdbms\data\jydm] is running...[0].
checking if the database under system path [E:\dmdbms\data\jydm] is running, write dmrman info.
EP[0] max_lsn: 904411
BACKUP DATABASE [jydm], execute......
CMD CHECK LSN......
BACKUP DATABASE [jydm], collect dbf......
CMD CHECK ......
DBF BACKUP SUBS......
total 1 packages processed...
total 2 packages processed...
total 3 packages processed...
total 4 packages processed...
total 5 packages processed...
total 6 packages processed...
total 7 packages processed...
total 8 packages processed...
DBF BACKUP MAIN......
BACKUPSET [E:\dmdbms\backup\db_jydm_bak_for_encrypt_03] END, CODE [0]......
META GENERATING......
total 9 packages processed...
total 9 packages processed!
CMD END.CODE:[0]
backup successfully!
time used: 7278.945(ms)

下面以数据库完全备份为例,创建加密密码为“abcd123456”,加密算法为“rc4”的复杂加密类型的数据库加密备份,完整步骤如下:
1) 保证数据库处于关闭状态。
2) 备份数据库。启动DMRMAN工具并输入以下命令。

RMAN> backup  database 'E:\dmdbms\data\jydm\dm.ini' full backupset 'E:\dmdbms\backup\db_jydm_bak_for_encrypt_04' identified by "abcd123456" with encryption 2 encrypt with rc4
backup database 'E:\dmdbms\data\jydm\dm.ini' full backupset 'E:\dmdbms\backup\db_jydm_bak_for_encrypt_04' identified by ****** with encryption * encrypt with ******;
checking if the database under system path [E:\dmdbms\data\jydm] is running...[4].
checking if the database under system path [E:\dmdbms\data\jydm] is running...[3].
checking if the database under system path [E:\dmdbms\data\jydm] is running...[2].
checking if the database under system path [E:\dmdbms\data\jydm] is running...[1].
checking if the database under system path [E:\dmdbms\data\jydm] is running...[0].
checking if the database under system path [E:\dmdbms\data\jydm] is running, write dmrman info.
EP[0] max_lsn: 904411
BACKUP DATABASE [jydm], execute......
CMD CHECK LSN......
BACKUP DATABASE [jydm], collect dbf......
CMD CHECK ......
DBF BACKUP SUBS......
total 1 packages processed...
total 2 packages processed...
total 3 packages processed...
total 4 packages processed...
total 5 packages processed...
total 6 packages processed...
total 7 packages processed...
total 8 packages processed...
DBF BACKUP MAIN......
BACKUPSET [E:\dmdbms\backup\db_jydm_bak_for_encrypt_04] END, CODE [0]......
META GENERATING......
total 9 packages processed...
total 9 packages processed!
CMD END.CODE:[0]
backup successfully!
time used: 7280.960(ms)

对于增量备份加密,如果基备份存在加密,则使用的加密算法和加密密码必须与基备份中一致;如果基备份未进行加密处理,则对增量备份使用的加密密码和算法没有特殊要求。

RMAN> backup  database 'E:\dmdbms\data\jydm\dm.ini' increment with backupdir 'E:\dmdbms\backup' backupset 'E:\dmdbms\backup\db_jydm_bak_incr_for_encrypt_01' identified by "abcd123456" with encryption 2 encrypt with rc4;
backup database 'E:\dmdbms\data\jydm\dm.ini' increment with backupdir 'E:\dmdbms\backup' backupset 'E:\dmdbms\backup\db_jydm_bak_incr_for_encrypt_01' identified by ****** with encryption * encrypt with ******;
checking if the database under system path [E:\dmdbms\data\jydm] is running...[4].
checking if the database under system path [E:\dmdbms\data\jydm] is running...[3].
checking if the database under system path [E:\dmdbms\data\jydm] is running...[2].
checking if the database under system path [E:\dmdbms\data\jydm] is running...[1].
checking if the database under system path [E:\dmdbms\data\jydm] is running...[0].
checking if the database under system path [E:\dmdbms\data\jydm] is running, write dmrman info.
EP[0] max_lsn: 904411
BACKUP DATABASE [jydm], execute......
CMD CHECK LSN......
BACKUP DATABASE [jydm], collect dbf......
CMD CHECK ......
DBF BACKUP SUBS......
total 1 packages processed...
total 2 packages processed...
total 3 packages processed...
total 4 packages processed...
total 5 packages processed...
total 6 packages processed...
total 7 packages processed...
total 8 packages processed...
DBF BACKUP MAIN......
BACKUPSET [E:\dmdbms\backup\db_jydm_bak_incr_for_encrypt_01] END, CODE [0]......
META GENERATING......
total 0 packages processed...
total 9 packages processed!
CMD END.CODE:[-8088],DESC:[无任何数据更新或者日志产生,无需备份]
[-8088]:无任何数据更新或者日志产生,无需备份
RMAN>

2.设置跟踪日志文件
DMRMAN备份时可选择生成跟踪日志文件,跟踪日志记录了SBT接口的调用过程,用户通过查看日志可跟踪备份还原过程。

与生成跟踪日志文件相关的参数有两个,TRACE FILE和TRACE LEVEL。TRACE FILE用于指定生成的跟踪日志文件路径。与DIsql工具不同的是,DMRMAN不可在备份时指定参数生成跟踪文件,只能使用CONFIGURE命令进行事先配置。

使用CONFIGURE DEFAULT…TRACE FILE…TRACE LEVEL命令启用TRACE功能并设TRACE文件路径,以下命令生成TRACE文件到E:\dmdbms\trace目录:

RMAN> configure
configure
THE DMRMAN DEFAULT SETTING:

DEFAULT DEVICE:
        MEDIA : DISK
DEFAULT TRACE :
        FILE  : ..\dm_SBTTRACE_202005.log
        LEVEL : 1
DEFAULT BACKUP DIRECTORY:
        TOTAL COUNT  :1

        E:\dmdbms\backup
DEFAULT ARCHIVE DIRECTORY:
        TOTAL COUNT  :1

                        E:\dmdbms\data\arch
time used: 37.758(ms)
RMAN> configure default trace file 'E:\dmdbms\trace\db_jydm_trace.log' trace level 2;
configure default trace file 'E:\dmdbms\trace\db_jydm_trace.log' trace level 2;
configure default trace successfully!
time used: 3.387(ms)
RMAN> configure
configure
THE DMRMAN DEFAULT SETTING:

DEFAULT DEVICE:
        MEDIA : DISK
DEFAULT TRACE :
        FILE  : E:\dmdbms\trace\db_jydm_trace.log
        LEVEL : 2
DEFAULT BACKUP DIRECTORY:
        TOTAL COUNT  :1

        E:\dmdbms\backup
DEFAULT ARCHIVE DIRECTORY:
        TOTAL COUNT  :1

                        E:\dmdbms\data\arch
time used: 40.347(ms)

指定参数TRACE FILE但TRACE LEVEL值设置为1即不启用TRACE功能,会生成TRACE文件,但不会写入TRACE信息。如下所示:

RMAN> configure default trace clear;
configure default trace clear;
configure default trace clear successfully!
time used: 2.183(ms)
RMAN> configure
configure
THE DMRMAN DEFAULT SETTING:

DEFAULT DEVICE:
        MEDIA : DISK
DEFAULT TRACE :
        FILE  :
        LEVEL : 1
DEFAULT BACKUP DIRECTORY:
        TOTAL COUNT  :1

        E:\dmdbms\backup
DEFAULT ARCHIVE DIRECTORY:
        TOTAL COUNT  :1

                        E:\dmdbms\data\arch
time used: 46.771(ms)

RMAN> configure default trace file 'E:\dmdbms\trace\db_jydm_trace.log' trace level 1;
configure default trace file 'E:\dmdbms\trace\db_jydm_trace.log' trace level 1;
configure default trace successfully!
time used: 4.799(ms)

TRACE LEVEL值设置为2即启用TRACE功能,但若TRACE FILE没有指定,系统默认在执行码路径的log目录下生成DM_SBTTRACE_年月.log文件。
如下所示:

RMAN> configure default trace level 2;
configure default trace level 2;
configure default trace successfully!
time used: 3.124(ms)

若TRACE FILE使用相对路径,日志文件则生成在执行码同级目录下。
为数据库脱机备份设置跟踪日志文件的操作步骤如下:
1) 保证数据库处于关闭状态。
2) 使用CONFIGURE命令配置生成跟踪日志文件。

RMAN> configure default trace file 'E:\dmdbms\trace\db_jydm_trace.log' trace level 2;
configure default trace file 'E:\dmdbms\trace\db_jydm_trace.log' trace level 2;
configure default trace successfully!
time used: 2.705(ms)

查看E:\dmdbms\trace\db_jydm_trace.log文件即可跟踪本次备份的SBT接口调用过程。
如果指定的TRACE文件已存在,服务器不会覆盖已存在的文件而是在已有文件基础上继续记录日志。

RMAN> configure default trace file 'E:\dmdbms\trace\db_jydm_trace.log' trace level 1;
configure default trace file 'E:\dmdbms\trace\db_jydm_trace.log' trace level 1;
[-8086]:无效的TRACE文件[E:\dmdbms\trace\db_jydm_trace.log]

DM7使用DMRMAN执行归档备份

使用脱机工具DMRMAN执行归档备份
1. 概述
在DMRMAN工具中使用BACKUP命令你可以备份数据库的归档。关闭服务器在DMRMAN中输入以下命令即可备份归档:

RMAN> backup archive log database 'E:\dmdbms\data\jydm\dm.ini';
backup archive log database 'E:\dmdbms\data\jydm\dm.ini';
checking if the database under system path [E:\dmdbms\data\jydm] is running...[4].
checking if the database under system path [E:\dmdbms\data\jydm] is running...[3].
checking if the database under system path [E:\dmdbms\data\jydm] is running...[2].
checking if the database under system path [E:\dmdbms\data\jydm] is running...[1].
checking if the database under system path [E:\dmdbms\data\jydm] is running...[0].
checking if the database under system path [E:\dmdbms\data\jydm] is running, write dmrman info.
EP[0] max_lsn: 901685
BACKUP ARCHIVE LOG ALL, execute......
CMD CHECK LSN......
BACKUP ARCHIVE LOG ALL, collect dbf......
CMD CHECK ......
ARCH BACKUP SUBS......
total 1 packages processed...
total 2 packages processed...
total 3 packages processed...
total 4 packages processed...
ARCH BACKUP MAIN......
BACKUPSET [E:\dmdbms\data\jydm\bak\ARCH_LOG_20200531_193129_000908] END, CODE [0]......
META GENERATING......
total 5 packages processed...
total 5 packages processed!
CMD END.CODE:[0]
backup successfully!
time used: 7252.182(ms)

命令执行完后会在默认的备份路径下生成备份集目录,默认的备份路径为dm.ini中BAK_PATH的配置值,若未配置,则使用SYSTEM_PATH下的bak目录。这是最简单的脱机归档备份语句,如果要设置其他备份选项请参考下文的语法及使用说明。

语法如下:

BACKUP
[ALL | [FROM LSN ]|[UNTIL LSN ] | [LSN BETWEEN < lsn值> AND < lsn值>] | [FROM TIME '时间串'] |
[UNTIL TIME '时间串'] | [TIME BETWEEN '时间串' AND '时间串']] [][DELETE INPUT]
DATABASE ''
[TO < 备份名>] [BACKUPSET '< 备份集目录>'] [DEVICE TYPE < 介质类型>[PARMS '< 介质参数>']
[BACKUPINFO '< 备份描述>'] [MAXPIECESIZE < 备份片限制大小>]
[IDENTIFIED BY < 加密密码>[WITH ENCRYPTION][ENCRYPT WITH < 加密算法>]]
[COMPRESSED [LEVEL < 压缩级别>]][TASK THREAD < 线程数>][PARALLEL [< 并行数>]];
::=NOT BACKED UP
| NOT BACKED UP numTIMES
| NOT BACKED UP SINCE TIME 'datetime_string'

ALL:备份所有的归档;
FROM LSN ,UNTIL LSN:备份的起始和截止lsn。请参考3.2.2.4归档备份
FROM TIME:指定备份的开始时间点。例如,’2015-12-10’。
UNTIL TIME:指定备份的截止时间点。
BETWEEN …AND …:指定备份的区间,仅仅指备份区间内的归档文件。
:搜索过滤。搜索过滤仅限于根据备份指定条件能找到的所有归档备份集。1) num TIMES,指若归档文件已经备份了num次,则不再备份;否则备份。如num=3,则认为已经备份了3次的归档文件就不再备份。若num=0,则认为所有都不需要备份。2)SINCE TIME ‘datetime_String’,指定时间开始没有备份的归档文件进行备份。3)若以上两种均未指定,则备份所有未备份过的归档日志文件。
DELETE INPUT:用于指定备份完,是否删除归档操作。
DATABASE:必选参数。指定备份目标库的INI文件路径。
TO: 指定生成备份名称。若未指定,系统随机生成,默认备份名格式为:ARCH_备份时间。
BACKUPSET: 指定当前备份集生成目录。若指定为相对路径,则在默认备份路径中生成备份集。
DEVICE TYPE:指存储备份集的介质类型,支持DISK和TAPE,默认DISK。DISK表示存储备份集到磁盘,TAPE表示存储到磁带。
PARMS:只对介质类型为TAPE时有效。
BACKUPINFO:备份的描述信息。最大不超过256个字节。
MAXPIECESIZE:最大备份片文件大小上限,以M为单位,最小128M,32位系统最大2G,64位系统最大128G。
IDENTIFIED BY:指定备份时的加密密码。密码应用双引号括起来,这样避免一些特殊字符通不过语法检测。密码的设置规则遵行ini参数pwd_policy指定的口令策略。
WITH ENCRYPTION:指定加密类型,0表示不加密,不对备份文件进行加密处理;1表示简单加密,对备份文件设置口令,但文件内容仍以明文存;2表示完全数据加密,对备份文件进行完全的加密,备份文件以密文方式存储。
ENCRYPT WITH:加密算法。缺省情况下,算法为AES256_CFB。具体可以使用的加密算法参考联机数据库备份章节的参数说明。
COMPRESSED:取值范围0~9。0表示不压缩,1表示1级压缩,9表示9级压缩。压缩级别越高,压缩越慢,但压缩比越高。若未指定,但指定COMPRESSED,则默认1;否则,默认0。
TASK THREAD:备份过程中数据处理过程线程的个数,取值范围0~64,默认为4。若指定为0,则调整为1;若指定超过当前系统主机核数,则调整为主机核数。线程数(TASK THREAD)*并行数(PARALLEL)不得超过512。
PARALLEL:指定并行备份的并行数,取值范围0~128。若不指定,则默认为4,指定0或者1均认为为非并行备份。若未指定关键PARALLEL,则认为非并行备份。并行备份不支持介质为TAPE的备份。线程数(TASK THREAD)*并行数(PARALLEL)不得超过512。

2. 备份归档
本节主要描述使用DMRMAN如何执行基本的脱机归档备份及实施一些备份策略,包括:
1. 设置备份选项
2. 创建归档备份
3. 创建设置条件的归档备份

1.设置备份选项
备份命令如果仅指定了必选参数如“BACKUP ARCHIVE LOG DATABASE ‘/opt/dmdbms/data/DAMENG/dm.ini’”,那么DMRMAN会根据配置的环境及内置的参数默认值自动指定备份介质类型、备份路径、备份片大小等参数。用户备份时也可以指定这些参数来覆盖默认值,常见的备份选项有设置备份集路径、指定备份名、限制备份片大小、添加描述信息、并行备份等。DMRMAN脱机备份归档的语法与使用DIsql联机备份类似,关于备份选项的详细介绍及使用参见3.2.2.3.2 设置备份选项。

2.创建归档备份
执行归档备份要求数据库处于脱机状态。与联机备份数据库一样,脱机归档备份需要配置归档。一个完整的创建脱机数据库备份的示例如下:
1) 启动DMRMAN命令行工具。
2) 保证数据库处于脱机状态。
3) DMRMAN中输入以下命令:

RMAN> backup archive log all database 'E:\dmdbms\data\jydm\dm.ini' backupset 'E:\dmdbms\backup\arch_all_bak_01';
backup archive log all database 'E:\dmdbms\data\jydm\dm.ini' backupset 'E:\dmdbms\backup\arch_all_bak_01';
checking if the database under system path [E:\dmdbms\data\jydm] is running...[4].
checking if the database under system path [E:\dmdbms\data\jydm] is running...[3].
checking if the database under system path [E:\dmdbms\data\jydm] is running...[2].
checking if the database under system path [E:\dmdbms\data\jydm] is running...[1].
checking if the database under system path [E:\dmdbms\data\jydm] is running...[0].
checking if the database under system path [E:\dmdbms\data\jydm] is running, write dmrman info.
EP[0] max_lsn: 901685
BACKUP ARCHIVE LOG ALL, execute......
CMD CHECK LSN......
BACKUP ARCHIVE LOG ALL, collect dbf......
CMD CHECK ......
ARCH BACKUP SUBS......
total 1 packages processed...
total 2 packages processed...
total 3 packages processed...
total 4 packages processed...
ARCH BACKUP MAIN......
BACKUPSET [E:\dmdbms\backup\arch_all_bak_01] END, CODE [0]......
META GENERATING......
total 5 packages processed...
total 5 packages processed!
CMD END.CODE:[0]
backup successfully!
time used: 8221.506(ms)

命令中的ALL参数表示执行的备份为备份所有的归档,也可以不指定该参数,DMRMAN默认执行的备份类型为ALL类型归档备份。

3.创建设置条件的归档备份
设置条件的归档备份指通过设置LSN或者时间点,控制归档需要备份归档的范围。脱机设置条件归档备份。增量备份示例如下:

D:\>net start DmServicejydm
DmServicejydm 服务正在启动 ....
DmServicejydm 服务已经启动成功。


D:\>disql sysdba/xxzx7817600

服务器[LOCALHOST:5236]:处于普通打开状态
登录使用时间: 10.068(毫秒)
disql V7.1.6.48-Build(2018.03.01-89507)ENT
Connected to: DM 7.1.6.48
SQL> select * from v$arch_file;

行号       DB_MAGIC    STATUS   LEN                  FREE                 ARCH_LSN             CLSN                 ARCH_SEQ             NEXT_SEQ             CREATE_TIME                 CLOSE_TIME                  PATH
---------- ----------- -------- -------------------- -------------------- -------------------- -------------------- -------------------- -------------------- --------------------------- --------------------------- ----------------------------------------------------------
1          -430050549  INACTIVE 225792               225792               892254               894139               161798               162230               2020-05-31 10:17:40.810000  2020-05-31 11:52:15.732000  E:\dmdbms\data\arch\ARCHIVE_LOCAL1_20200531101740800_0.log
2          -430050549  INACTIVE 282112               282112               894139               896221               162231               162773               2020-05-31 11:52:15.732000  2020-05-31 18:10:29.344000  E:\dmdbms\data\arch\ARCHIVE_LOCAL1_20200531115215733_0.log
3          -430050549  INACTIVE 198656               198656               896222               898933               162774               163153               2020-05-31 18:10:29.344000  2020-05-31 18:11:41.803000  E:\dmdbms\data\arch\ARCHIVE_LOCAL1_20200531181130589_0.log
4          -430050549  INACTIVE 202752               202752               898934               901685               163154               163541               2020-05-31 18:11:41.803000  2020-05-31 19:22:33.194000  E:\dmdbms\data\arch\ARCHIVE_LOCAL1_20200531192047977_0.log
5          -430050549  ACTIVE   1073741824           4608                 901686               901686               163542               163542               2020-05-31 19:22:33.194000  2020-05-31 19:41:37.396000  E:\dmdbms\data\arch\ARCHIVE_LOCAL1_20200531194137390_0.log

已用时间: 7.243(毫秒). 执行号:3.
SQL> begin
2   for i in 11 .. 20 loop
3   insert into t2 values(i);
4   end loop;
5   commit;
6   end;
7   /
DMSQL 过程已成功完成
已用时间: 3.688(毫秒). 执行号:4.
SQL> alter system switch logfile;
操作已执行
已用时间: 15.692(毫秒). 执行号:0.
SQL> select * from v$arch_file;

行号       DB_MAGIC    STATUS   LEN                  FREE                 ARCH_LSN             CLSN                 ARCH_SEQ             NEXT_SEQ             CREATE_TIME                 CLOSE_TIME                  PATH
---------- ----------- -------- -------------------- -------------------- -------------------- -------------------- -------------------- -------------------- --------------------------- --------------------------- ----------------------------------------------------------
1          -430050549  ACTIVE   1073741824           4096                 0                    0                    0                    0                    2020-05-31 19:43:28.792000  2020-05-31 19:43:28.797000  E:\dmdbms\data\arch\ARCHIVE_LOCAL1_20200531194328794_0.log
2          -430050549  INACTIVE 225792               225792               892254               894139               161798               162230               2020-05-31 10:17:40.810000  2020-05-31 11:52:15.732000  E:\dmdbms\data\arch\ARCHIVE_LOCAL1_20200531101740800_0.log
3          -430050549  INACTIVE 282112               282112               894139               896221               162231               162773               2020-05-31 11:52:15.732000  2020-05-31 18:10:29.344000  E:\dmdbms\data\arch\ARCHIVE_LOCAL1_20200531115215733_0.log
4          -430050549  INACTIVE 198656               198656               896222               898933               162774               163153               2020-05-31 18:10:29.344000  2020-05-31 18:11:41.803000  E:\dmdbms\data\arch\ARCHIVE_LOCAL1_20200531181130589_0.log
5          -430050549  INACTIVE 202752               202752               898934               901685               163154               163541               2020-05-31 18:11:41.803000  2020-05-31 19:22:33.194000  E:\dmdbms\data\arch\ARCHIVE_LOCAL1_20200531192047977_0.log
6          -430050549  INACTIVE 143872               143872               901686               903130               163542               163814               2020-05-31 19:22:33.194000  2020-05-31 19:43:28.792000  E:\dmdbms\data\arch\ARCHIVE_LOCAL1_20200531194137390_0.log

6 rows got

已用时间: 8.257(毫秒). 执行号:5.
SQL> checkpoint(100);
DMSQL 过程已成功完成
已用时间: 19.634(毫秒). 执行号:6.
SQL> alter database archivelog current;
操作已执行
已用时间: 15.156(毫秒). 执行号:0.
SQL> select * from v$arch_file;

行号       DB_MAGIC    STATUS   LEN                  FREE                 ARCH_LSN             CLSN                 ARCH_SEQ             NEXT_SEQ             CREATE_TIME                 CLOSE_TIME                  PATH
---------- ----------- -------- -------------------- -------------------- -------------------- -------------------- -------------------- -------------------- --------------------------- --------------------------- ----------------------------------------------------------
1          -430050549  ACTIVE   1073741824           4096                 0                    0                    0                    0                    2020-05-31 19:44:15.929000  2020-05-31 19:44:15.934000  E:\dmdbms\data\arch\ARCHIVE_LOCAL1_20200531194415931_0.log
2          -430050549  INACTIVE 225792               225792               892254               894139               161798               162230               2020-05-31 10:17:40.810000  2020-05-31 11:52:15.732000  E:\dmdbms\data\arch\ARCHIVE_LOCAL1_20200531101740800_0.log
3          -430050549  INACTIVE 282112               282112               894139               896221               162231               162773               2020-05-31 11:52:15.732000  2020-05-31 18:10:29.344000  E:\dmdbms\data\arch\ARCHIVE_LOCAL1_20200531115215733_0.log
4          -430050549  INACTIVE 198656               198656               896222               898933               162774               163153               2020-05-31 18:10:29.344000  2020-05-31 18:11:41.803000  E:\dmdbms\data\arch\ARCHIVE_LOCAL1_20200531181130589_0.log
5          -430050549  INACTIVE 202752               202752               898934               901685               163154               163541               2020-05-31 18:11:41.803000  2020-05-31 19:22:33.194000  E:\dmdbms\data\arch\ARCHIVE_LOCAL1_20200531192047977_0.log
6          -430050549  INACTIVE 143872               143872               901686               903130               163542               163814               2020-05-31 19:22:33.194000  2020-05-31 19:43:28.792000  E:\dmdbms\data\arch\ARCHIVE_LOCAL1_20200531194137390_0.log
7          -430050549  INACTIVE 9728                 9728                 903130               903130               163815               163825               2020-05-31 19:43:28.792000  2020-05-31 19:44:15.929000  E:\dmdbms\data\arch\ARCHIVE_LOCAL1_20200531194328794_0.log

7 rows got

1) 启动DMRMAN命令行工具。
2) 保证数据库处于脱机状态。

D:\>net stop DmServicejydm
DmServicejydm 服务正在停止...
DmServicejydm 服务已成功停止。

3) DMRMAN中输入以下命令:

RMAN> backup archive log lsn between 901686 and 903130 database 'E:\dmdbms\data\jydm\dm.ini' backupset 'E:\dmdbms\backup\arch_lsn_bak_01';
backup archive log lsn between 901686 and 903130 database 'E:\dmdbms\data\jydm\dm.ini' backupset 'E:\dmdbms\backup\arch_lsn_bak_01';
checking if the database under system path [E:\dmdbms\data\jydm] is running...[4].
checking if the database under system path [E:\dmdbms\data\jydm] is running...[3].
checking if the database under system path [E:\dmdbms\data\jydm] is running...[2].
checking if the database under system path [E:\dmdbms\data\jydm] is running...[1].
checking if the database under system path [E:\dmdbms\data\jydm] is running...[0].
checking if the database under system path [E:\dmdbms\data\jydm] is running, write dmrman info.
EP[0] max_lsn: 904411
BACKUP ARCHIVE LOG FROM LSN 901686 TO LSN 903130, execute......
CMD CHECK LSN......
BACKUP ARCHIVE LOG FROM LSN 901686 TO LSN 903130, collect dbf......
CMD CHECK ......
ARCH BACKUP SUBS......
total 1 packages processed...
total 2 packages processed...
ARCH BACKUP MAIN......
BACKUPSET [E:\dmdbms\backup\arch_lsn_bak_01] END, CODE [0]......
META GENERATING......
total 3 packages processed...
total 3 packages processed!
CMD END.CODE:[0]
backup successfully!
time used: 7313.615(ms)

命令中的LSN BETEEWN start AND end参数表示执行的备份为执行备份的区间,或者设置FROM LSN(TIME)以及UNTIL LSN(TIME)。