数据库要进行联机备份需要开启归档:
https://blog.csdn.net/weixin_48588449/article/details/108233597
配置归档方法,参考配置
联机备份–DISQL备份恢复
disql 命令行操作
1.数据库备份:
最简单的数据库备份语句:
SQL> BACKUP DATABASE BACKUPSET 'db_bak_01'; --单引号内也可指定备份路径
FULL参数可省略,默认为完全备份:
SQL> BACKUP DATABASE FULL BACKUPSET '/home/dm_bak/db_full_bak_01';
增量备份:基于全库备份操作的,指定全库备份目录即可
SQL> BACKUP DATABASE INCREMENT WITH BACKUPDIR '/home/dm_bak' BACKUPSET '/home/dm_bak/db_increment_bak_02';
指定备份集路径、设置备份名、指定介质类型、添加备份描述、限制备份片大小、备份压缩、并行备份:
SQL> BACKUP DATABASE TO WEEKLY_FULL_BAK BACKUPSET ‘/home/dm_bak/db_bak_3_02’ DEVICE TYPE TAPE BACKUPINFO ‘完全备份’MAXPIECESIZE 300 COMPRESSED LEVEL 5 PARALLEL 8;
数据库的恢复还原操作只能脱机进行,使用dmrman
./dmrman CTLSTMT="RESTORE DATABASE '/dm/dmdbms/data/DAMENG/dm.ini' FROM BACKUPSET '/home/dm_bak/db_full_bak_01'"
./dmrman CTLSTMT="RECOVER DATABASE '/dm/dmdbms/data/DAMENG/dm.ini' FROM BACKUPSET '/home/dm_bak/db_full_bak_01'"
./dmrman CTLSTMT="RECOVER DATABASE '/dm/dmdbms/data/DAMENG/dm.ini' UPDATE DB_MAGIC"
一次恢复,两次还原(注意:新库只需要还原一次即可,还原DB_MAGIC)
两个指定:指定dm.ini文件,指定备份集路径
2.表空间备份
最简单的表空间备份语句:
SQL> BACKUP TABLESPACE MAIN BACKUPSET 'ts_bak_01';
指定基备份目录(不指定则搜索最近一次完全/增量备份作基备份)
SQL>BACKUP TABLESPACE MAIN INCREMENT BASE ON BACKUPSET'ts_full_bak_01' BACKUPSET 'ts_increment_bak_02';
完全备份(FULL参数可省略,默认为完全备份)
SQL> BACKUP TABLESPACE MAIN FULL BACKUPSET '/home/dm_bak/ts_full_bak_01';
增量备份
SQL> BACKUP TABLESPACE MAIN INCREMENT WITH BACKUPDIR '/home/dm_bak' BACKUPSET '/home/dm_bak/ts_increment_bak_02';
表空间执行恢复即可,
SQL> ALTER TABLESPACE MAIN OFFLINE;
SQL> RESTORE TABLESPACE MAIN FROM BACKUPSET 'ts_bak_01';
SQL> ALTER TABLESPACE MAIN ONLINE;
系统处于OPEN状态下
表空间还原、恢复操作一次性完成,还原后不需单独执行恢复
可使用表空间完全备份、表空间增量备份、数据库备份文件还原表空间
3.表备份
表备份均为联机完全备份,不需要备份归档日志,不存在增量备份之说。
最简单的表备份语句:
SQL> BACKUP TABLE TAB_01 BACKUPSET 'tab_bak_01';
表结构还原
SQL>RESTORE TABLE STRUCT TAB_FRO_RES_02 FROM BACKUPSET '/home/dm_bak/tab_bak_for_res_02';
表数据还原
SQL>RESTORE TABLE TAB_FOR_RES_02 FROM BACKUPSET '/home/dm_bak_for_res_02';
4.归档备份
归档备份拷贝指定归档目录下的所有的归档文件到备份集中。
SQL>BACKUP ARCHIVE LOG ALL BACKUPSET 'arch_bak_01';
备份的起始 LSN 和截至 LSN
SQL>BACKUP ARCHIVELOGLSN BETWEEN 50414 AND 50478 BACKUPSET
'/home/dm_bak/arch_bak_01';
归档的还原修复操作只能脱机进行,使用dmrman
还原
RMAN>RESTORE ARCHIVE LOG FROM BACKUPSET'/home/dm_bak/arch_all_for_restore' TODATABASE '/opt/dmdbms/data/DAMENG/dm.ini' OVERWRITE 2;
或者
RMAN>RESTORE ARCHIVE LOG FROM BACKUPSET'/home/dm_bak/arch_all_for_restore' TOARCHIVEDIR'/opt/dmdbms/data/DAMENG/arch_dest' OVERWRITE 2;
修复
RMAN>REPAIR ARCHIVELOG DATABASE '/opt/dmdbms/data/DAMENG/dm.ini';
脱机备份–DMRMAN备份数据库
1.数据库备份
完全备份
RMAN>BACKUP DATABASE '/opt/dmdbms/data/DAMENG/dm.ini' FULL BACKUPSET '/home/dm_bak/db_full_bak_01';
增量备份
RMAN>BACKUP DATABASE '/opt/dmdbms/data/DAMENG/dm.ini' INCREMENT WITH BACKUPDIR '/home/dm_bak 'BACKUPSET'/home/dm_bak/db_increment_bak_02';
数据库还原恢复
RMAN>RESTORE DATABASE '/opt/dmdbms/data/DAMENG/dm.ini' FROM BACKUPSET '/home/dm_bak/db_full_bak_01'
RMAN>RECOVER DATABASE '/opt/dmdbms/data/DAMENG/dm.ini' FROM BACKUPSET '/home/dm_bak/db_full_bak_01'
RMAN>RECOVER DATABASE '/opt/dmdbms/data/DAMENG/dm.ini' UPDATE DB_MAGIC
一次恢复,两次还原(注意:新库只需要还原一次即可,还原DB_MAGIC)
两个指定:指定dm.ini文件,指定备份集路径
2.归档备份
普通归档备份
RMAN>BACKUP ARCHIVE LOG ALL DATABASE '/opt/dmdbms/data/DAMENG/dm.ini' BACKUPSET '/home/dm_bak/arch_all_bak_01';
通过设置 LSN 或者时间点,控制需要备份归档的范围
RMAN>BACKUP ARCHIVE LOG LSN BETWEEN 50000 AND 20000 DATABASE '/opt/dmdbms/data/DAMENG/dm.ini' BACKUPSET '/home/dm_bak/db_increment_bak_02';
还原修复
还原
RMAN>RESTORE ARCHIVE LOG FROM BACKUPSET'/home/dm_bak/arch_all_bak_01' TODATABASE '/opt/dmdbms/data/DAMENG/dm.ini' OVERWRITE 2;
或者
RMAN>RESTORE ARCHIVE LOG FROM BACKUPSET'/home/dm_bak/arch_all_bak_01' TOARCHIVEDIR'/opt/dmdbms/data/DAMENG/arch_dest' OVERWRITE 2;
修复
RMAN>REPAIR ARCHIVELOG DATABASE '/opt/dmdbms/data/DAMENG/dm.ini';
管理工具备份恢复
1.库备份
点击新建备份
可以全量备份,也可基于全量做增量备份
也可选择压缩,加密;完成后点击确定。
2.表备份
选择新建备份,选择模式名,表名;
也可选择压缩,加密;完成后点击确定。
3.表空间备份
选择新建备份,选择备份的表空间,可全备,也可基于全备做增备,选择路径;
也可选择压缩,加密;完成后点击确定。
4.归档备份
选择新建备份,可备份所有归档,也可指定LSN/指定时间备份归档;
也可选择压缩,加密;完成后点击确定。
备份示例