达梦数据库物理备份分为脱机备份和联机备份,目前对dmrman和sql工具下两种备份和恢复测试

一: 脱机备份和恢复(使用 dmrman 工具)

1.查看默认备份目录:

select * from v$parameter t where name in ('BAK_PATH', 'BAK_USE_AP');

BAK_PATH:DM 默认的备份路径,生成环境不要和源库数据文件放在同一磁盘上。避免磁 盘损坏,数据文件和备份文件同时损坏的情况。

2.查看dm服务是否关闭

ps -ef|grep dm 

3.进行dmrman备份

3.1 备份到默认目录

[dmdba@dmtest bin]$ ./dmrman

dmrman V8

RMAN> backup database '/dm8/data/DMTEST/dm.ini';

backup database '/dm8/data/DMTEST/dm.ini';

Database mode = 0, oguid = 0

begin redo pwr log collect, last ckpt lsn: 53584 ...

redo pwr log collect finished

EP[0]'s cur_lsn[53584]

Processing backupset /dm8/data/DMTEST/bak/DB_DMTEST_FULL_20230103_230752_958702

[Percent:100.00%][Speed:0.00M/s][Cost:00:00:00][Remaining:00:00:00]

backup successfully!

time used: 00:00:01.110

RMAN>

3.2 备份到非默认目录

[dmdba@dmtest dm8]$ mkdir backup

[dmdba@dmtest dm8]$ cd bin

[dmdba@dmtest bin]$ ./dmrman

dmrman V8

RMAN> backup database '/dm8/data/DMTEST/dm.ini' to full01 backupset '/dm8/backup/full01';

backup database '/dm8/data/DMTEST/dm.ini' to full01 backupset '/dm8/backup/full01';

Database mode = 0, oguid = 0

begin redo pwr log collect, last ckpt lsn: 53584 ...

redo pwr log collect finished

EP[0]'s cur_lsn[53584]

Processing backupset /dm8/backup/full01

[Percent:100.00%][Speed:0.00M/s][Cost:00:00:00][Remaining:00:00:00]

backup successfully!

time used: 00:00:01.108

RMAN>

恢复测试:

模拟故障恢复

删除system表空间文件后,启动dm服务,报如下错误,然后进行恢复

[dmdba@dmtest bin]$ ./DmServiceDMTESTSVR status

DmServiceDMTESTSVR dead but pid file exists

[dmdba@dmtest bin]$ ./DmServiceDMTESTSVR start

Starting DmServiceDMTESTSVR:                               [ FAILED ]

version info: security

/dm8/data/DMTEST/SYSTEM.DBF not exist

[dmdba@dmtest bin]$

使用默认备份目录备份集进行恢复

RMAN> restore database '/dm8/data/DMTEST/dm.ini' from backupset '/dm8/data/DMTEST/bak/DB_DMTEST_FULL_20230103_230752_958702';

restore database '/dm8/data/DMTEST/dm.ini' from backupset '/dm8/data/DMTEST/bak/DB_DMTEST_FULL_20230103_230752_958702';

[Percent:100.00%][Speed:0.00M/s][Cost:00:00:00][Remaining:00:00:00]

restore successfully.

time used: 826.643(ms)

RMAN>

RMAN> recover database '/dm8/data/DMTEST/dm.ini' update db_magic;

recover database '/dm8/data/DMTEST/dm.ini' update db_magic;

Database mode = 0, oguid = 0

EP[0]'s cur_lsn[53584]

recover successfully!

time used: 983.303(ms)

RMAN>

RMAN> recover database '/dm8/data/DMTEST/dm.ini' with archivedir '/dm8/arch';

recover database '/dm8/data/DMTEST/dm.ini' with archivedir '/dm8/arch';

Database mode = 0, oguid = 0

EP[0]'s cur_lsn[53584]

EP:0 total 1 pkgs applied, percent: 100%

recover successfully!

time used: 228.669(ms)

RMAN> recover database '/dm8/data/DMTEST/dm.ini' update db_magic;

recover database '/dm8/data/DMTEST/dm.ini' update db_magic;

Database mode = 0, oguid = 0

EP[0]'s cur_lsn[53584]

recover successfully!

time used: 983.303(ms)

RMAN>

非默认目录下恢复

非默认目录恢复

[dmdba@dmtest bin]$ ./dmrman

dmrman V8

RMAN> restore database '/dm8/data/DMTEST/dm.ini' from backupset '/dm8/backup/full01'

restore database '/dm8/data/DMTEST/dm.ini' from backupset '/dm8/backup/full01'

[Percent:100.00%][Speed:0.00M/s][Cost:00:00:00][Remaining:00:00:00]

restore successfully.

time used: 504.060(ms)

