ITPub博客

首页 > 数据库 > 国内数据库 > DM8数据备份还原

DM8数据备份还原

原创 国内数据库 作者:zhaobw_0626 时间:2021-08-09 19:17:08 0 删除 编辑
DM8的备份分为物理备份和逻辑备份:
为什么要做备份?防止软硬件故障、误操作、天灾 (异地容灾)。且要使用物理备份和逻辑备份相结合来进行备份;
1、物理备份:备份的是数据文件
1.1 冷备份(不常用):
冷备份的场景:
·  数据库服务是关闭的;
·  需要启动 DMAP服务;
关闭数据库:
--root用户关闭:
[root@dm8alone etc]# systemctl stop DmServiceTEST.service
[root@dm8alone etc]# systemctl status DmAPService.service
--dmdba用户关闭:
[dmdba@dm8alone ~]$ cd /dm8/bin
--查看实例服务:
[dmdba@dm8alone bin]$ ./DmServiceTEST status
DmServiceTEST (pid 6204) is running.
--关闭数据库实例服务:
[dmdba@dm8alone bin]$ ./DmServiceTEST stop
Stopping DmServiceTEST: [ OK ]
--查看DmAP服务是否启动,如果没启动则启动:
[dmdba@dm8alone bin]$ ./DmAPService status
[dmdba@dm8alone bin]$ ./DmAPService start
[dmdba@dm8alone dm8]$ mkdir backup
[dmdba@dm8alone bin]$
--进入bin目录执行dmrman命令:
[dmdba@dm8alone bin]$ ./dmrman
dmrman V8
RMAN> backup database '/dm8/data/DAMENG/dm.ini' backupset '/dm8/backup/20200712';
backup database '/dm8/data/DAMENG/dm.ini' backupset '/dm8/backup/20200712';
file dm.key not found, use default license!
Database mode = 0, oguid = 0
EP[0]'s cur_lsn[43509]
BACKUP DATABASE [DAMENG],execute......
CMD CHECK LSN......
BACKUP DATABASE [DAMENG],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 [/dm8/backup/20200712] END, CODE [0]......
META GENERATING......
total 7 packages processed...
total 7 packages processed...
total 7 packages processed!
CMD END.CODE:[0]
backup successfully!
time used: 00:00:01.182
RMAN>exit
备份后的文件如下图:
  此时将数据文件移走(模拟故障):

 

RMAN>restore database '/dm8/data/DAMENG/dm.ini' from backupset '/dm8/backup/20200712';
restore database '/dm8/data/DAMENG/dm.ini' from backupset '/dm8/backup/20200712';
file dm.key not found, use default license!
RESTORE DATABASE CHECK......
RESTORE DATABASE,data collect......
RESTORE DATABASE,database refresh ......
RESTORE BACKUPSET [/dm8/backup/20200712] START......
total 5 packages processed...
total 7 packages processed...
RESTORE DATABASE,UPDATE ctl file......
RESTORE DATABASE,REBUILD key file......
RESTORE DATABASE,CHECK db info......
RESTORE DATABASE,UPDATE db info......
total 7 packages processed...
total 7 packages processed!
CMD END.CODE:[0]
restore successfully.
time used: 334.217(ms)
RMAN>
restore以后,再看数据文件,已经恢复回来了:

 

可见, restore的过程,其实就是把数据文件复制到原路径下的一个过程。但是,此时直接启动服务仍会报错,因为DM8比DM7多了更新db_magic这个步骤,如果不更新db_magic,会报以下错误:
[dmdba@dm8alone bin]$ ./DmServiceTEST start
Starting DmServiceTEST: [ FAILED ]
file dm.key not found, use default license!
version info: develop
Use normal os_malloc instead of HugeTLB
Use normal os_malloc instead of HugeTLB
DM Database Server x64 V8 1-1-78-20.04.28-121039-ENT startup...
Database mode = 0, oguid = 0
License will expire on 2021-04-28
Instance TEST startup failed, execute 'recover database ... update db_magic' in dmrman.
--更新db_magic的步骤:
RMAN> recover database '/dm8/data/DAMENG/dm.ini' update db_magic;
recover database '/dm8/data/DAMENG/dm.ini' update db_magic;
file dm.key not found, use default license!
Database mode = 0, oguid = 0
EP[0]'s cur_lsn[43509]
EP[0]'s apply_lsn[43509] >= end_lsn[43509]
recover successfully!
time used: 00:00:01.051
RMAN>
此时,实例就可以正常启动了:
[dmdba@dm8alone bin]$ ./DmServiceTEST start
Starting DmServiceTEST: [ OK ]
[dmdba@dm8alone bin]$
由于冷备份在备份之后到出现故障这个时间段内的数据无法找回,而且需要停数据库服务,因此生产环境中不建议使用冷备份。
--冷备份也可以使用控制台工具来做:

 

