首页  :: 新随笔  :: 管理

DM8数据库备份与恢复

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

1. 数据库全备与恢复

联机方式支持数据库、用户表空间、用户表和归档的备份以及用户表的还原。在进行联机库级备份、归档备份和表空间备份时,必须保证系统处于归档模式,否则联机备份不能进行。

 

1. 查看数据库是否为归档模式

SQL> select arch_mode from v$database;

ARCH_MODE
---------
Y

 

2. 数据库全备

SQL> backup database full backupset '/backup/db_backup_base_20230213';

 

3. 归档日志备份

如果数据库体积较大,距离上次全库备份时间不长且数据量变化不大的话,可以通过备份归档日志进行前滚恢复。

SQL> BACKUP ARCHIVE LOG ALL BACKUPSET '/backup/arch_log_backup_20230213'; 

 

 4. 关闭DM数据库服务

[root]# systemctl stop DmServiceDMSERVER.service

 

5. 数据库还原

RMAN> restore database '/data/dmdbms/data/DAMENG/dm.ini' from backupset '/backup/db_backup_base_20230213';

 

6. 归档日志还原,指定归档日志还原的目标路径,OVERWRITE 为 2,如果归档文件已存在,会报错: 

RMAN> RESTORE ARCHIVE LOG FROM BACKUPSET '/backup/arch_log_backup_20230213' TO  archivedir '/backup/archlog' OVERWRITE 2;

 

7. 数据库恢复(使用备份的归档日志进行日志前滚)

RMAN> recover database '/data/dmdbms/data/DAMENG/dm.ini' with archivedir '/backup/archlog';

 

8. 更新数据库DB_MAGIC

RMAN> recover database '/data/dmdbms/data/DAMENG/dm.ini' UPDATE DB_MAGIC;

 

9. 启动DM数据库服务

[root]# systemctl start DmServiceDMSERVER.service

 

2. 差异增量备份和恢复

1. 查看数据库是否处于归档模式

SQL> select arch_mode from v$database;

ARCH_MODE
---------
Y

2. 数据库全备

SQL> backup database backupset '/backup/db_backup_base';

3. 数据库第一次(差异)增量备份

SQL> backup database increment backupset '/backup/db_backup_increment_01';

4. 数据库第二次(差异)增量备份

SQL> backup database increment backupset '/backup/db_backup_increment_02';

5. 归档日志备份

SQL> backup archive log all backupset '/backup/arch_log_backup_20230213';

6. 关闭DM数据库服务

[root]# systemctl stop DmServiceDMSERVER.service

7. 归档日志还原,指定归档日志还原的目标路径,OVERWRITE 为 2,如果归档文件已存在,会报错:

RMAN> RESTORE ARCHIVE LOG FROM BACKUPSET '/backup/arch_log_backup_20230213' TO  archivedir '/backup/archlog' OVERWRITE 2;

8. 数据库基础备份集还原

RMAN> restore database '/data/dmdbms/data/DAMENG/dm.ini' from backupset '/backup/db_backup_base';

9. 数据库第一次增量备份集还原

RMAN> restore database '/data/dmdbms/data/DAMENG/dm.ini' from backupset '/backup/db_backup_increment_01';

10. 数据库第二次增量备份集还原

RMAN> restore database '/data/dmdbms/data/DAMENG/dm.ini' from backupset '/backup/db_backup_increment_02';

11. 数据库第二次增量备份集恢复

RMAN> recover database '/data/dmdbms/data/DAMENG/dm.ini' from backupset '/backup/db_backup_increment_02' with archivedir '/backup/archlog';

12. 更新数据库DB_MAGIC

RMAN> recover database '/data/dmdbms/data/DAMENG/dm.ini' update db_magic;

13. 启动DM数据库服务

[root]# systemctl start DmServiceDMSERVER.service

 

3. 累计增量备份和恢复

1. 查看数据库是否处于归档模式

SQL> select arch_mode from v$database;

ARCH_MODE
---------
Y

2. 数据库全备

SQL> backup database backupset '/backup/db_backup_base';

3. 第一次全库(累计)增量备份

SQL> backup database increment with backupdir '/backup/db_backup_base' backupset '/backup/db_backup_increment_01';

4. 第二次全库(累计)增量备份

SQL> backup database increment with backupdir '/backup/db_backup_base' backupset '/backup/db_backup_increment_02';

5. 归档日志备份

SQL> backup archive log all backupset '/backup/arch_log_backup_20230213';

6. 关闭DM数据库服务

[root]# systemctl stop DmServiceDMSERVER.service

7. 归档日志还原,指定归档日志还原的目标路径,OVERWRITE 为 2,如果归档文件已存在,会报错:

RMAN> RESTORE ARCHIVE LOG FROM BACKUPSET '/backup/arch_log_backup_20230213' TO  archivedir '/backup/archlog' OVERWRITE 2;

 8. 从数据库基础备份集还原

RMAN> restore database '/data/dmdbms/data/DAMENG/dm.ini' from backupset '/backup/db_backup_base';

9. 从数据库最后一次(累计)增量备份集还原

RMAN> restore database '/data/dmdbms/data/DAMENG/dm.ini' from backupset '/backup/db_backup_increment_02';

10. 从数据库最后一次(累计)增量备份恢复

RMAN> recover database '/data/dmdbms/data/DAMENG/dm.ini' with archivedir '/backup/archlog';

11. 更新数据库DB_MAGIC

RMAN> recover database '/data/dmdbms/data/DAMENG/dm.ini' update db_magic;

12. 启动DM数据库服务

[root]# systemctl start DmServiceDMSERVER.service

 

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