Script to back up the controlfile of a database

This script backs up the controlfile of a database. It runs a sql statement to back up the controlfile to a file, a SQL file that can then be edited and run to recreate the controlfile should it ever become corrupt. En español

bkp_ctrl.sh below:
#!/bin/sh
 
# parameters
# 1: enter the SID for the database whose controlfile is being backed up.
# 2: enter the ORACLE_HOME for that database.
export ORACLE_SID=$1
export ORACLE_HOME=$2
DATE=`date +%y_%m_%d`
# change the location of the sql to a place that exists in your server
$ORACLE_HOME/bin/sqlplus -s ‘/ as sysdba’ <<EOF
set pagesize 0
set echo off
set trimspool on
set feedback on
set head off
ALTER DATABASE BACKUP CONTROLFILE TO TRACE AS ‘/home/oracle/backups/create_`echo $ORACLE_SID`_`echo $DATE`.sql’ REUSE;
EOF

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s