达梦备份策略及备份还原演练
1 备份归档策略
根据应用需求,定制备份策略如下所示
备份类型 |
备份周期 |
备份时间 |
全量备份 |
每周 |
每周六 23 点 |
增量备份 |
每天 |
除周六外每天 23 点 |
删除备份 |
每天 |
每天 23 点 30分删除14天前数据 |
归档备份(建议无需备份,定期从归档目录拷贝) |
每天 |
每隔12小时备份一次 |
归档策略 |
设置归档日志限制大小500G |
超过限制大小,覆盖最开始文件 |
登录数据库执行以下命令,创建作业系统表
SP_INIT_JOB_SYS(1);
--全量备份 (每周六 23 点全备)
call SP_CREATE_JOB ('bakfull',1,0,'',0,0,'',0,'');
call SP_JOB_CONFIG_START ('bakfull');
call SP_ADD_JOB_STEP ('bakfull', 'bak01', 6, '00000000/dmdata/dmbak', 0,
0, 0, 0, NULL, 0);
call SP_ADD_JOB_SCHEDULE ('bakfull', 'std1', 1, 2, 1, 64, 0, '23:00:00',
NULL, '2021-10-22 14:24:06', NULL, '');
call SP_ADD_JOB_SCHEDULE ('bakfull', 'once1', 1, 0, 0, 0, 0, NULL, NULL,
sysdate+1/1440, NULL, '');
call SP_JOB_CONFIG_COMMIT ('bakfull');
--增量备份 (每周除周六外每天 23 点增量备份) :
call SP_CREATE_JOB ('bakincr',1,0,'',0,0,'',0,'');
call SP_JOB_CONFIG_START ('bakincr');
call SP_ADD_JOB_STEP ('bakincr', 'bak2', 6,
'10000000/dmdata/dmbak |/dmdata/dmbak', 0, 0, 0, 0, NULL, 0);
call SP_ADD_JOB_SCHEDULE ('bakincr', 'std2', 1, 2, 1, 63, 0, '23:00:00',
NULL, '2021-10-22 14:24:06', NULL, '');
call SP_JOB_CONFIG_COMMIT ('bakincr');
--备份定期删除 (每天 23: 30 删除 14 天前备份) :
call SP_CREATE_JOB ('delbak',1,0,'',0,0,'',0,'');
call SP_JOB_CONFIG_START ('delbak');
call SP_ADD_JOB_STEP ('delbak','bak1',0,
'SF_BAKSET_BACKUP_DIR_ADD (''DISK'',''/dmdata/dmbak'');call
sp_db_bakset_remove_batch (''DISK'',now ()-14);', 1, 2, 0, 0, NULL, 0);
call SP_ADD_JOB_SCHEDULE ('delbak', 'del01', 1, 1, 1, 0, 0, '23:30:00',
NULL, '2020-11-02 14:48:41', NULL, '');
call SP_JOB_CONFIG_COMMIT ('delbak');
--定期归档备份 (每天13点开始归档备份, 每隔12小时备份一次)
call SP_CREATE_JOB ('bakarch',1,0,'',0,0,'',0,'');
call SP_JOB_CONFIG_START ('bakarch');
call SP_ADD_JOB_STEP ('bakarch', 'bakarch1', 6,
'31000000/dmdata/dmarch', 1, 2, 0, 0, NULL, 0);
call SP_ADD_JOB_SCHEDULE ('bakarch', 'bakarch2', 1, 1, 1, 0, 720,
'00:00:00', '23:59:59', '2022-01-06 13:00:07', NULL, '');
call SP_JOB_CONFIG_COMMIT ('bakarch');
2 备份还原演练测试
2.1 创建测试数据
create table t (id int ,name VARCHAR (100));
begin
for i in 1..10000 loop
insert into t values (i,'test' | |i);
end loop;
commit;
end;
2.2 将备份文件传到目标库
scp -r /dmdata/dmbak/ dmdba@192.168.20.63:/dmdata
2.3 查看归档(如没开启,需要开启归档)
select arch_type, arch_dest,arch_file_size,arch_space_limit,arch_is_valid from
V$DM_ARCH_INI;
2.4 将归档日志文件拷贝到目标库
scp -r /dm8/data/dmarch/ dmdba@192.168.20.63:/dmdata
2.5 目标库关机 , 进行dmman 脱机还原
mrman use_ap=2
2.5.1 使用全量备份文件还原数据库
RESTORE DATABASE '/dmdata/DAMENG/dm.ini' FROM BACKUPSET
'/dmdata/dmbak/DB_DAMENG_FULL_2022_01_06_14_27_40';
2.5.2 使用增量量份文件还原数据库
RESTORE DATABASE '/dmdata/DAMENG/dm.ini' FROM BACKUPSET
'/dmdata/dmbak/DB_DAMENG_INCREMENT_2022_01_06_14_31_40';
2.5.3 使用归档文件恢复数据库最新状态
2.5.5 重启数据库,由于是从集群备份还原到单机,会提示主库处于配置状态,执行下面语句,验证数据
是否ok
alter database normal;
alter database open;
也可指定恢复到某个节点,比如恢复到昨天某个时间点
(RECOVER DATABASE '/dmdata/DAMENG/dm.ini' WITH ARCHIVEDIR'/dmdata/dmarch'
UNTIL TIME'2022-01-05 14:21:22';)