0% found this document useful (0 votes)
598 views

How To Take RMAN Full Backup Using Shell Scrip1

The document describes how to take different types of RMAN backups including cold, full, incremental level 1, and incremental level 1 cumulative backups using RMAN commands and shell scripts. It provides steps to shutdown and mount the database, connect to RMAN and run backup commands, and schedule the backups using shell scripts and crontab. The key points are: 1) Cold backups are taken when the database is mounted and not in archivelog mode. Full and incremental backups require the database to be open and in archivelog mode. 2) Backup scripts are created to automate full, incremental level 1, and incremental level 1 cumulative backups using RMAN and shell commands. 3) The scripts are scheduled using

Uploaded by

Sopan sonar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
598 views

How To Take RMAN Full Backup Using Shell Scrip1

The document describes how to take different types of RMAN backups including cold, full, incremental level 1, and incremental level 1 cumulative backups using RMAN commands and shell scripts. It provides steps to shutdown and mount the database, connect to RMAN and run backup commands, and schedule the backups using shell scripts and crontab. The key points are: 1) Cold backups are taken when the database is mounted and not in archivelog mode. Full and incremental backups require the database to be open and in archivelog mode. 2) Backup scripts are created to automate full, incremental level 1, and incremental level 1 cumulative backups using RMAN and shell commands. 3) The scripts are scheduled using

Uploaded by

Sopan sonar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
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
SERNAME=info@indoline.in
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` " sopan.sonar@gmail.com
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

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy