Oracle: Auto Backup
Auto Back up
- Create ‘filname.sh’ file with following code anywhere in server after amendments. (Possible amendments in RED.) e.g. filename is make_db.sh.
#!/bin/bash
#
#
dy=`date +%a`
hn=`hostname`
bk='/opt/back'
sb=$bk'/'$hn
#
#!/bin/bash
#
#
dy=`date +%a`
hn=`hostname`
bk='/opt/back'
sb=$bk'/'$hn
#
#
cm_d01='tar -Pczf '$sb'/'$hn'_'$dy'_d01.tar.gz /opt/d01'
cm_d02='tar -Pczf '$sb'/'$hn'_'$dy'_d02.tar.gz /opt/d02'
cm_d02_da='tar -Pczf '$sb'/'$hn'_'$dy'_d02_data.tar.gz /opt/d02/oracle/proddata'
#
#
dy1="Tue"
dy2="Wed"
dy3="Thu"
dy4="Fri"
dy5="Sat"
dy6="Sun"
dy7="Mon"
both_bk_on=$dy7
#
#
printf "\n"
if test -d /opt/d01 ; then
printf "Source Folder d01 Exist ............... OK\n"
if test -d /opt/d02 ; then
printf "Source Folder d02 Exist ............... Ok\n"
if test -d $bk ; then
printf "$bk Folder Exist ............... Ok\n"
else
printf "Going to create $bk Folder\n"
mkdir $bk
fi
if test -d $sb ; then
printf "$sb Sub Folder Exist ............... Ok\n"
else
printf "Going to create $sb $ub Folder\n"
mkdir $sb
fi
# ------------------------------------------------------------------
printf "Going to create tar file for d02 \n"
/home/oracle/down.sh
ls -l /opt/d02/oracle/proddata > $sb/list"_"$hn"_"$dy"_d02_b4.txt"
if test "$dy" = "$both_bk_on" ; then
$cm_d02
else
$cm_d02_da
fi
ls -l /opt/d02/oracle/proddata > $sb/list"_"$hn"_"$dy"_d02_aft.txt"
tar -tzvf $sb"/"$hn"_"$dy"_"d02.tar.gz > $sb"/list_"$hn"_"$dy"_d02_tar.txt"
if test "$dy" = "$both_bk_on" ; then
printf "Also going to create tar file for d01\n"
$cm_d01
fi
/home/oracle/up.sh
# ------------------------------------------------------------------
else
printf "Source Folder D02 Does Not Exist\n"
fi
else
printf "Source Folder d01 Does Not Exist\n"
fi
- Now we will edit CRONTAB utility according to our requirement. Crontab is just like a scheduler. (See basics of CRONTAB at the end.)
- Add this line in CRONTAB ‘00 21 * * * /opt/back/make_db.sh’
Manual Back up
This
document will guide you to take backup of single Tier R12. DB and Apps
combine. Incase you are working on multi node repeat the steps for DB
and Apps server separately.
Take Backup
- Go to the directory where you want to place the backup...e.g. /opt/back.
- Down services. (So that no further live entries should made and it will speedup the process)
- Now take the backup as followed.
tar -Pczf haseeb_oracle_04apr11.ar.gz /opt/haseeb_oracle/
(where
tar -Pczf are the keywords then target folder with backup file name and
then source folder with path(of which you want to take backup.))
- Backup done.
Place Backup
- Go to the path where you want to place the extracted file.(target folder) and run the following command
tar -xzf back/haseeb_oracle_04apr11.ar.gz
- This will place the your extracted files in that directory.
- Now move the files accordingly so that your directory structure remains the same.
In
my case when I extracted the files it creates the ‘opt’ folder in
existing ‘/opt’ folder (make sure there is hell off difference in '/opt'
and 'opt/'. In '/opt','/'itself is directory.)
While I need to retain the file structure like opt/oracle/.
So I will remove the existing 'oracle' directory from '/opt' and move the oracle directory from 'opt/' to '/opt'.
Now I’ll have the exact file structure what I need to have.
All done.
No comments:
Post a Comment