企业RAC数据库rman备份实施手记

网友投稿 969 2022-05-28

Oracle RAC的备份,其实和单节点备份区别不大,只需要注意RAC的特性,在编写备份脚本时,注意RAC各个节点的Archive log存储方式、RAC数据盘使用的磁盘方式等。

本次备份策略,依然采用比较传统的每周日进行一次全量备份,其它时间进行增量备份策略:

另,备份保留策略设置REDUNDANCY 为 1,即保留一份有效备份即可。

1. 准备备份空间

通过NFS方式,在两个RAC节点,挂载NFS共享磁盘,做为数据备份存储:

# NFS服务搭建过程,请参考其它nfs文档,此处不再赘述;

# 为方便开机自动挂载,将NFS共享盘,添加到开机自动挂载:

# vi /etc/fstab

192.168.10.153:/dbbackup /dbbackup             nfs     defaults        0 0

# mount -a

# df -h

Filesystem           Size Used Avail Use% Mounted on

/dev/mapper/vg_template-lv_root

110G   32G   74G  30% /

tmpfs                 16G 207M   16G   2% /dev/shm

/dev/sda1             477M   76M 376M  17% /boot

192.168.10.153:/dbbackup

500G   33M 500G   1% /dbbackup

2. 准备备份脚本

$ more /dbbackup/scripts/zydb/full_zydb.sh

echo -e '******Start********_'$(date '+%Y%m%d%H%M%S')

source /home/oracle/.bash_profile

rman target / log=/dbbackup/logs/zydb/full_zydb/full_zydb_`date +%Y%m%d-%H%M%S`.log <

run{

allocate channel c1 type disk;

allocate channel c2 type disk;

backup as compressed backupset incremental level 0 tag 'zydb_incr_level_0' format

'/dbbackup/zydb/full_%d_%T_%s' database include current controlfile;

backup as compressed backupset archivelog all format '/dbbackup/zydb/arclog_0_%s_%p_%t_%d' delete input;

crosscheck backup;

delete noprompt expired backup;

delete noprompt obsolete;

crosscheck archivelog all;

delete noprompt expired archivelog all;

release channel c1;

release channel c2;

}

exit;

EOF

$ more /dbbackup/scripts/zydb/incr_zydb.sh

echo -e '******Start********_'$(date '+%Y%m%d%H%M%S')

source /home/oracle/.bash_profile

rman target / log=/dbbackup/logs/zydb/incr_zydb/incr_zydb_`date +%Y%m%d-%H%M%S`.log <

企业RAC数据库rman备份实施手记

run{

allocate channel c1 type disk;

allocate channel c2 type disk;

backup as compressed backupset incremental level 1 tag 'zydb_incr_level_1' format

'/dbbackup/zydb/incr_%d_%T_%s' database include current controlfile;

backup as compressed backupset archivelog all format '/dbbackup/zydb/arclog_1_%s_%p_%t_%d' delete input;

crosscheck backup;

delete noprompt expired backup;

delete noprompt obsolete;

crosscheck archivelog all;

delete noprompt expired archivelog all;

release channel c1;

release channel c2;

}

exit;

EOF

注意:

此备份脚本其实和单节点脚本无差别,是因为当前RAC的归档文件,是存在ASM空间内的;如果离线归档没有存放在共享空间,则以上脚本不可行,需要修改为能同时访问RAC所有节点;

备份加入compressed进行压缩存储,节省备份存储空间(备份效率会有损耗);

备份脚本准备完成后,建议手动执行一次,确认脚本执行状态正常。

3. 开启块跟踪

Block Change Tracking 块变更跟踪功能,是指有数据块发生改变时,就会将其记录在跟踪文件中,记录从上一次0级备份以来数据块的变化。当RMAN进行增量备份时,就不用完全遍历整个数据文件,查找需要备份的数据块,从而提高了备份的效率。

SQL> set linesize 500

SQL> col FILENAME format a50

SQL> select * from v$block_change_tracking;

STATUS     FILENAME                                               BYTES

---------- -------------------------------------------------- ----------

DISABLED

SQL> alter database enable block change tracking using file '+DATA';

-- 查看开启后的状态:

SQL> set linesize 500

SQL> col FILENAME format a50

SQL> select * from v$block_change_tracking;

STATUS     FILENAME                                               BYTES

---------- -------------------------------------------------- ----------

ENABLED   +DATA/zydb/changetracking/ctf.284.1065039345         11599872

4. 配置备份自动执行

目前自动执行有如下方案:

通过操作系统的定时任务,例如Linux的Crontab服务;

通过Oracle自带的DBMS_SCHEDULE来执行;

本次备份的数据库有两个RAC节点,通过Linux的crontab备份,会产生节点间备份任务协调等问题,因此直接采用Oracle的DBMS_SCHEDULE来执行备份任务;

全量备份任务,指定每周日凌晨1点执行;

在BYDAY参数指定周日(BYDAY=SUN),执行时间指定 1 点(BYHOUR=1):

begin

dbms_scheduler.create_job

(

job_name       => 'ZYDB_BAK_LEVEL_0',

job_type       => 'EXECUTABLE',

job_action     => '/dbbackup/scripts/zydb/full_zydb.sh',

repeat_interval => 'FREQ=WEEKLY; BYDAY=SUN; BYHOUR=1',

enabled         => true,

comments       => 'ZYDB Backup JOB LEVEL_0'

);

end;

/

增量备份任务,指定每周从周一到周六,每天凌晨1点执行;

在BYDAY参数指定周一至周六(BYDAY=MON,TUE,WED,THU,FRI,SAT):

begin

dbms_scheduler.create_job

(

job_name       => 'ZYDB_BAK_LEVEL_1',

job_type       => 'EXECUTABLE',

job_action     => '/dbbackup/scripts/zydb/incr_zydb.sh',

repeat_interval => 'FREQ=WEEKLY; BYDAY=MON,TUE,WED,THU,FRI,SAT; BYHOUR=1',

enabled         => true,

comments       => 'ZYDB Backup JOB LEVEL_1'

);

end;

/

SQL> set linesize 500;

SQL> col NEXT_RUN_DATE format a50

SQL> col OBJECT_NAME format a30

-- 查看scheduler,以及下次执行时间

SQL> select obj#, object_name, next_run_date from sys.scheduler$_job ssj, dba_objects dob where ssj.obj# = dob.object_id and object_name like 'ZYDB_BAK%';

OBJ# OBJECT_NAME                   NEXT_RUN_DATE

---------- ------------------------------ --------------------------------------------------

93354 ZYDB_BAK_LEVEL_0               28-FEB-21 01.38.25.900000 AM PRC

93355 ZYDB_BAK_LEVEL_1               23-FEB-21 01.38.55.400000 AM PRC

-- 查看已创建的JOB

SQL> select job_name, job_type, enabled, state from user_scheduler_jobs where job_name like 'ZYDB_BAK%';

JOB_NAME                       JOB_TYPE         ENABL STATE

------------------------------ ---------------- ----- ---------------

ZYDB_BAK_LEVEL_0               EXECUTABLE       TRUE SCHEDULED

ZYDB_BAK_LEVEL_1               EXECUTABLE       TRUE SCHEDULED

-- 查看JOB运行日志

SQL> select log_id, log_date, status from user_scheduler_job_run_details where job_name like 'ZYDB_BAK%';

no rows selected

至此,备份任务配置完成!

Oracle 数据库

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:MySQL源码学习(六):线性预读
下一篇:主键索引就是聚集索引?MySQL 索引类型大梳理
相关文章