首页 > 数据库 >Oracle ADG环境下的RMAN备份策略

Oracle ADG环境下的RMAN备份策略

时间:2023-02-08 11:23:51浏览次数:62  
标签:log 备份 30 .% echo ADG Oracle RMAN backup

作为IT运维人员,尤其是数据库岗位,数据的备份重于一切。
现在很多用户会有一个普遍误区,认为现在类似ADG这类灾备已经很完善,且实时性也更佳,往往就忽略了传统的备份效用。
但实际上,我们千万不能因为有了容灾建设就盲目忽略备份的作用,二者其实有着本质区别。很多场景,灾备都是无法替代传统备份的,二者是缺一不可的关系。

之前在

中搭建了一套 Single Instance Primary + RAC Standby 的初始环境。
下面我们就给这套数据库环境制定备份策略。

1.主库备份策略

需求:数据库每天全备 + 归档每6小时备份一次;

crontab定时任务设置:
每天1:30执行数据库的全备,每6小时执行数据库归档日志的备份:

[oracle@bogon orabak]$ crontab -l
30 1 * * * /hdd/scripts/backup.sh /hdd/orabak
0 */6 * * * /hdd/scripts/backuparch.sh /hdd/orabak

调用的相关脚本内容参考:

vi /hdd/scripts/backup.sh

#!/bin/bash
#ENV
export ORACLE_SID=demo
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=/u01/app/oracle/product/19.3.0/db_1
export PATH=$ORACLE_HOME/bin:$PATH


#backup RMAN
if [ ! -d "$1" ]; then
        echo "You have input no dir for \$1"
        exit 1
fi

echo "=================================================================================" >>${1}/backup_full.log
echo "Begin backup at : `date`" >> ${1}/backup_full.log
rman target / <<EOF >> ${1}/backup_full.log
run {
CONFIGURE RETENTION POLICY TO REDUNDANCY = 2;
CONFIGURE DEVICE TYPE DISK PARALLELISM 6;
CONFIGURE DEFAULT DEVICE TYPE TO DISK;
backup as compressed backupset database format '${1}/FULLBAK_%d_%T_%s_%p.DBFILE';
backup current controlfile format '${1}/%d.%s.%p.%T.CTL';
backup spfile format '${1}/%d.%s.%p.%T.SPFILE';
crosscheck backup;
crosscheck copy;
sql "alter system archive log current";
backup as COMPRESSED backupset archivelog all not backed up format '${1}/%d.%s.%p.%T.ARC';
crosscheck archivelog all;
delete noprompt archivelog all completed before 'sysdate-10';
delete noprompt expired backup;
delete noprompt obsolete;
}
exit
EOF
echo "End backup at : `date`" >>${1}/backup_full.log

echo "Begin cp to NAS at : `date`" >>${1}/backup_full.log
cp ${1}/*`date +%Y%m%d`* /public/Others/orabak
echo "End cp to NAS at : `date`" >>${1}/backup_full.log
echo "=================================================================================" >>${1}/backup_full.log

exit 0

vi /hdd/scripts/backuparch.sh

#!/bin/bash
#ENV
export ORACLE_SID=demo
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=/u01/app/oracle/product/19.3.0/db_1
export PATH=$ORACLE_HOME/bin:$PATH

#backup RMAN
if [ ! -d "$1" ]; then
        echo "You have input no dir for \$1"
        exit 1
fi

echo "=================================================================================" >>${1}/backup_arch.log
echo "Begin backup at : `date`" >> ${1}/backup_arch.log
rman target / <<EOF >> ${1}/backup_arch.log
run {
CONFIGURE RETENTION POLICY TO REDUNDANCY = 2;
CONFIGURE DEVICE TYPE DISK PARALLELISM 6;
CONFIGURE DEFAULT DEVICE TYPE TO DISK;
backup current controlfile format '${1}/%d.%s.%p.%T.CTL';
backup spfile format '${1}/%d.%s.%p.%T.SPFILE';
crosscheck backup;
crosscheck copy;
sql "alter system archive log current";
backup as COMPRESSED backupset archivelog all not backed up format '${1}/%d.%s.%p.%T.ARC';
crosscheck archivelog all;
delete noprompt archivelog all completed before 'sysdate-10';
delete noprompt expired backup;
delete noprompt obsolete;
}
exit
EOF
echo "End backup at : `date`" >>${1}/backup_arch.log

echo "Begin cp to NAS at : `date`" >>${1}/backup_arch.log
cp ${1}/*`date +%Y%m%d`*.{CTL,SPFILE,ARC} /public/Others/orabak
echo "End cp to NAS at : `date`" >>${1}/backup_arch.log
echo "=================================================================================" >>${1}/backup_arch.log

exit 0

2.备库备份策略

需求:每10分钟清除4h之前的归档日志;

crontab定时任务设置:

[oracle@db01rac1 scripts]$ crontab -l
*/10 * * * * /u01/scripts/delarch.sh /u01/scripts