选择备份还原后,新建备份即可:
  比较简单,这里就不再赘述了,下面看看如何做热备份。
1.2 热备:生产环境大部分都是使用热备份
热备份的场景:
·  数据库是打开的;
·  需要启动 DMAP服务;
·  需要启动归档;
--查看和启动数据库服务:
[dmdba@dm8alone bin]$ ./DmServiceTEST status
[dmdba@dm8alone bin]$ ./DmServiceTEST start
--查看和启动DMAP服务:
[dmdba@dm8alone bin]$ ./DmAPService status
[dmdba@dm8alone bin]$ ./DmAPService start
--启用归档、设置归档大小和最大值:
SQL> alter database mount;
SQL> alter database add archivelog 'DEST = /dm8/dmarch, type= local,file_size = 128 ,space_limit = 10240';
SQL> alter database archivelog;
SQL> alter database open;
--查看归档模式:
SQL> select arch_mode from v$database;
热备份可以备份数据库、表空间、表和归档;
--备份数据库:
SQL> backup database backupset '/dm8/backup/db_bak';
操作已执行
已用时间 : 978.702(毫秒). 执行号:5.
--备份表空间:
SQL> backup tablespace tbs backupset '/dm8/backup/tbs';
操作已执行
已用时间 : 820.071(毫秒). 执行号:6.
--备份表:
SQL> backup table sysdba.t1 backupset '/dm8/backup/t1';
操作已执行
已用时间 : 936.143(毫秒). 执行号:8.
--备份归档:
SQL> backup archivelog backupset '/dm8/backup/arch';
操作已执行
已用时间 : 806.614(毫秒). 执行号:9.
--假设表空间损坏或丢失:

 

通过以下步骤来进行还原:
--停掉数据库服务:
[dmdba@dm8alone bin]$ ./DmServiceTEST stop
Stopping DmServiceTEST: [ OK ]
[dmdba@dm8alone bin]$
--还原表空间:
RMAN> restore database '/dm8/data/DAMENG/dm.ini' tablespace tbs from backupset '/dm8/backup/tbs';
restore database '/dm8/data/DAMENG/dm.ini' tablespace tbs from backupset '/dm8/backup/tbs';
file dm.key not found, use default license!
RESTORE TABLESPACE[tbs] IN DB[/dm8/data/DAMENG/dm.ini] CHECK......
Database mode = 0, oguid = 0
EP[0]'s cur_lsn[44941]
RESTORE TABLESPACE[tbs] IN DB[/dm8/data/DAMENG/dm.ini],dbf collect......
RESTORE TABLESPACE[tbs] IN DB[/dm8/data/DAMENG/dm.ini],ts status and dbf refresh ......
RESTORE BACKUPSET [/dm8/backup/tbs] START......
total 2 packages processed...
total 4 packages processed...
RESTORE TABLESPACE[tbs] IN DB[/dm8/data/DAMENG/dm.ini],UPDATE ctl file......
total 4 packages processed...
total 4 packages processed!
CMD END.CODE:[0]
restore successfully.
time used: 446.610(ms)
RMAN>
--恢复表空间:
RMAN> recover database '/dm8/data/DAMENG/dm.ini' tablespace tbs;
recover database '/dm8/data/DAMENG/dm.ini' tablespace tbs;
Database mode = 0, oguid = 0
[WARN]tablespace TBS is corrupted(state: 2), restore or drop please.
EP[0]'s cur_lsn[44941]
RECOVER TABLESPACE[tbs] IN DB[/dm8/data/DAMENG/dm.ini] CHECK......
EP[0]'s cur_lsn[44941]
EP:0 total 2 pkgs applied, percent: 12%
EP:0 total 4 pkgs applied, percent: 25%
EP:0 total 6 pkgs applied, percent: 37%
EP:0 total 8 pkgs applied, percent: 50%
EP:0 total 10 pkgs applied, percent: 62%
EP:0 total 12 pkgs applied, percent: 75%
EP:0 total 14 pkgs applied, percent: 87%
EP:0 total 16 pkgs applied, percent: 100%
Recover from archive log finished, time used:0.029s.
CMD END.CODE:[0]
recover successfully.
time used: 533.927(ms)
RMAN>
查看数据文件,已经恢复回来了:

 

