0% found this document useful (0 votes)
531 views5 pages

How To Take RMAN Full Backup Using Shell Scrip1

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 5

How to create cold backup using RMAN?

Using the steps below one take cold backup using RMAN. As its a cold backup the database as the database is in

mount stage and the database doesnt have to be archivelog mode .

Step 1) Shutdown database

SQL> shutdown immediate;

Step 2) Start database in mount stage

SQL> startup mount;

Step 3) Run rman and connect to target database and run rman to backup database and connection to

catalog if you are using one

$ ./rman target /

RMAN> backup database;

RMAN>list backup;

RMAN command to create level 0 backup which is needed before running of incremental backup level 1

RMAN> BACKUP INCREMENTAL LEVEL 0 DATABASE;


RMAN command to run level 1 backup. Level 1 backup will backup all blocks changed since most recent

cumulative or differential backup. If a level 0 backup doesnt exists, when running INCREMENTAL backup

Oracle will perform a full backup.

RMAN> BACKUP INCREMENTAL LEVEL 1 DATABASE;


RMAN command to run level 1 cumulative backup. Level 1 backup will backup all blocks changed since

most recent Level 0 backup. If a level 0 backup doesnt exists, when running INCREMENTAL backup

Oracle will perform a full backup.

RMAN> BACKUP INCREMENTAL LEVEL 1 CUMULATIVE DATABASE;


RMAN command to backup database level 1 and skip datafiles and archived redo logs that cannot be read

due to I/O errors to be excluded from backup

RMAN> BACKUP INCREMENTAL LEVEL 1 INACCESSIBLE DATABASE;

Oracle Alert log monitoring using shell script

Vi /u02/Backups/Script/alertlog_monotor.sh

#!/bin/bash
export ORACLE_SID=galaxy
export ORAENV_ASK=NO
. /home/oracle/.bash_profile
[email protected]
SERPUBIP=192.168.100.1
SERVER=`dbserver.indolne.in` #### Sets the server name for the email
WEEKDAY=`date '+%w%H%M'` #### Sets the number value of the day of the week
DATE_VAR=`date '+%Y_%m_%d'`

Alert_log_loc=/u01/DbServer/oracle/diag/rdbms/galaxy2/galaxy2/trace/
# Check for the existence of ORA- in the alert log and email/page on error
egrep 'ORA-|error|TNS' $Alert_log_loc/alert_$ORACLE_SID.log |sort -u
> $Alert_log_loc/$ORACLE_SID_OUT_ALERTLOG.txt #### Output file with ORA- errors
cat $Alert_log_loc/alert_$ORACLE_SID.log >> $Alert_log_loc/archived_alert_$ORACLE_SID.log
cat /dev/null > $Alert_log_loc/alert_$ORACLE_SID.log

if [ -s "$Alert_log_loc/$ORACLE_SID_OUT_ALERTLOG.txt" ] ; then
cat $Alert_log_loc/$ORACLE_SID_OUT_ALERTLOG.txt | mail -s "URGENT -ERROR in Oracle Alert Log
File for $SERNAME ($SERPUBIP) at `date` " [email protected]
fi

# Weekly alert log datestamp and compress (Sunday 00:15)

if [[ $WEEKDAY -eq 00015 ]]; then


mv $Alert_log_loc/archived_alert_${ORACLE_SID}.log
$Alert_log_loc/archived_alert_${ORACLE_SID}_${DATE_VAR}.log
gzip $Alert_log_loc/archived_alert_${ORACLE_SID}_${DATE_VAR}.log
fi

exit 0

:wq (save & exit)

Now Schedule the above script in crontab for every 15mins.

crontab -l

*/15 * * * * /backups/alertlog_monotor.sh

How to take RMAN Full backup using Shell script

Create the following backup path:-


[oracle@server1 ~]$ mkdir -p /u01/backups/rman_backup/full_backup
[oracle@server1 ~]$ mkdir -p /u01/backups/scripts/

Make sure database is in archivelog mode , if its not put it on archivelog mode.

SQL> sqlplus / as sysdba


SQL> startup mount;
SQL> alter database archivelog;
SQL> alter database open;

[oracle@server1 ~]$ vi /u01/backups/scripts/full_backup.sh