调用的相关脚本内容参考:
vi /u01/scripts/delarch.sh

#!/bin/bash
#ENV
export ORACLE_SID=jydb1;
export ORACLE_BASE=/u01/app/oracle;
export ORACLE_HOME=/u01/app/oracle/product/19.3.0/db_1;
export PATH=$ORACLE_HOME/bin:$PATH;

#RMAN delete archivelog
if [ ! -d "$1" ]; then
        echo "You have input no dir for \$1"
        exit 1
fi

echo "=================================================================================" >>${1}/delarch.log
echo "Begin backup at : `date`" >> ${1}/delarch.log
rman target / <<EOF >> ${1}/delarch.log
delete noprompt archivelog all completed before 'sysdate - 1/24*4';
EOF
echo "End backup at : `date`" >>${1}/delarch.log
echo "=================================================================================" >>${1}/delarch.log

exit 0

3.测试备份策略

在实际部署上面备份脚本后,验证阶段发现有报错信息:

You have mail in /var/spool/mail/oracle
[oracle@bogon ~]$
[oracle@bogon ~]$ tail -200f /var/spool/mail/oracle
From [email protected]  Mon Jan 30 18:00:25 2023
Return-Path: <[email protected]>
X-Original-To: oracle
Delivered-To: [email protected]
Received: by bogon.localdomain (Postfix, from userid 10001)
	id 8738341B51FA; Mon, 30 Jan 2023 18:00:25 +0800 (CST)
From: "(Cron Daemon)" <[email protected]>
To: [email protected]
Subject: Cron <oracle@bogon> /hdd/scripts/backuparch.sh /hdd/orabak
Content-Type: text/plain; charset=UTF-8
Auto-Submitted: auto-generated
Precedence: bulk
X-Cron-Env: <XDG_SESSION_ID=4131>
X-Cron-Env: <XDG_RUNTIME_DIR=/run/user/10001>
X-Cron-Env: <LANG=en_US.UTF-8>
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/home/oracle>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=oracle>
X-Cron-Env: <USER=oracle>
Message-Id: <[email protected]>
Date: Mon, 30 Jan 2023 18:00:18 +0800 (CST)

