物理备份则直接扫描数据库文件,找出那些已经分配、使用的数据页,拷贝并保存到备份集中。物理备份过程中,不关心数据页的具体内容是什么,也不关心数据页属于哪一张表,只是简单的根据数据库文件系统的描述,来挑选有效的数据页。
联机备份和脱机备份
数据库处于运行状态、并正常提供数据库服务情况下进行的备份操作,称为联机备份。
数据库处于关闭状态时进行的备份操作,称为脱机备份。
备份还原实现策略有两种:dmap辅助进程方式和无辅助进程方式。用户可通过DM.INI参数bak_use_ap来选择(dmrman使用参数use_ap),bak_use_ap可取值1、2。默认为1。
bak_use_ap的两种取值的相应作用如下:
1:DMAP辅助进程方式,可支持第三方备份(指定DEVICE TYPE为TAPE)。DMAP插件执行,改造了备份还原任务子系统,允许指定并行度,大幅提升了备份还原的效率,特别是加密、压缩的处理效率。如果选择使用DMAP辅助进程,执行备份还原之前就必须启动DMAP服务。安装DM数据库以后,DMAP服务会自动启动。如果需要手动启动,有两种途径,一是启动DM服务查看器中的DmAPService。二是通过手动启动DMAP执行码实现,DMAP执行码位于DM安装目录的bin子目录下。除此之外,LINUX下,还可以调用bin目录下的DmAPService脚本。
2:无辅助进程方式,不依赖DMAP,由主进程dmserver自身执行备份还原,但不支持第三方备份(指定DEVICE TYPE为TAPE)。
脱机备份也称冷备,需要关闭数据库服务,开启dmap服务。
这里使用无辅助进程方式备份还原,不需要dmap服务。
备份
[dmdba@localhost ~]$ dmrman use_ap=2
RMAN> backup database '/opt/dmdbms/data/DAMENG/dm.ini' full backupset '/home/dmdba/db_full_bak';
或者
[dmdba@localhost ~]$ dmrman use_ap=2 CTLSTMT="backup database '/opt/dmdbms/data/DAMENG/dm.ini' full backupset '/home/dmdba/db_full_bak'"
还原和恢复
[dmdba@localhost ~]$ dmrman use_ap=2 CTLSTMT="RESTORE DATABASE '/opt/dmdbms/data/DAMENG/dm.ini' FROM BACKUPSET '/home/dmdba/db_full_bak'"
[dmdba@localhost ~]$ dmrman use_ap=2 CTLSTMT="RECOVER DATABASE '/opt/dmdbms/data/DAMENG/dm.ini' FROM BACKUPSET '/home/dmdba/db_full_bak'"
[dmdba@localhost ~]$ dmrman use_ap=2 CTLSTMT="RECOVER DATABASE '/opt/dmdbms/data/DAMENG/dm.ini' UPDATE DB_MAGIC"
restore时加上reuse dmini参数可以覆盖dm.ini文件
[dmdba@localhost ~]$ dmrman use_ap=2 CTLSTMT="RESTORE DATABASE '/opt/dmdbms/data/DAMENG/dm.ini' REUSE DMINI FROM BACKUPSET '/home/dmdba/db_full_bak'"
restore to命令还原到指定目录(还原到空目录或者加overwrite参数)
SYSTEM.DBF文件损坏只能用restore to命令还原,否则报错“/opt/dmdbms/data/DAMENG/SYSTEM.DBF not exist”
[dmdba@localhost ~]$ mv /opt/dmdbms/data/DAMENG /opt/dmdbms/data/DAMENG1
[dmdba@localhost ~]$ dmrman use_ap=2 CTLSTMT="RESTORE DATABASE to '/opt/dmdbms/data/DAMENG' overwrite FROM BACKUPSET '/home/dmdba/db_full_bak'"
备份
[dmdba@localhost ~]$ dmrman use_ap=2 CTLSTMT="backup database '/opt/dmdbms/data/DAMENG/dm.ini' full backupset '/home/dmdba/db_full_bak'"
[dmdba@localhost ~]$ dmrman use_ap=2 CTLSTMT="backup database '/opt/dmdbms/data/DAMENG/dm.ini' increment with backupdir '/home/dmdba' backupset '/home/dmdba/db_full_bak_inc1'"
还原和恢复
[dmdba@localhost ~]$ dmrman use_ap=2 CTLSTMT="RESTORE DATABASE '/opt/dmdbms/data/DAMENG/dm.ini' FROM BACKUPSET '/home/dmdba/db_full_bak'"
[dmdba@localhost ~]$ dmrman use_ap=2 CTLSTMT="RESTORE DATABASE '/opt/dmdbms/data/DAMENG/dm.ini' FROM BACKUPSET '/home/dmdba/db_full_bak_inc1'"
[dmdba@localhost ~]$ dmrman use_ap=2 CTLSTMT="RECOVER DATABASE '/opt/dmdbms/data/DAMENG/dm.ini' FROM BACKUPSET '/home/dmdba/db_full_bak_inc1'"
[dmdba@localhost ~]$ dmrman use_ap=2 CTLSTMT="RECOVER DATABASE '/opt/dmdbms/data/DAMENG/dm.ini' UPDATE DB_MAGIC"
脱机备份也称热备,需要开启数据库服务和dmap服务,且启动dmap的用户和启动DMSERVER服务的用户必须一致,否则会导致备份失败。由于数据库时处于运行状态的,所以需要开启归档。
联机备份之前,请设置INI参数BAK_USE_AP,选用合适的备份方式。
ALTER DATABASE MOUNT;
ALTER DATABASE ARCHIVELOG;
ALTER DATABASE ADD ARCHIVELOG 'DEST=/opt/dmdbms/data/DAMENG/arch, TYPE=LOCAL, FILE_SIZE=256, SPACE_LIMIT=0';
ALTER DATABASE OPEN;
备份
SQL> insert into test.tb1 values(1);
SQL> commit;
SQL> backup database full backupset '/home/dmdba/db_full_bak';
SQL> insert into test.tb1 values(2);
SQL> commit;
SQL> backup database increment with backupdir '/home/dmdba' backupset '/home/dmdba/db_full_bak_inc1';
SQL> insert into test.tb1 values(3);
SQL> commit;
SQL> backup database increment with backupdir '/home/dmdba' backupset '/home/dmdba/db_full_bak_inc2';
SQL> insert into test.tb1 values(4);
SQL> commit;
还原和恢复
[dmdba@localhost ~]$ dmrman use_ap=2 CTLSTMT="RESTORE DATABASE '/opt/dmdbms/data/DAMENG/dm.ini' FROM BACKUPSET '/home/dmdba/db_full_bak'"
[dmdba@localhost ~]$ dmrman use_ap=2 CTLSTMT="RESTORE DATABASE '/opt/dmdbms/data/DAMENG/dm.ini' FROM BACKUPSET '/home/dmdba/db_full_bak_inc1'"
[dmdba@localhost ~]$ dmrman use_ap=2 CTLSTMT="RESTORE DATABASE '/opt/dmdbms/data/DAMENG/dm.ini' FROM BACKUPSET '/home/dmdba/db_full_bak_inc2'"
[dmdba@localhost ~]$ dmrman use_ap=2 CTLSTMT="RECOVER DATABASE '/opt/dmdbms/data/DAMENG/dm.ini' FROM BACKUPSET '/home/dmdba/db_full_bak_inc2'"
[dmdba@localhost ~]$ dmrman use_ap=2 CTLSTMT="RECOVER DATABASE '/opt/dmdbms/data/DAMENG/dm.ini' with archivedir '/opt/dmdbms/data/DAMENG/arch'"
[dmdba@localhost ~]$ dmrman use_ap=2 CTLSTMT="RECOVER DATABASE '/opt/dmdbms/data/DAMENG/dm.ini' UPDATE DB_MAGIC"
备份
SQL> insert into test.tb1 values(5);
SQL> commit;
SQL> backup tablespace TESTTBS backupset '/home/dmdba/ts_full_bak';
SQL> insert into test.tb1 values(6);
SQL> commit;
SQL> backup tablespace TESTTBS increment with backupdir '/home/dmdba' backupset '/home/dmdba/ts_full_bak_inc1';
SQL> insert into test.tb1 values(7);
SQL> commit;
模拟故障
[root@localhost ~]# systemctl stop DmServiceDM.service
[root@localhost ~]# rm -f /opt/dmdbms/data/DAMENG/TESTTBS01.DBF
还原和恢复
[dmdba@localhost ~]$ dmrman use_ap=2 CTLSTMT="RESTORE DATABASE '/opt/dmdbms/data/DAMENG/dm.ini' TABLESPACE TESTTBS FROM BACKUPSET '/home/dmdba/ts_full_bak'"
[dmdba@localhost ~]$ dmrman use_ap=2 CTLSTMT="RESTORE DATABASE '/opt/dmdbms/data/DAMENG/dm.ini' TABLESPACE TESTTBS FROM BACKUPSET '/home/dmdba/ts_full_bak_inc1'"
[dmdba@localhost ~]$ dmrman use_ap=2 CTLSTMT="RECOVER DATABASE '/opt/dmdbms/data/DAMENG/dm.ini' TABLESPACE TESTTBS"
DM共支持9个级别(1~9 级)的压缩处理,级别越高压缩比越高,但相应的压缩速度越慢、CPU开销越大。
SQL> backup database full backupset '/home/dmdba/db_full_bak' compressed level 1;
实测数据规模25G
压缩1级备份文件大小3.8G,压缩9级备份文件大小3.7G
压缩1级备份时间50s,压缩9级备份时间3m49s
指定并行备份的并行数和拆分块大小。并行数取值范围0~128。若不指定并行数,则默认为4,若指定为0或者1均认为非并行备份。若未指定关键字PARALLEL,则认为非并行备份。并行备份不支持存在介质为TAPE的备份。线程数(TASK THREAD)*并行数(PARALLEL)不得超过512。
SQL> backup database full backupset '/home/dmdba/db_full_bak' parallel 4;
SQL> backup database full backupset '/home/dmdba/db_full_bak' task thread 4 parallel 4;
文章
阅读量
获赞