#!/bin/bash
export ORACLE_SID=galaxy
export ORACLE_BASE=/u01/DbServer/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_1
export LD_LIBRARY_PATH=$ORACLE_HOME/lib
export PATH=$ORACLE_HOME/bin:/bin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/X11R6/bin
export path1=/u02/Backups/rman_backup/full_backup
date1=`date +%d%m%y_%H%M%S`
mkdir $path1/$date1
chown oracle:oinstall -R $path1/$date1
$ORACLE_HOME/bin/rman target / <<eof
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 2 DAYS;
report obsolete;
delete Noprompt obsolete;
configure CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO
'$path1/$date1/control_%d_%F';
run
{
backup incremental level 0 database FORMAT '$path1/$date1/full_%d_%T_%t_%s_%p';
backup archivelog all FORMAT '$path1/$date1/archive_%d_%T_%t_%s_%p' ;
}
eof

cd $path1
file1=`ls -ltrh | tail -1 | awk '{print $9}'`
tar -zcvf $file1.tar.gz $file1

:wq (save & exit)

Now schedule the script using crontab from oracle user:-


#The script will run everynight at 12 A.M

[oracle@server1 ~]$ crontab -e


0 0 * * * /u01/backups/scripts/full_backup.sh > /dev/null

How to take RMAN INCREMENTAL LEVEL 1 Backup using Shell script


Create the following backup path:-
[oracle@server1 ~]$ mkdir -p /u01/backups/rman_backup/inc_level_1
[oracle@server1 ~]$ mkdir -p /u01/backups/scripts/

Make sure database is in archivelog mode , if its not put it on archivelog mode.

SQL> sqlplus / as sysdba


SQL> startup mount;
SQL> alter database archivelog;
SQL> alter database open;

[oracle@server1 ~]$ vi /u02/Backups/Scripts/IncLevel_1_rman_backup.sh

#!/bin/bash
export PS1="`/bin/hostname s`> "
export ORACLE_SID=galaxy
export ORACLE_BASE=/u01/DbServer/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_1
export PATH=$ORACLE_HOME/bin:/bin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/X11R6/bin
export path1=/u02/Backups/rman_backup/inc_level_1
date1=`date +%d%m%y_%H%M%S`
mkdir $path1/$date1
chown oracle:oinstall -R $path1/$date1
$ORACLE_HOME/bin/rman target / <<eof
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 2 DAYS;
report obsolete;
delete Noprompt obsolete;
configure CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '$path1/$date1/control_%d_%F';
backup incremental level 1 database FORMAT '$path1/$date1/inc_level_1_%d_%T_%t_%s_%p';

eof

cd $path1
file1=`ls -ltrh | tail -1 | awk '{print $9}'`
tar -zcvf $file1.tar.gz $file1

:wq (save & exit)

Now schedule the script using crontab from oracle user:-


#The script will run every 30mins

[oracle@server1 ~]$ chmod 755 /u01/backups/scripts/IncLevel_1_rman_backup.sh


[oracle@server1 ~]$ crontab -e
15,45 * * * * /u01/backups/scripts/IncLevel_1_rman_backup.sh > /dev/null

How to take RMAN INCREMENTAL LEVEL 1 Cumulative Backup using Shell script
Create the following backup path:-
[oracle@server1 ~]$ mkdir -p /u02/Backups/rman_backup/inc_level_1_cum
[oracle@server1 ~]$ mkdir -p /u02/Backups/scripts/

Make sure database is in archivelog mode , if its not put it on archivelog mode.

SQL> sqlplus / as sysdba


SQL> startup mount;
SQL> alter database archivelog;
SQL> alter database open;

[oracle@server1 ~]$ vi /u01/backups/scripts/IncLevel_1_Cum_rman_backup.sh

#!/bin/bash
export PS1="`/bin/hostname s`> "
export ORACLE_SID=galaxy
export ORACLE_BASE=/u02/DbServer/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_1
export PATH=$ORACLE_HOME/bin:/bin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/X11R6/bin
export path1=/u02/Backups/rman_backup/inc_level_1_cum
date1=`date +%d%m%y_%H%M%S`
mkdir $path1/$date1
chown oracle:oinstall -R $path1/$date1
su - oracle -c "$ORACLE_HOME/bin/rman target / " <<eof
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 2 DAYS;
report obsolete;
delete Noprompt obsolete;
configure CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '$path1/$date1/control_%d_%F';
backup incremental level 1 cumulative database FORMAT '$path1/$date1/inc_level_1_cum_%d_%T_%t_%s_%p';
eof

[oracle@server1 ~]$ chmod 755 /u02/Backups/Scripts/IncLevel_1_Cum_rman_backup.sh

Now schedule the script using crontab from oracle user:-


The script will run every 6 hours

[oracle@server1 ~]$ crontab -e

0 */6 * * * /u02/Backups/Scripts/IncLevel_1_Cum_rman_backup.sh > /dev/null

You might also like