分享一个Oracle分时间段归档脚本(清理ASM空间)
概述
端午节又给叫醒了...好吧,又是ASM归档空间问题导致,说一下背景,因ASM空间不够,硬盘槽也插满了,每天归档量大概100G,所以在对UNDO表空间增加20G空间后隔天归档又爆了。
正常情况是3点执行增备脚本备份归档到本地并把ASM的归档清理掉,ASM保留的归档都是从3点往后算的,增加20G后终于达到了临界值,导致到3点前归档空间已经满了,无法执行相关的脚本并自动清理。
这里大概有几个解决方案:
1、对数据库瘦身,腾出空间
2、数据库整体迁移
3、买个主机,大概30万(领导否决了)
前面2个不是一时半会解决的,所以这里取个巧,把增备脚本改成每天多次执行,这样ASM的归档就不会保留一天了。
清理归档脚本
#!/bin/bash #this is rman auto incr backup script backtime=$(date +%Y%m%d%H%M) if [ -f ~/.bash_profile ]; then . ~/.bash_profile fi rman target / log=/backup/log/incr_$backtime.log <<EOF run { sql 'alter system archive log current'; allocate channel c1 type disk; allocate channel c2 type disk; backup as compressed backupset tag incr_backup_level1 incremental level 1 format '/backup/oradata/level1_%T_%t_s%s_p%p.bak' database; sql 'alter system archive log current'; backup as compressed backupset format '/backup/arch/archlog_%T_t%t_s%s_p%p.bak' archivelog all delete input; release channel c1; release channel c2; allocate channel d1 type disk; backup format '/backup/control/controlfile_%T_s%s_p%p.bak' current controlfile; crosscheck backup; crosscheck copy; delete noprompt expired backup; delete noprompt obsolete; delete noprompt backup of database completed before'sysdate-7'; release channel d1; } EOF
这里是利用backup ...all delete input的特性来清理掉ASM上的归档。
测试脚本
执行脚本后查看日志
观察ASM空间容量
可以看到空间已经减下来了。
设置定时任务
00 03,12,23 * * 2-6,0 /home/oracle/scripts/level1_backup.sh
后面会分享更多devops和DBA方面内容,感兴趣的朋友可以关注下!
相关推荐
hzcyhujw 2019-04-25
beibeijia 2020-06-07
oraclemch 2020-05-09
末点 2020-05-01
haiross 2020-01-11
oraclemch 2019-12-15
TripleGold 2019-11-08
qiaosym 2011-03-02
downtown 2010-12-20
Streamoutput 2019-11-08
hairetz 2008-08-08
点滴技术生活 2019-05-27
海内存知己 2019-05-27
TemateRoom 2019-03-19
编程点滴 2013-03-08
zhangdy0 2015-02-08
81357216 2019-06-28
spring 2013-01-07
MicroBoy 2012-11-29