使用脱机工具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 …:指定备份的区间,仅仅指备份区间内的归档文件。
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)。