--启动数据库服务:
[dmdba@dm8alone bin]$ ./DmServiceTEST start
Starting DmServiceTEST: [ OK ]
[dmdba@dm8alone bin]$
注: DMRMAN不支持热备份。
--数据库、表和归档的热备份还原和恢复命令如下 ,大家可以逐一来测试一下:
--还原数据库:
RMAN> restore database '/dm8/data/DAMENG/dm.ini' from backupset '/dm8/backup/db_bak';
restore database '/dm8/data/DAMENG/dm.ini' from backupset '/dm8/backup/db_bak';
file dm.key not found, use default license!
RESTORE DATABASE CHECK......
RESTORE DATABASE,data collect......
RESTORE DATABASE,database refresh ......
RESTORE BACKUPSET [/dm8/backup/db_bak] START......
total 5 packages processed...
total 7 packages processed...
RESTORE DATABASE,UPDATE ctl file......
RESTORE DATABASE,REBUILD key file......
RESTORE DATABASE,CHECK db info......
RESTORE DATABASE,UPDATE db info......
total 7 packages processed...
total 7 packages processed!
CMD END.CODE:[0]
restore successfully.
time used: 339.153(ms)
RMAN>
--恢复数据库:
RMAN> recover database '/dm8/data/DAMENG/dm.ini' from backupset '/dm8/backup/db_bak';
recover database '/dm8/data/DAMENG/dm.ini' from backupset '/dm8/backup/db_bak';
Database mode = 0, oguid = 0
EP[0]'s cur_lsn[44784]
RESTORE RLOG CHECK......
RESTORE RLOG, gen tmp file......
RESTORE RLOG FROM BACKUPSET [/dm8/backup/db_bak] START......
total 2 packages processed...
total 2 packages processed...
total 2 packages processed!
CMD END.CODE:[0]
EP:0 total 1 pkgs applied, percent: 100%
Recover from archive log finished, time used:0.009s.
recover successfully!
time used: 314.604(ms)
RMAN>
--更新db_magic
RMAN> recover database '/dm8/data/DAMENG/dm.ini' update db_magic;
recover database '/dm8/data/DAMENG/dm.ini' update db_magic;
Database mode = 0, oguid = 0
EP[0]'s cur_lsn[44788]
EP[0]'s apply_lsn[44788] >= end_lsn[44788]
recover successfully!
time used: 00:00:01.044
RMAN>
2、逻辑备份:备份的是SQL语句
达梦的逻辑备份命令与 Oracle的exp,imp命令相似,具体命令为:dexp dimp,可以通过dmexp help和dmimp help查看帮助:

 

dmexp help
 dexp和dimp可以按照 数据库,表,模式,用户四种方式来导入导出:
按数据库导出 :
[dmdba@alone bin]$ dexp SYSDBA/SYSDBA file=/dm8/backup/full.dmp full=y
按模式导出 :
[dmdba@alone bin]$ dexp SYSDBA/SYSDBA file=/dm8/backup/schemas.dmp schemas=test
按用户导出 :
[dmdba@alone bin]$ dexp SYSDBA/SYSDBA file=/dm8/backup/owner.dmp owner=test
按数据表导出 :
[dmdba@alone bin]$ dexp SYSDBA/SYSDBA file=/dm8/backup/t1.dmp tables=t1
按数据库导入 :
[dmdba@alone bin]$ dimp SYSDBA/SYSDBA file=/dm8/backup/full.dmp full=y
按模式导入 :
[dmdba@alone bin]$dimp SYSDBA/SYSDBA file=/dm8/backup/schemas.dmp schemas=test
按用户导入 :
[dmdba@alone bin]$dimp SYSDBA/SYSDBA file=/dm8/backup/owner.dmp owner=test
按表导入(表已存在):
[dmdba@alone bin]$ dimp SYSDBA/SYSDBA file=/dm8/backup/t1.dmp tables=t1 ignore=y
按表导入(表不存在):
[dmdba@alone bin]$ dimp SYSDBA/SYSDBA file=/dm8/backup/t1.dmp tables=t1

 


更多资讯请上达梦技术社区了解: 

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/69978967/viewspace-2704074/,如需转载,请注明出处,否则将追究法律责任。

上一篇: 没有了~
请登录后发表评论 登录
全部评论

注册时间:2020-07-13

  • 博文量
    4
  • 访问量
    3080