shell判断oracle主备,shell判断oracle主备数据库备份脚本

1.脚本如下

说明:按照客户要求,在主备数据库上同时部署脚本,自动判断是否是主库,如果是主库则进行备份,备库不需要备份,记录日志为备份库即可,以下脚本仅供参考,可以进一步优化。

脚本说明:

1、DATABASE_ROLE查看主备库角色变量

2、Main()函数 数据库备份脚本

3、根据主备库关键字判断是否执行main()函数

#!/bin/bash

# Author:roidba

# filename:/backup/backup.sh

#logfile:/backup/rman_fullbackup.log

ORACLE_SID=orcl; export ORACLE_SID

ORACLE_BASE=/u01/app/oracle; export ORACLE_BASE

ORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_1; export ORACLE_HOME

PATH=.:${JAVA_HOME}/bin:${PATH}:$HOME/bin:$ORACLE_HOME/bin

####variables###

DATABASE_ROLE=`sqlplus -silent "/as sysdba" <

SET PAGESIZE 0 FEEDBACK OFF VERIFY OFF HEADING OFF ECHO OFF

select DATABASE_ROLE from v\\\$database;

EXIT;

EOF`

###function###

main()

{

($ORACLE_HOME/bin/rman<

connect target /

run {

CONFIGURE CONTROLFILE AUTOBACKUP ON;

CONFIGURE BACKUP OPTIMIZATION ON;

allocate channel d1 type disk;

allocate channel d2 type disk;

backup as compressed backupset database format '/backup/fulldbbakcup_%s_%p_%t.rmn' tag='fulldbbackup' include current controlfile;

backup as compressed backupset archivelog all format '/backup/backup_archive_%s_%p_%t.arc';

release channel d1;

release channel d2;

crosscheck backup;

delete noprompt expired backup;

delete noprompt archivelog until time 'sysdate -3' backed up 1 times to device type disk;

delete noprompt backupset of archivelog until time 'sysdate -3' ;

delete noprompt backupset of database completed before 'sysdate - 3';

}

exit;

EOF

)

}

###if-then-else###

if [ "$DATABASE_ROLE" = "PRIMARY" ];

then

main

echo "***database role is primary***">>/backup/rman_fullbackup.log

else

echo "database role is standby"

fi

2.自动备份,使用crontab调度

sh /backup/rman_backup.sh >>/backup/rman_fullbackup.log&

crontab -e

07 20 * * *sh /backup/rman_backup.sh >>/backup/rman_fullbackup.log&

3.理解crontab格式

$more /etc/crontab

SHELL=/bin/bash

PATH=/sbin:/bin:/usr/sbin:/usr/bin

MAILTO=root

HOME=/

# For details see man 4 crontabs

# Example of job definition:

# .---------------- minute (0 - 59)

# |  .------------- hour (0 - 23)

# |  |  .---------- day of month (1 - 31)

# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...

# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat

# |  |  |  |  |

# *  *  *  *  * user-name command to be executed

$

原文:http://blog.51cto.com/roidba/2119684

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值