首页  :: 新随笔  :: 管理

DM8数据库备份恢复之repair archivelog

Posted on 2023-02-15 10:09  高&玉  阅读(256)  评论(0编辑  收藏  举报

前言

DM官方建议:当DM数据库异常宕机后,需要在DMRMAN交互模式下执行repair archivelog修复动作确保buffer中的联机日志刷新到本地的REDO日志中,否则后面使用备份恢复的时可能因为归档日志不完整导致恢复失败或者修复后缺少部分数据。

在当前环境如果归档日志未修复,进行恢复的时候可能会报如下错误:

[-730]:归档日志不完整

下面分两个场景测试repair archive log的重要性。

 

场景1:

  1. 数据库全备
  2. 执行事务正常提交
  3. kill -9 $(pidof dmserver)
  4. 利用归档日志恢复数据库
  5. 启动dmserver服务
  6. 查看t1、t2表中数据

 

场景2:

  1. 数据库全备
  2. 执行事务正常提交
  3. kill -9 $(pidof dmserver)
  4. 修复归档日志
  5. 利用归档日志恢复数据库
  6. 启动dmserver服务
  7. 查看t1、t2表中数据

场景1

1. 数据库全备

SQL> backup database full backupset '/backup/dm_full_backup_20230214' backupinfo 'dameng_all_backup' maxpiecesize 300 compressed level 5 parallel 4;
操作已执行
已用时间: 00:00:06.467. 执行号:700.

2. 执行事务

QL> conn gaoyu/
密码:

SQL> select * from t1;

行号     ID          NAME    
---------- ----------- --------
1          1           zhangsan
2          2           niuli
3          3           name3
4          4           name4
5          5           name5

已用时间: 0.647(毫秒). 执行号:603.
SQL> select * from t2;

行号     ID          NAME   
---------- ----------- -------
1          1           lisi
2          2           xiaomei
3          3           name3
4          4           name4
5          5           老五

已用时间: 0.682(毫秒). 执行号:604.
SQL> delete from t1 where id > 3;
影响行数 2

已用时间: 3.684(毫秒). 执行号:605.
SQL> delete from t2 where id > 4;
影响行数 1

已用时间: 1.571(毫秒). 执行号:606.
SQL> select * from t1;

行号     ID          NAME    
---------- ----------- --------
1          1           zhangsan
2          2           niuli
3          3           name3

已用时间: 0.525(毫秒). 执行号:607.
SQL> select * from t2;

行号     ID          NAME   
---------- ----------- -------
1          1           lisi
2          2           xiaomei
3          3           name3
4          4           name4

已用时间: 1.440(毫秒). 执行号:608.
SQL> commit;
操作已执行
已用时间: 1.128(毫秒). 执行号:609.

3. 强制杀掉dmserver进程

[dmdba]# kill -9 $(pidof dmserver)

4. 检查备份集

RMAN> check backupset '/backup/dm_full_backup_20230214';
check backupset '/backup/dm_full_backup_20230214';
[Percent:100.00%][Speed:0.00M/s][Cost:00:00:00][Remaining:00:00:00]                                 
check backupset successfully.
time used: 158.465(ms)

5. 数据库还原

RMAN> restore database '/data/dmdbms/data/DAMENG/dm.ini' from backupset '/backup/dm_full_backup_20230214';
restore database '/data/dmdbms/data/DAMENG/dm.ini' from backupset '/backup/dm_full_backup_20230214';
file dm.key not found, use default license!
Normal of FAST
Normal of DEFAULT
Normal of RECYCLE
Normal of KEEP
Normal of ROLL
[Percent:100.00%][Speed:0.00M/s][Cost:00:00:02][Remaining:00:00:00]                                 
restore successfully.
time used: 00:00:02.719

6. 数据库恢复

RMAN> recover database '/data/dmdbms/data/DAMENG/dm.ini' with archivedir '/data/dmdbms/archlog';
recover database '/data/dmdbms/data/DAMENG/dm.ini' with archivedir '/data/dmdbms/archlog';
Database mode = 2, oguid = 0
Normal of FAST
Normal of DEFAULT
Normal of RECYCLE
Normal of KEEP
Normal of ROLL
EP[0]'s cur_lsn[207589], file_lsn[207589]
[Percent:100.00%][Speed:0.00PKG/s][Cost:00:00:00][Remaining:00:00:00]                               
recover successfully!
time used: 650.187(ms)

7. 更新数据库DB_MAGIC

RMAN> recover database '/data/dmdbms/data/DAMENG/dm.ini' update DB_MAGIC;
recover database '/data/dmdbms/data/DAMENG/dm.ini' update DB_MAGIC;
Database mode = 2, oguid = 0
Normal of FAST
Normal of DEFAULT
Normal of RECYCLE
Normal of KEEP
Normal of ROLL
EP[0]'s cur_lsn[207669], file_lsn[207669]
recover successfully!
time used: 00:00:01.141

8. 启动dmserver服务

[root]# systemctl start DmServiceDMSERVER.service

9. 验证数据

由于内存中的redo日志未刷新落盘到归档日志中,导致delete删除的数据还存在。

SQL> conn gaoyu
密码:

服务器[LOCALHOST:5236]:处于普通打开状态
登录使用时间 : 4.351(ms)
SQL> select * from t1;

行号     ID          NAME    
---------- ----------- --------
1          1           zhangsan
2          2           niuli
3          3           name3
4          4           name4
5          5           name5

已用时间: 3.316(毫秒). 执行号:600.
SQL> select * from t2;

行号     ID          NAME   
---------- ----------- -------
1          1           lisi
2          2           xiaomei
3          3           name3
4          4           name4
5          5           老五

已用时间: 5.924(毫秒). 执行号:601.

场景2

1. 数据库全备

SQL> backup database full backupset '/backup/dm_full_backup_20230214' backupinfo 'dameng_all_backup' maxpiecesize 300 compressed level 5 parallel 4;
操作已执行
已用时间: 00:00:06.467. 执行号:700.

2. 执行事务

SQL> conn gaoyu/
密码:

SQL> select * from t1;

行号     ID          NAME    
---------- ----------- --------
1          1           zhangsan
2          2           niuli
3          3           name3
4          4           name4
5          5           name5

已用时间: 0.647(毫秒). 执行号:603.
SQL> select * from t2;

行号     ID          NAME   
---------- ----------- -------
1          1           lisi
2          2           xiaomei
3          3           name3
4          4           name4
5          5           老五

已用时间: 0.682(毫秒). 执行号:604.
SQL> delete from t1 where id > 3;
影响行数 2

已用时间: 3.684(毫秒). 执行号:605.
SQL> delete from t2 where id > 4;
影响行数 1

已用时间: 1.571(毫秒). 执行号:606.
SQL> select * from t1;

行号     ID          NAME    
---------- ----------- --------
1          1           zhangsan
2          2           niuli
3          3           name3

已用时间: 0.525(毫秒). 执行号:607.
SQL> select * from t2;

行号     ID          NAME   
---------- ----------- -------
1          1           lisi
2          2           xiaomei
3          3           name3
4          4           name4

已用时间: 1.440(毫秒). 执行号:608.
SQL> commit;
操作已执行
已用时间: 1.128(毫秒). 执行号:609.

3. 强制杀掉dmserver进程

[dmdba]# kill -9 $(pidof dmserver)

4. 修复归档日志

RMAN> repair archivelog database '/data/dmdbms/data/DAMENG/dm.ini';
repair archivelog database '/data/dmdbms/data/DAMENG/dm.ini';
file dm.key not found, use default license!
Database mode = 0, oguid = 0
Normal of FAST
Normal of DEFAULT
Normal of RECYCLE
Normal of KEEP
Normal of ROLL
begin redo pwr log collect, last ckpt lsn: 207999 ...
redo pwr log collect finished
EP[0]'s cur_lsn[208851], file_lsn[208851]
repair archive log successfully.
repair time used: 341.204(ms)
time used: 342.765(ms)

5. 检查备份集

RMAN> check backupset '/backup/dm_full_backup_20230214';
check backupset '/backup/dm_full_backup_20230214';
[Percent:100.00%][Speed:0.00M/s][Cost:00:00:00][Remaining:00:00:00]                                 
check backupset successfully.
time used: 158.465(ms)

6. 数据库还原

RMAN> restore database '/data/dmdbms/data/DAMENG/dm.ini' from backupset '/backup/dm_full_backup_20230214';
restore database '/data/dmdbms/data/DAMENG/dm.ini' from backupset '/backup/dm_full_backup_20230214';
Normal of FAST
Normal of DEFAULT
Normal of RECYCLE
Normal of KEEP
Normal of ROLL
[Percent:100.00%][Speed:0.00M/s][Cost:00:00:02][Remaining:00:00:00]                                 
restore successfully.
time used: 00:00:02.713

7. 数据库恢复

RMAN> recover database '/data/dmdbms/data/DAMENG/dm.ini' with archivedir '/data/dmdbms/archlog';
recover database '/data/dmdbms/data/DAMENG/dm.ini' with archivedir '/data/dmdbms/archlog';
Database mode = 2, oguid = 0
Normal of FAST
Normal of DEFAULT
Normal of RECYCLE
Normal of KEEP
Normal of ROLL
EP[0]'s cur_lsn[207962], file_lsn[207962]
[Percent:100.00%][Speed:0.00PKG/s][Cost:00:00:00][Remaining:00:00:00]                               
recover successfully!
time used: 565.221(ms)

8. 更新数据库DB_MAGIC

RMAN> recover database '/data/dmdbms/data/DAMENG/dm.ini' update DB_MAGIC;
recover database '/data/dmdbms/data/DAMENG/dm.ini' update DB_MAGIC;
Database mode = 2, oguid = 0
Normal of FAST
Normal of DEFAULT
Normal of RECYCLE
Normal of KEEP
Normal of ROLL
EP[0]'s cur_lsn[208851], file_lsn[208851]
recover successfully!
time used: 00:00:01.128

9. 启动dmserver

[root]# systemctl start DmServiceDMSERVER.service

10. 验证数据

可以看到归档日志修复后数据库可以恢复到最新状态。

SQL> conn gaoyu
密码:

服务器[LOCALHOST:5236]:处于普通打开状态
登录使用时间 : 4.251(ms)
SQL> select * from t1;

行号     ID          NAME    
---------- ----------- --------
1          1           zhangsan
2          2           niuli
3          3           name3

已用时间: 4.209(毫秒). 执行号:600.
SQL> select * from t2;

行号     ID          NAME   
---------- ----------- -------
1          1           lisi
2          2           xiaomei
3          3           name3
4          4           name4

已用时间: 2.234(毫秒). 执行号:601.

 

参考:https://eco.dameng.com/document/dm/zh-cn/ops/physical-backup-restore.html