目录标题
- 1. 主库备份
- 2. Docker启动备库
- 3. 备库修改属组
- 4. 开始恢复
- 5. 连接数据库配置归档 & Open
- 6. 检查数据
关于达梦数据库(DMDBMS)的主库备份、Docker启动备库、恢复备份以及配置归档和打开数据库的详细步骤。
1. 主库备份
# 使用达梦数据库备份命令备份数据库
backup database full backupset '/opt/dmdbms/dmdata/db_full_bak_0115_backup';# 使用scp命令将备份文件传输到备库服务器
scp -r /opt/dmdbms/dmdata/db_full_bak_0115_backup* 10.10.x.x:/opt/qfusion/dameng/data
数据备份
2. Docker启动备库
# 停止并删除旧的Docker容器
docker rm -f dameng-single# 创建数据目录
mkdir -p /opt/qfusion/dameng/data# 启动新的Docker容器
docker run -it --name=dameng-single --restart=always --entrypoint=/bin/bash --user=root --privileged=true \--network=mynet --ip 172.18.12.102 \-p 5236:5236 \-v /opt/qfusion/dameng/data:/opt/dmdbms/dmdata/ \k8smaster.qfusion.irds/irds/dameng-8.0:v1.0.7-2024
3. 备库修改属组
# 进入Docker容器
docker exec -it -u root dameng-single bash# 修改备份目录和数据目录的属组
chown -R dmdba:dinstall /opt/dmdbms/dmdata
chown -R dmdba:dinstall /opt/dmdbms/dmdata/backup
4. 开始恢复
# 进入Docker容器
docker exec -it -u dmdba dameng-single bash# 设置环境变量并初始化数据库
export LD_LIBRARY_PATH=/opt/dmdbms/bin:$LD_LIBRARY_PATH
/opt/dmdbms/bin/dminit path=/opt/dmdbms/dmdata db_name=DAMENG_FOR_RESTORE# 启动达梦数据库服务
/opt/dmdbms/bin/DmAPService start# 使用dmrman工具恢复数据库
/opt/dmdbms/bin/dmrman
RMAN> RESTORE DATABASE '/opt/dmdbms/dmdata/DAMENG_FOR_RESTORE/dm.ini' FROM BACKUPSET '/opt/dmdbms/dmdata/backup';
RMAN> RECOVER DATABASE '/opt/dmdbms/dmdata/DAMENG_FOR_RESTORE/dm.ini' FROM BACKUPSET '/opt/dmdbms/dmdata/backup';
RMAN> SHOW BACKUPSET '/opt/dmdbms/dmdata/backup' INFO DB;
RMAN> RECOVER DATABASE '/opt/dmdbms/dmdata/DAMENG_FOR_RESTORE/dm.ini' update db_magic;
5. 连接数据库配置归档 & Open
# 启动达梦数据库服务
/opt/dmdbms/bin/dmserver /opt/dmdbms/data/DAMENG/dm.ini &# 创建归档目录
mkdir /opt/dmdbms/dmdata/DAMENG_FOR_RESTORE/arch# 使用disql工具连接数据库并进行配置
/opt/dmdbms/bin/disql SYSDBA/'"tneQpf@cbodgB5l0"'ALTER DATABASE MOUNT;
ALTER DATABASE NORMAL;
ALTER DATABASE ARCHIVELOG;
ALTER DATABASE ADD ARCHIVELOG 'DEST = /opt/dmdbms/dmdata/DAMENG_FOR_RESTORE/arch, TYPE = local, FILE_SIZE = 1024, SPACE_LIMIT = 2048';
ALTER DATABASE OPEN;
6. 检查数据
-- 检查表空间使用情况
selectt.name as tablespace_name,sum(d.free_size * d.page_size / 1024 / 1024) as "free_space(M)",sum(d.total_size * d.page_size / 1024 / 1024) as "total_space(M)",sum(d.free_size * 100) / sum(d.total_size) as "free_percent(%)"
from v$tablespace t, v$datafile d
where t.id = d.group_id
group by t.name;-- 连接到数据库并查询表数据
conn bpx/bpx
select * from test_table;
这些步骤涵盖了从备份到恢复的整个过程,并确保了数据库的正确配置和数据的完整性。请根据您的实际环境和需求进行调整。