X

Alejandro Vargas' Blog

  • January 30, 2007

Rman Admin and Backup Script for RAC on ASM

Alejandro Vargas
Technical Leader, ACS Global Delivery, Infrastructure & BigData

This script does a couple of Admin activities, then make a backup 'as copy' to File System.

A customer wanted to have something on File System to restore from in case of total loss, in addition to EMC's srdf, just in case...

--------- script start on next line -----------
#!/bin/csh -x
# rman_backup_as_copy_to_FS
# ----------------------------
# 29-01-07 Alejandro Vargas
# ----------------------------
# This script make a backup copy to file system
# This backup can be restored on File system as a regular hot backup
# Or can be restored to ASM by using rman
# -------------------------------------------------------------------------------
# This script does:
# 1) Administrative tasks:
#       crosscheck
#       delete obsolete
# 2) Archive log current on 1st Instance
# 3) Archive log current on 2nd Instance
# 4) Rman backup as copy to file system including controlfile and archivelogs
# 5) Archive log current on 1st Instance
# 6) Archive log current on 2nd Instance
# 7) Rman backup as copy archivelogs not backed up and print backupset list to log
# --------------------------------------------------------------------------------
# This script works with 2 nodes only, if you have more than 2 nodes you need to customize it.
#
# This script use aliases and Environment variables set on .cshrc
# to setup the environment to point to the Database:
# setenv DBS_HOME /u01/app01/oracle/product/10gDB
# setenv BASE_PATH /usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/root/bin
# alias 10db  'setenv $ORACLE_HOME $DBS_HOME; setenv PATH $ORACLE_HOME/bin:$BASE_PATH'

# This script do require as parameters the 2 instance names
# It will use them to archive all required logs from instances 1 and 2
# --------------------------------------------------------------------

set v_inst1=racdbtst1
set v_inst2=racdbtst2

# Rman Backup Location variable
# -----------------------------
set v_rman_loc=/vmasmtest/BACKUP/rman_backups

# Step 1: Administrative tasks, crosscheck and delete obsolete
# ------------------------------------------------------------

10db
setenv ORACLE_SID $v_inst1

rman target / nocatalog <<EOF
crosscheck backupset;
crosscheck copy;
crosscheck archivelog all;
delete noprompt expired backup ;
delete noprompt obsolete;
exit
EOF


# This script run from 1st node. We use an external identified DBA user, ops$oracle, to execute
# the archive log current. From the same session we connect as ops$oracle into the 2nd instance
# You need remote_os_authent=TRUE on both instances to connect remotely without password

# Step 2: Archive log current on 1st Instance
# Step 3: Archive log current on 2nd Instance
# -------------------------------------------

sqlplus -s /@$v_inst1 << EOF
select instance_name from v$instance
/
alter system archive log current
/
connect /@$v_inst2;
select instance_name from v$instance
/
alter system archive log current
/
exit
EOF

# On step 4 we use 4 channels. This needs to be customized according the number of cpu's/IO
# channels available. Rman is invoked in nocatalog mode, we need to have configured
# ORACLE_HOME, ORACLE_SID and PATH on the environment, as we did in the previous steps.

# Step 4: Rman backup as copy to file system including controlfile and archivelogs
# --------------------------------------------------------------------------------

rman target / nocatalog <<EOF
run {
allocate channel backup_disk1 type disk format '$v_rman_loc/%U';
allocate channel backup_disk2 type disk format '$v_rman_loc/%U';
backup as COPY tag '%TAG' database include current controlfile;
release channel backup_disk1;
release channel backup_disk2;
}
exit
EOF

# Step 5 and 6: Archive log current on 1st and 2nd Instances
# ----------------------------------------------------------
sqlplus -s /@$v_inst1 << EOF
select instance_name from v$instance
/
alter system archive log current
/
connect /@$v_inst2;
select instance_name from v$instance
/
alter system archive log current
/
exit
EOF

# Step 7: Rman backup as copy archivelogs not backed up and print backupset list to log

rman target / nocatalog <<EOF
backup as copy archivelog all format '$v_rman_loc/%d_AL_%T_%u_s%s_p%p'  delete input;
list backupset;
exit
EOF

# Redirecting rman output to log will suppress standard output, because of that
# running separately.

rman target / nocatalog log=$v_rman_loc/backupset_info.log <<EOF
list backup summary;
list backupset;
list backup of controlfile;
exit
EOF

# eof rman_backup_as_copy_to_FS
--------- script finish on previous line -------------

Join the discussion

Comments ( 3 )
  • Satish Friday, February 9, 2007
    Alejandro,
    A wonderful script, please accept my compliments.
    I suggest one change. 'alter system archive log current' from the node where RMAN is backed up switches log files of all threads(RAC nodes) - the script, therefore, does not need to be customized for any RAC environment.
    Use a single RMAN block as under :-
    run {
    allocate channel backup_disk1 type disk format '$v_rman_loc/%U';
    allocate channel backup_disk2 type disk format '$v_rman_loc/%U';
    # switch archive logs for all threads
    sql 'alter system archive log current';
    backup as COPY tag '%TAG' database include current controlfile;
    sql 'alter system archive log current';
    crosscheck archivelog all;
    delete noprompt expired archivelog all;
    backup archivelog all ...
    release channel backup_disk1;
    release channel backup_disk2;
    Thanks,
    Satish
  • Satish Friday, February 9, 2007
    An excellent script !!
  • Oswaldo Moscoso Friday, June 19, 2009
    I need scripts for RMAN to do cold backup for RAC to single node
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.