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