企业Oracle数据库备份实施手记
【摘要】 作为企业应用的核心数据库,备份必不可少;如果单位预算多的,可以考虑直接上专业的备份软件(NetBackup、CommVault等均可),预算不多的话,也可以像我一样,通过Oracle数据库自带的RMAN工具,来实现自动备份。
作为企业应用的核心数据库,备份必不可少;如果单位预算多的,可以考虑直接上专业的备份软件(NetBackup、CommVault等均可),预算不多的话,也可以像我一样,通过Oracle数据库自带的RMAN工具,来实现自动备份;
以下为我司ERP系统的配置过程,以及备份策略,以此记录以备参考;
关于备份策略,因为企业ERP的备份数据量并不大,所以只定义两级策略,策略如下:
星期日 | 星期一 | 星期二 | 星期三 | 星期四 | 星期五 | 星期六 | |
---|---|---|---|---|---|---|---|
备份级别 | 0 | 1 | 1 | 1 | 1 | 1 | 1 |
另外,根据业务人员的要求,数据库备份保留策略为14天,如下所示:
RMAN> show all;
using target database control file instead of recovery catalog
RMAN configuration parameters for database with db_unique_name OADB are:
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 14 DAYS;
CONFIGURE BACKUP OPTIMIZATION OFF; # default
CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default
CONFIGURE CONTROLFILE AUTOBACKUP OFF; # default
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '%F'; # default
CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET; # default
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE MAXSETSIZE TO UNLIMITED; # default
CONFIGURE ENCRYPTION FOR DATABASE OFF; # default
CONFIGURE ENCRYPTION ALGORITHM 'AES128'; # default
CONFIGURE COMPRESSION ALGORITHM 'BASIC' AS OF RELEASE 'DEFAULT' OPTIMIZE FOR LOAD TRUE ; # default
CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default
CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/oracle/app/product/11.2.0/dbhome_1/dbs/snapcf_oadb.f'; # default
RMAN>
# 注:控制文件的备份,在备份脚本内定义;
备份的自动周期性执行,则是通过Linux系统自动的Crontab服务来实现:
# 确保crond服务运行,且开机自动启动:
# systemctl start crond && systemctl enable crond
# systemctl status crond
● crond.service - Command Scheduler
Loaded: loaded (/usr/lib/systemd/system/crond.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2020-01-22 12:15:28 CST; 1 years 0 months ago
Main PID: 1679 (crond)
CGroup: /system.slice/crond.service
└─1679 /usr/sbin/crond -n
Jan 22 12:15:28 ly-eims-web-01 systemd[1]: Started Command Scheduler.
Jan 22 12:15:28 ly-eims-web-01 crond[1679]: (CRON) INFO (RANDOM_DELAY will be scaled with factor 5% if used.)
Jan 22 12:15:28 ly-eims-web-01 crond[1679]: (CRON) INFO (running with inotify support)
# 以下定义全量备份为周日执行,增量备份为周一到周六执行:
# 注:crontab的定义,在oracle用户环境内配置;
$ crontab -l
0 3 * * 0 /dbbackup/ltdb/scripts/cron_full_oadb.sh
0 3 * * 1-6 /dbbackup/ltdb/scripts/cron_incr_oadb.sh
# 此处嵌套了一层,将备份脚本的所有输出,重定向到磁盘日志文件,以备后查:
$ more /dbbackup/ltdb/scripts/cron_full_oadb.sh
/dbbackup/ltdb/scripts/full_oadb.sh >> /dbbackup/ltdb/backuplog/full_oadb/full_oadb_`date +%Y%m%d-%H%M%S`.log
$ more /dbbackup/ltdb/scripts/cron_incr_oadb.sh
/dbbackup/ltdb/scripts/incr_oadb.sh >> /dbbackup/ltdb/backuplog/incr_oadb/incr_oadb_`date +%Y%m%d-%H%M%S`.log
以下是全量备份脚本(full_oadb.sh)内容
$ more /dbbackup/ltdb/scripts/full_oadb.sh
echo -e '******Start********_'$(date '+%Y%m%d%H%M%S')
export ORACLE_SID=oadb
export ORACLE_BASE=/oracle/app
export ORACLE_HOME=/oracle/app/product/11.2.0/dbhome_1
export PATH=$ORACLE_HOME/bin:$PATH
rman target sys/oracle@oadb<<EOF
run{
allocate channel c1 type disk;
backup as compressed backupset incremental level 0 tag 'oadb_incr_L0' format
'/dbbackup/ltdb/oadb/full_%d_%T_%s' database include current controlfile;
backup as compressed backupset archivelog all format '/dbbackup/ltdb/oadb/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;
}
exit;
EOF
说明:
1. 数据库的备份目录(/dbbackup/ltdb/oadb/)需要事先创建好;
2. 本次实施,备份目录/dbbackup,使用的是华为云上的 sfs 弹性文件服务挂载的目录,执行备份前,需要先挂载好 sfs文件系统,并配置好oracle用户权限;
$ more /dbbackup/ltdb/scripts/incr_oadb.sh
echo -e '******Start********_'$(date '+%Y%m%d%H%M%S')
export ORACLE_SID=oadb
export ORACLE_BASE=/oracle/app
export ORACLE_HOME=/oracle/app/product/11.2.0/dbhome_1
export PATH=$ORACLE_HOME/bin:$PATH
rman target sys/oracle@oadb <<EOF
run{
allocate channel c1 type disk;
backup as compressed backupset incremental level 1 tag 'oadb_incr_L1' format
'/dbbackup/ltdb/oadb/incr_%d_%T_%s' database include current controlfile;
backup as compressed backupset archivelog all format '/dbbackup/ltdb/oadb/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;
}
exit;
EOF
如上,rman的备份操作配置完成!
【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)