达梦7备份与还原

前言

本文档介绍了达梦7的备份与还原相关操作。详细的文档,可以查看达梦安装目录下的文件doc/special/DM7备份与还原.pdf

基础概念

备份集

这个概念频繁出现在文档和命令中,一定要先熟悉。

备份集用来存放备份过程中产生的备份数据及备份信息。一个备份集对应了一次完整的备份*。 一般情况下, 一个备份集就是一个目录, 备份集包含一个或多个备份片文件,以及一个备份元数据文件。

下图展示了一个备份集

# tree db_full_2020_02_25

db_full_2020_02_25
├── db_full_2020_02_25_1.bak (redo日志备份)
├── db_full_2020_02_25.bak (数据页文件)
└── db_full_2020_02_25.meta (元数据)

逻辑备份和物理备份

  1. 逻辑备份就是将指定对象(库级、模式级、表级)的数据导出到
    文件的备份方式。 逻辑备份针对的是数据内容,并不关心这些数据物理存储在什么位置。

  2. 物理备份则直接扫描数据库文件,找出那些已经分配、使用的数据页,拷贝并保存到备份集中。物理备份过程中,不关心数据页的具体内容是什么,也不关心数据页属于哪一张表,只是简单的根据数据库文件系统的描述,来挑选有效的数据页。

本文只涉及物理备份

联机备份与脱机备份

顾名思义,就是备份的时候数据库实例是否正常在线,可以分为联机备份和脱机备份。

由于数据库无时无刻不在工作,为了保证备份的完整性,在备份的时候,关闭数据库实例就可以保证备份期间数据的完整性和一致性。

但是如果每次备份都要关闭数据库实例,在多数线上场景并不可行。在联机备份时,可能存在一些处于活动状态的事务正在执行,为确保备份数据的一致性,需要将备份期间产生的 REDO 日志一起备份。 因此,只能在配置本地归档、并开启本地归档的数据库上执行联机备份。

使用DMRMAN脱机备份与还原

对于脱机备份,首选DMRMAN工具,DMRMAN(DM RECOVERY MANEGER)是 DM7 的脱机备份还原管理工具,由它来统一负责库级脱机备份、脱机还原、数据库恢复等相关操作,该工具支持命令行指定参数方式和控制台交互方式执行,降低了用户的操作难度。

要点:

  1. dmap服务一定要启动

  2. 执行dmrman一定要使用数据库的所有者用户,不能是root

使用前准备工作

cd $DM_HOME/bin
./dmap

使用dmrman必须确保dmap服务启动

启动dmrman交互式控制台

su dmdba (这里按照实际的数据库用户切换)
cd $DM_HOME/bin
./dmrman

执行备份动作

dmrman V7.6.0.209-Build(2019.10.25-114655)ENT 
RMAN> BACKUP DATABASE'/opt/dmdbms/data/DAMENG/dm.ini';
BACKUP DATABASE '/opt/dmdbms/data/DAMENG/dm.ini';
checking if the database under system path [/opt/dmdbms/data/DAMENG] is running...[4].
checking if the database under system path [/opt/dmdbms/data/DAMENG] is running...[3].
the database under system path [/opt/dmdbms/data/DAMENG] is running.

我们可以看到,上述命令出现错误,因为数据库实例没有关闭

systemctl stop DmServiceGSDOA.service

重新执行备份命令

dmrman V7.6.0.209-Build(2019.10.25-114655)ENT 
RMAN> BACKUP DATABASE'/opt/dmdbms/data/DAMENG/dm.ini';
BACKUP DATABASE '/opt/dmdbms/data/DAMENG/dm.ini';
checking if the database under system path [/opt/dmdbms/data/DAMENG] is running...[4].
checking if the database under system path [/opt/dmdbms/data/DAMENG] is running...[3].
checking if the database under system path [/opt/dmdbms/data/DAMENG] is running...[2].
checking if the database under system path [/opt/dmdbms/data/DAMENG] is running...[1].
checking if the database under system path [/opt/dmdbms/data/DAMENG] is running...[0].
checking if the database under system path [/opt/dmdbms/data/DAMENG] is running, write dmrman info.
EP[0] max_lsn: 12895683
BACKUP DATABASE [DAMENG],execute......
CMD CHECK LSN......
BACKUP DATABASE [DAMENG],collect dbf......
CMD CHECK ......
DBF BACKUP SUBS......
total 1 packages processed...
total 3 packages processed...
total 4 packages processed...
total 7 packages processed...
total 8 packages processed...
total 30 packages processed...
total 52 packages processed...
DBF BACKUP MAIN......
BACKUPSET [/opt/dmdbms/data/DAMENG/bak/DB_DAMENG_FULL_20200225_110522_000950] END, CODE [0]......
META GENERATING......
total 56 packages processed...
total 56 packages processed!
CMD END.CODE:[0]
backup successfully!
time used: 30721.841(ms)

