Shell to determine Oracle backup script for primary and standby databases

Source: Internet
Author: User


1. The script is as follows

Note: According to customer requirements, in the primary and standby database to deploy the script at the same time, automatically determine whether it is the main library, if the main library is backed up, the repository does not need backup, logging is the backup library, the following script is for reference only, can be further optimized.

Script Description:

1. Database_role View the main repository role variables

2. Main () function Database backup script

3. determine if the main () function is executed according to the Master repository keyword

#!/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" <<eof

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 <<eof

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 /full dbbakcup _%s_%p_%t.rmn ' tag= ' Span style= "; font-family: Song body; font-size:14px" >fulldbbackup

Backup as compressed backupset archivelog all format '/ Backup / Backup _archive_%s_%p_%t.arc ';

Release Channel D 1 ;

Release Channel D 2 ;

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"

F I

2. automatic backup, using crontab scheduling

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

Crontab-e

* * * sh/backup/rman_backup.sh >>/backup/rman_fullbackup. Log &

3. Understanding the crontab format

<roidb01:orcl:/backup> $more/etc/crontab

Shell=/bin/bash

Path=/sbin:/bin:/usr/sbin:/usr/bin

Mailto=root

home=/

# for details see Mans 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

<roidb01:orcl:/backup>$


Shell to determine Oracle backup script for primary and standby databases

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.