Shell Script Freeze and Unfreeze oracle db 8i,9i for begin/end backup(apply with backup agent)

** Myself
Freeze script
#########  DYNAMIC ENV ##############
orauser=oracle            #Oracle User
orasid=jde1                #Oracle SID
backcontrol_tmp=/tmp/backup_${orasid}controlfile.ctl        #Backup controlfile on temp directory
backcontrol_srg=/u01/back_ctl/backup_${orasid}controlfile.ctl    #Backup controlfile on storage
blog=/tmp/hot_ora_backup.log
#############################################################
###### Write information Backup to logfile ###
date >> $blog
echo "Start begin backup" >> $blog
###### Read information tablespace for freeze ###
su - ${orauser}   << BOF 2>&1
export ORACLE_SID=$orasid
sqlplus /nolog << EOF  >> $blog
connect internal
set head off
set feedback off
set trimspool on
set pagesize 0
set line 1000
spool switch.lst
select 'alter system switch logfile;' from v\\\$log;
spool off
!cat switch.lst |grep -v "SQL"|grep -v "AL" > switch.sql
spool tbs.lst
alter system checkpoint;
@switch.sql
---- Freeze All tablespace except Temp ---
select 'alter tablespace '||name||' begin backup;'  from v\\\$tablespace where name <> 'TEMP';
spool off
!cat tbs.lst | grep -v "SQL>" > tbs.sql
@tbs.sql
---- Backup controlfile ---
!echo "Backup controlfile to $backupdir/control_back.ctl" >> $blog
alter database backup controlfile to '$backcontrol_tmp' reuse;
!cp -p $backcontrol_tmp $backcontrol_srg
exit
EOF
rm tbs.lst tbs.sql switch.lst switch.sql 
BOF

Unfreeze script
#########  DYNAMIC ENV ##############
orauser=oracle        #Oracle User
orasid=jde1            #Oracle SID
blog=/tmp/hot_ora_backup.log
#############################################################
###### Write information Backup to logfile ###
date >> $blog
echo "Start end backup" >> $blog
###### Read information tablespace for Unfreeze ###
su - ${orauser}   << BOF 2>&1
export ORACLE_SID=$orasid
sqlplus /nolog << EOF  >> $blog
connect internal
spool tbs.lst
set head off
set feedback off
set trimspool on
set pagesize 0
set line 1000
---- Unfreeze All tablespace except Temp  ----
select 'alter tablespace '||name||' end backup;'  from v\\\$tablespace where name <> 'TEMP';
spool off
!cat tbs.lst | grep -v "SQL>" > tbs.sql
@tbs.sql
exit
EOF
rm tbs.lst tbs.sql
BOF
echo "Finish end backup" >> $blog

0 comments:

Loading