RMAN> recover database '/dm8/data/DMTEST/dm.ini' with archivedir '/dm8/arch';

recover database '/dm8/data/DMTEST/dm.ini' with archivedir '/dm8/arch';

Database mode = 0, oguid = 0

EP[0]'s cur_lsn[53584]

EP:0 total 1 pkgs applied, percent: 100%

recover successfully!

time used: 228.530(ms)

RMAN> recover database '/dm8/data/DMTEST/dm.ini' update db_magic;

recover database '/dm8/data/DMTEST/dm.ini' update db_magic;

Database mode = 0, oguid = 0

EP[0]'s cur_lsn[53584]

recover successfully!

time used: 983.588(ms)

RMAN>

二:联机备份和恢复(使用disql工具)

联机备份:数据库是启动状态,联机备份要求数据库打开归档。

1.备份时 AP 服务需要为启动状态。

[dmdba@KylinDCA04 bak]$ ps -ef|grep dmap

dmdba 86474 1 0 4 月 14 ? 00:00:01 /dm8/bin/dmap

2.备份操作

SQL> backup database full to ONLINEBAK_01 backupset '/dm8/backup/ONLINEBAK_01';

backup database full to ONLINEBAK_01 backupset '/dm8/backup/ONLINEBAK_01';

[-715]:Archive log not exist.

used time: 00:00:01.918. Execute id is 0.

SQL> checkpoint(100);

DMSQL executed successfully

used time: 7.067(ms). Execute id is 410.

SQL> backup database full to ONLINEBAK_01 backupset '/dm8/backup/ONLINEBAK_01';

executed successfully

used time: 932.736(ms). Execute id is 411.

SQL>

3.删除系统文件,模拟故障恢复  ---要求执行脚本时,查看脚本模拟的故障内容事项。 删除system.dbf,main.dbf

[dmdba@dmtest bin]$ ./dmrman

dmrman V8

RMAN> RESTORE DATABASE '/dm8/data/DMTEST/dm.ini' from BACKUPSET '/dm8/backup/ONLINEBAK_01';

RESTORE DATABASE '/dm8/data/DMTEST/dm.ini' from BACKUPSET '/dm8/backup/ONLINEBAK_01';

[Percent:100.00%][Speed:0.00M/s][Cost:00:00:00][Remaining:00:00:00]

restore successfully.

time used: 504.157(ms)

RMAN> RECOVER DATABASE '/dm8/data/DMTEST/dm.ini' with archivedir '/dm8/arch';

RECOVER DATABASE '/dm8/data/DMTEST/dm.ini' with archivedir '/dm8/arch';

Database mode = 0, oguid = 0

EP[0]'s cur_lsn[54991]

EP:0 total 1 pkgs applied, percent: 16%

EP:0 total 2 pkgs applied, percent: 33%

EP:0 total 3 pkgs applied, percent: 50%

EP:0 total 4 pkgs applied, percent: 66%

EP:0 total 5 pkgs applied, percent: 83%

EP:0 total 6 pkgs applied, percent: 100%

recover successfully!

time used: 233.892(ms)

RMAN> RECOVER DATABASE '/dm8/data/DMTEST/dm.ini' update db_magic;

RECOVER DATABASE '/dm8/data/DMTEST/dm.ini' update db_magic;

Database mode = 0, oguid = 0

EP[0]'s cur_lsn[55229]

recover successfully!

time used: 982.645(ms)

RMAN>

4.启动dm服务

su - dmdba

cd /dm8/bin

[dmdba@dmtest ~]$ cd /dm8/bin

[dmdba@dmtest bin]$ ls -al Dm*

-rwxr-xr-x 1 dmdba dmdba    13827 Jan  2 21:19 DmAPService

-rwxr-xr-x 1 dmdba dmdba    14479 Jan  2 21:19 DmAuditMonitorService

-rwxr-xr-x 1 dmdba dmdba    13655 Jan  2 21:19 DmInstanceMonitorService

-rwxr-xr-x 1 dmdba dmdba    14126 Jan  2 21:19 DmJobMonitorService

-rwx------ 1 dmdba dinstall 16122 Jan  2 22:10 DmServiceDMTESTSVR

[dmdba@dmtest bin]$

5.登录disql验证

[dmdba@dmtest bin]$ pwd
/dm8/bin
[dmdba@dmtest bin]$ ./disql sysdba/Dameng123:5238

Server[LOCALHOST:5238]:mode is normal, state is open
login used time : 3.557(ms)
last login ip : ::1
last login time : 2023-01-04 12:34:24
login failed times : 0
Whether password is expired : Not expired
disql V8
SQL> select * from t_test;

LINEID A


1 1
2 2

以上是达梦数据库2中物理备份和恢复的方式,还有其它工具方式,待测试