cp: cannot stat ‘/hdd/orabak/*20230130*.CTL’: No such file or directory
cp: cannot stat ‘/hdd/orabak/*20230130*.SPFILE’: No such file or directory

查看备份日志:

516 Deleting the following obsolete backups and copies:
517 Type                 Key    Completion Time    Filename/Handle
518 -------------------- ------ ------------------ --------------------
519 Backup Set           20     30-JAN-23
520   Backup Piece       20     30-JAN-23          /flash/fast_recovery_area/DEMO/autobackup/2023_01_30/o1_mf_s_1127488370_kxgvhm1c_.bkp
521 Backup Set           30     30-JAN-23
522   Backup Piece       30     30-JAN-23          /flash/fast_recovery_area/DEMO/autobackup/2023_01_30/o1_mf_s_1127488380_kxgvhwj0_.bkp
523 Backup Set           31     30-JAN-23
524   Backup Piece       31     30-JAN-23          /hdd/orabak/DEMO.56.1.20230130.CTL
525 Backup Set           32     30-JAN-23
526   Backup Piece       32     30-JAN-23          /hdd/orabak/DEMO.57.1.20230130.SPFILE
527 deleted backup piece
528 backup piece handle=/flash/fast_recovery_area/DEMO/autobackup/2023_01_30/o1_mf_s_1127488370_kxgvhm1c_.bkp RECID=20 STAMP=1127488371
529 Deleted 1 objects
530
531 deleted backup piece
532 backup piece handle=/flash/fast_recovery_area/DEMO/autobackup/2023_01_30/o1_mf_s_1127488380_kxgvhwj0_.bkp RECID=30 STAMP=1127488380
533 Deleted 1 objects
534
535 deleted backup piece
536 backup piece handle=/hdd/orabak/DEMO.57.1.20230130.SPFILE RECID=32 STAMP=1127498407
537 Deleted 1 objects
538
539 deleted backup piece
540 backup piece handle=/hdd/orabak/DEMO.56.1.20230130.CTL RECID=31 STAMP=1127498406
541 Deleted 1 objects
542
543
544 RMAN>
545

发现针对控制文件和参数文件,在最后居然被删掉了。。

梳理脚本逻辑,确认是这条命令触发的删除:

delete noprompt obsolete;

何为obsolete?目前策略中的 REDUNDANCY 设置为2,但是因为开启了自动的控制文件备份(其中也会同时包含参数文件),所以反而手工备份的都没有被传输到备份端。

另外,需要注意的是,这不是一个小问题,因为这会给正常恢复带来很大的麻烦;
试想,没有这两个文件,尤其是控制文件的备份存档到NAS,一旦主机crash,通过NAS上的备份就成为无稽之谈。

那么解决方案呢?也很简单,修改默认值,默认值为:

CONFIGURE CONTROLFILE AUTOBACKUP ON; # default
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '%F'; # default

因此对应了两种修改方式:

方式一:关闭RMAN中控制文件的自动备份;

CONFIGURE CONTROLFILE AUTOBACKUP OFF; 

方式二:设置RMAN中控制文件自动备份的路径为我们备份的路径:

CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/hdd/orabak/AUTO_%F.CTL'; 

4.ADG环境下的特殊配置

为了应对主备角色切换期间等场景,在主备库都配置上归档删除策略,确保未传到备库的归档不会被删除:

RMAN> CONFIGURE ARCHIVELOG DELETION POLICY TO SHIPPED TO ALL STANDBY;

new RMAN configuration parameters:
CONFIGURE ARCHIVELOG DELETION POLICY TO SHIPPED TO ALL STANDBY;
new RMAN configuration parameters are successfully stored

标签:log,备份,30,.%,echo,ADG,Oracle,RMAN,backup
From: https://www.cnblogs.com/jyzhao/p/17099026.html

相关文章

  • oracle 分配权限命令
    Oracle分配权限以管理员身份登录数据库创建用户:createuser[username]identifiedby[password];赋予登录权限:grantcreate session to[username];赋予建表权限:gr......
  • Oracle:卸载与安装
    卸载如何完全彻底卸载Oracle安装windows安装Oracle详细教程查看字符集SELECT*FROMNls_Database_Parameters......
  • Oracle VM VirtualBox网络在主机模式下实现访问外网
    提前条件:虚拟机网络已设置为主机模型目标是将能上网的网卡共享给虚拟主机的网卡  操作步骤:1.在主机上打开能上网的网卡,上面是WLAN,打开属性 2.切换到共享,选择......
  • Oracle19c 解决ORA-28001
    今天一个网页出现404错误查看tomcat日志发现是数据库连接不上了,报错信息上可以看出是用户的口令(密码)失效了,查阅相关资料,发现oracle12c会默认给每一个用户的口令180天的有效......
  • mysql与oracle语法区别
    1.MySQL的字符串类型是varchar:CODEVARCHAR(40),Oracle中是varchar2:CODEVARCHAR2(40)。2.MySQL的数值类型是decimal,FLOAT,DOUBLE,Oracle中是NUMBER。3.MySQL支持在建表时同时......
  • Performance API不完全使用指北
    本教程解释了如何使用PerformanceAPI来记录真实用户访问你的应用程序的统计数据。使用浏览器的DevTools来评估web应用性能是很有用的,但要复现现实世界的使用情况并不容......
  • IDEA加载项目时提示Windows Defender might be impacting your build performance
    1.点击fix,弹出对话框,选择configureautomatically,选择ok2.出现以下提示表示成功 3.若不成功,可以手动设置防火墙白名单,添加排除项 ......
  • 7.DG和ADG的区别
    DG(DataGuard)DG(DataGuard,数据卫士)不是一个备份恢复的工具,然而,DG却拥有备份的功能,在物理DG下它可以和主库一模一样,但是它存在的目的并不仅仅是为了备份恢复数据,应该说它的......
  • 52.Toad for Oracle 使用说明
    一.Toad功能综述 二.系统需求 三.安装指南 四.快速入门 1.Schemabrowser的用法简介 2.SQEditor的使用介绍 3.ProcedureEditor的用法介绍 4.如何进行PLSQL的debug 5.如何......
  • Debug - Navivat创建Oracle连接时,报错cannot create oci environment
     解决方案这个问题的原因是navicat不能创建oci的环境。在工具-->选项-->其他-->oci中配置中默认是指向在安装路径下的instantclient_10_2/oci.dll。按默认的其实是不对......