Here we will discuss step by step to take rman backup and automate/schedule
it using crontab in linux,solaris and unix platform. After that for restoration of rman backup check another post for Restoration of RMAN Backup from one server to another server.
As per my experience, here mentioning below rman backup
scripts that was already test in test
instance and live environment as well for
daily, weekly ,monthly and yearly backup.
Below script will do the
following task:-
👉 Backup Oracle Home binary file using tar.
👉 Backup the complete database, control file and all archivelog.
👉 Crosshcheck datatabase rman backup and archivelog .
👉 Delete old backup which have taken before 4 day’s.
👉 Delete expired archivelog.
copy the entire shell
script and create rmanbkp.sh file.
Shell Script:- /data01/crontab_scripts/rmanbkp.sh
#!/bin/ksh
#Created by Sajid Quamer
. /data05/11.2.0.4/PROD_db.env
destnation=/backup/rmanPROD/`date
+"%A"_"%d-%m-%y"_"%T"`
export destnation
old=/backup/rmanPROD/Last_`date
+"%A"_"%d-%m-%y"_"%T"`
export old
#cd /backup/archive_bkp/
mv $destnation $old
mkdir -p $destnation
#Cleanig OLD Backup
rm -rf $old
cd /backup/rmanPROD/
find . -name "*.rbkp"
-mtime +10 -exec rm -rf {} \;
find . -name "*.tgz"
-mtime +10 -exec rm -rf {} \;
#Backing up Oracle Binary file.
cd $ORACLE_HOME
tar -cvzf $destnation/11.2.0.4.tgz
*
rman target / nocatalog
cmdfile=/data01/crontab_scripts/rmanbkp.sql log=$destnation/full_bkp_.log
cd /backup/rmanPROD/
find . -name "*.rbkp"
-mtime +10 -exec rm -rf {} \;
find . -name "*.tgz"
-mtime +10 -exec rm -rf {} \;
#Transfer RMAN backup to Backup
Server (172.168.11.10)
#sh
/acedata01/crontab_scripts/rmanFTP.sh
bkp=`date +"%A"`
cd $destnation
ftp -n 172.168.11.10 <<
!EOF
user orauat orauat1
prompt
bin
cd /backup/rmanPROD
mkdir $bkp
cd /backup/rmanPROD/$bkp
lcd $destnation
mput *.tgz
mput DB*
mput ARCBAK*
mput C*
mput *.log
quit
!EOF
Step 2: Prepare Rman Backup
script :-
simply copy the below rman backup script to make rmanbkp.sql
file.
Rman Backup Script file:- /data01/crontab_scripts/rmanbkp.sql
RUN
{
sql 'alter system archive log current';
BACKUP AS compressed backupset filesperset
8 DATABASE FORMAT '$destnation/DB_%d_%p_%T_%s.rbkp' TAG DAILY_HOT_BACKUP;
sql 'alter system archive log current';
BACKUP AS compressed backupset ARCHIVELOG ALL
NOT BACKED UP 1 TIMES FORMAT '$destnation/ARCBAK_%d_%p_%T_%s.rbkp' TAG
ARCHIVE_BKP;
BACKUP AS compressed backupset CURRENT
CONTROLFILE FORMAT '$destnation/CNT_%d_%p_%T_%s.rbkp' TAG CONTROL_FILE;
CROSSCHECK COPY;
CROSSCHECK BACKUP;
CROSSCHECK ARCHIVELOG ALL;
DELETE ARCHIVELOG UNTIL TIME 'sysdate-4'
BACKED UP 1 TIMES TO DEVICE TYPE DISK;
DELETE EXPIRED BACKUP;
DELETE NOPROMPT OBSOLETE;
DELETE NOPROMPT EXPIRED COPY;
DELETE NOPROMPT EXPIRED BACKUP;
DELETE NOPROMPT EXPIRED ARCHIVELOG ALL;
}
exit;
Step 3: Schedule rman backup shell
scripts:-
Crontab syntax:-
Basically Crontab file has six fields
for specifying minute, hour, day of month, month, day of week and the command to be run .
* * * * * command or scripts
file to be executed.
| ||||
| | | |+----->day of week (0
-6) (Sunday=0)
| | | +------->month (1 -12)
| | +--------->day of month
(1 -31)
| +----------->hour (0 -23)
+------------->minute (0 -59)
Crontab examples to automate shell
script which already have explain above..
00 1 * * * /data01/crontab_scripts/rmanbkp.sh #Run at 01:00 am every day
00 20 * * * /data01/crontab_scripts/rmanbkp.sh #Runs at 08:00 pm every day
00 1 * * 0 /data01/crontab_scripts/rmanbkp.sh #Runs at 1:00 am every Sunday
00 1 * * 7 <command> #Runs
at 1:00 am every Sunday
00 1 * * Sun <command>
#Runs at 1:00 am every Sunday
30 8 30,31 * * /data01/crontab_scripts/rmanbkp.sh #Runs at 8:30 am on the last day of every
month
30 22 01 01 * * /data01/crontab_scripts/rmanbkp.sh #Runs at 10:30 Pm on the 1st January
of every year.

10 comments:
Thanks for sharing this blog.
Oracle course in Chennai
Clearly well articulated..So does this script mean that it takes a full backup of the entire database everyday?
Exactly, The script will do the entire database (Datafile,Controlfile and Archive log.) backup including binary file(required for Cloning on test/dev server).
How to discover best arrangement? More often than not this inquiry comes in the brain of the purchaser. voodoodreams
Excellent Blog!!! Such an interesting blog with clear vision, this will definitely help for beginner to make them update.
RPA Training in Chennai
RPA Classes in Chennai
AWS Training in Chennai
Data Science Course in Chennai
Digital Marketing Course in Chennai
RPA Training in Anna Nagar
RPA Training in Adyar
Hi Sir, It is well explained but can you clarify me the source and destination? also can i have contact number. also i wanted to know how to take DB location backup from one DB server to Another DB server using shell script.
Well as i understand your concern , You just want to move DB backup from source to other destination. To do so you should prepare shell script as below.
#!/bin/ksh
destination=/backup/rmanPROD/`date +"%A"_"%d-%m-%y"_"%T"`
export destination
bkp=`date +"%A"`
cd $destination
ftp -n 192.168.11.25 << !EOF
user orabkp orabkppassword
prompt
bin
cd /backup/rmanPROD --- destination of another server.
mkdir $bkp
cd /backup/rmanPROD/$bkp
lcd $destination
mput *.tgz
mput DB*
mput ARCBAK*
mput C*
mput *.log
quit
!EOF
Destination Server:- 192.168.11.25 ---where you want to move backup
You have to mention Username and password of Destination Server. You can copy above script and make shell script and put the shell script in backup shell script file. Once backup will complete , This shell script will transfer your backup from source to destination on another server.
Thanks for this valuable information.
I just loved your article on the beginners guide to starting a blog.If somebody take this blog article seriously
in their life, he/she can earn his living by doing blogging.Thank you for this articl
Oracle DBA Training in Bangalore
Great post. Thanks for sharing.....
RPA Training in Bangalore
RPA Course in Bangalore
Post a Comment
Thanks for reading till end. I hope this will help you more to improve your knowledge.
Now it's your turn!
What do you think? Share your experience in the comments box and subscribe for more interesting post.