dmap启动失败怎么办

删除 dmap 同目录下的文件

rm -rf DM_PIPE_DMAP*

执行还原动作

假设我们要还原的数据库为:/opt/dmdbms/dd/gck/dm.ini,备份集目录在:/tmp/DB_FULL_2020_01_17

先执行 restore

RMAN> RESTORE DATABASE '/opt/dmdbms/dd/gck/dm.ini' FROM BACKUPSET '/tmp/DB_FULL_2020_01_17';
RESTORE DATABASE '/opt/dmdbms/dd/gck/dm.ini' FROM BACKUPSET '/tmp/DB_FULL_2020_01_17';
checking if the database under system path [/opt/dmdbms/dd/gck] is running...[4].
checking if the database under system path [/opt/dmdbms/dd/gck] is running...[3].
checking if the database under system path [/opt/dmdbms/dd/gck] is running...[2].
checking if the database under system path [/opt/dmdbms/dd/gck] is running...[1].
checking if the database under system path [/opt/dmdbms/dd/gck] is running...[0].
checking if the database under system path [/opt/dmdbms/dd/gck] is running, write dmrman info.
RESTORE DATABASE CHECK......
RESTORE DATABASE,dbf collect......
RESTORE DATABASE,dbf refresh ......
RESTORE BACKUPSET [/tmp/DB_FULL_2020_01_17/DB_FULL_2020_01_17_0] START......
total 1 packages processed...
RESTORE BACKUPSET [/tmp/DB_FULL_2020_01_17/DB_FULL_2020_01_17_3] START......
total 1 packages processed...
RESTORE BACKUPSET [/tmp/DB_FULL_2020_01_17/DB_FULL_2020_01_17_1] START......
total 3 packages processed...
RESTORE BACKUPSET [/tmp/DB_FULL_2020_01_17/DB_FULL_2020_01_17_2] START......
total 6 packages processed...
RESTORE DATABASE,UPDATE ctl file......
RESTORE DATABASE,REBUILD key file......
RESTORE DATABASE,CHECK db info......
RESTORE DATABASE,UPDATE db info......
total 29 packages processed!
CMD END.CODE:[0]
restore successfully.
time used: 15222.155(ms)

再执行recover

RMAN> RECOVER DATABASE '/opt/dmdbms/dd/gck/dm.ini' FROM BACKUPSET '/tmp/DB_FULL_2020_01_17';
RECOVER DATABASE '/opt/dmdbms/dd/gck/dm.ini' FROM BACKUPSET '/tmp/DB_FULL_2020_01_17';
checking if the database under system path [/opt/dmdbms/dd/gck] is running...[4].
checking if the database under system path [/opt/dmdbms/dd/gck] is running...[3].
checking if the database under system path [/opt/dmdbms/dd/gck] is running...[2].
checking if the database under system path [/opt/dmdbms/dd/gck] is running...[1].
checking if the database under system path [/opt/dmdbms/dd/gck] is running...[0].
checking if the database under system path [/opt/dmdbms/dd/gck] is running, write dmrman info.
EP[0] max_lsn: 461621
RESTORE RLOG  CHECK......
RESTORE RLOG ,gen tmp file......
RESTORE RLOG FROM BACKUPSET [/tmp/DB_FULL_2020_01_17] START......
total 0 packages processed...
total 2 packages processed!
CMD END.CODE:[0]

EP[0] Recover LSN from 461622 to 461790.
Recover from archive log finished, time used:0.076s.
recover successfully!
time used: 7028.527(ms)