flags to avoid restart


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting flags to avoid restart
# 8  
Old 09-26-2012
OK. So, this message is suggesting updates to the code provided in the first message i this thread. The basic idea is to create a log file (Completed.YYYYMMDD) that contains a list of databases successfully backed up on the date specified by the filename extension and skip any database backup if that log file indicates that the database has already been backed up.
I also modified the commands to process $ORATAB to make it a little more efficient (calling awk once and sort once instead of calling grep three times, sort once, and uniq once).

Now for the changes. First, change:
Code:
export ORATAB=/etc/oratab

###START OF LOOP
for db in `egrep -i ":NBU" $ORATAB | grep -v "^#" | grep -v "\*" | cut -d":" -f1 | sort | uniq`
do
  echo "processing database: $db"

to:
Code:
export ORATAB=/etc/oratab

### Look for a list of databases successfully backed up today.  Create if it doesn't exist.
comp=$(date "+Completed.%Y%m%d")
if [ ! -f $comp ]
then    touch $comp
fi

###START OF LOOP
for db in $(awk -F: '$0 ~ /:[Nn][Bb][Uu]/ && $1 !~ /^#/ && $0 !~ /[*]/ {print $1}' $ORATAB | sort -u)
do
  echo "processing database: $db"
   if [ $(grep -c -e "^$db\$" $comp) -gt 0 ]
   then   printf "Skipping %s: It has already been backed up.\n" "$db"
          continue
   fi

and then change:
Code:
# ---------------------------------------------------------------------------
# Log the completion of this script.
# ---------------------------------------------------------------------------

  if [ "$RSTAT" = "0" ]
  then
    LOGMSG="Backup successfully $ORACLE_SID"
    echo $LOGMSG|mailx -s "BACKUP Status ..." abc@company.com
  else

to:
Code:
# ---------------------------------------------------------------------------
# Log the completion of this script.
# ---------------------------------------------------------------------------

  if [ "$RSTAT" = "0" ]
  then
    LOGMSG="Backup successfully $ORACLE_SID"
    echo $LOGMSG|mailx -s "BACKUP Status ..." abc@company.com
    echo $db >> $comp
  else

Crazy_max, how does this compare to what you came up with?
This User Gave Thanks to Don Cragun For This Post:
# 9  
Old 09-26-2012
Thanks Don.

I was trying for something too, but it did not work out...i did what you mentioned created touch entry for keeping track of successful DB(/tmp/checkifdbbackwassuccesful. and was trying something in term of this in my main for loop...

Code:
for db in `egrep -i ":NBU" $ORATAB | grep -v "^#" | grep -v "\*" | cut -d":" -f1 | sort | uniq`
do

########################################################
# Check to make sure previous backup was successful    #             
# if it was not, only backup that specific DB          # 
########################################################

if [ -f /tmp/checkifdbbackwassuccesful ]; then
   for success_db in `cat /oracle/tmp/testsuccess|grep $db`; do
if test $db = $success_db; then
 :
else
RUN MY BACKUP CMD
fi

but obviously that did not work.... and will still working on it

THANK YOU For you reply on this...couple of questions i have for you....

how would we deal with something like...let say my backup started at around 11pm today(it will touch/create a file called Completed.20120926) and my backup ended tomorrow around 2am....now that it is a different day and if i try to restart my backup job(if it failed) wouldn't it look for filed called Completed.20120927(sept 27/next day) and will obviously not find it and process all the DB again ?

Moderator's Comments:
Mod Comment edit by bakunin: you got it almost right: start with a [code]-tag, but end with a [/code]-tag (notice the "/").

Last edited by bakunin; 09-26-2012 at 11:17 PM..
# 10  
Old 09-26-2012
Yes. I was assuming that you'd start your backups a little after midnight and have all day to retry the backups if the log shows that one or more of the backups failed.

You could also make the name of your successful backup log file be an operand to your shell script and use $1 instead of setting $comp using the current date. (If you do this, you'll need to verify that an operand is present when you start the script. Or, you could use $1 to initialize the value of $comp instead of using the date command only when an operand is present. The concept still works, you just need to choose a filename for your log file that works for your situation.)
This User Gave Thanks to Don Cragun For This Post:
# 11  
Old 09-27-2012
Thanks Don, i am not able to understand what exactly do you mean when you say i can make the name of my successful backup log file be an operand to my shell script? Do you have an example of it for my situation ?

---------- Post updated at 10:22 AM ---------- Previous update was at 08:29 AM ----------

to avoid the day/date confusion...i modified it to be something like below...just creating a simple file

Code:
export comp=/oracle/completed_backup
if [ ! -f /oracle/completed_backup ]
then touch $comp
fi


then at the end i check to make sure ## of count i want backed up and # of count db backup was successful..if it match remove
file otherwise do nothing(so if restart the backup it know which one to backup)

Code:
######   end of loop #######
done

## Check to make sure oratab entry and sucessful backup match
## if it dose then remove the file that captures success entry($comp)

actual_db=`egrep -i ":NBU" $ORATAB | grep -v "^#" | grep -v "\*" | cut -d":" -f1 | sort | uniq|wc -l`
success_db=`cat /oracle/sqlutils/completed_backup|wc -l`

if [ $actual_db = $success_db ]; then
    rm /oracle/sqlutils/completed_backup
	else
	:  #DO NOTHING if value dose not match
	fi

exit $RSTAT

THANK YOU FOR YOUR HELP
# 12  
Old 09-27-2012
I was suggesting that you could change:
Code:
comp=$(date "+Completed.%Y%m%d")

in the first set of changes suggested in message sequence #8 in this thread to:
Code:
comp=${1:-$(date "+Completed.%Y%m%d")}

Then it will behave exactly as it did before if you invoke your backup shell script with no arguments. I don't know the name of your script, but for this discussion, suppose that it is called backupdbs. If you issued the command:
Code:
backupdbs

late last night, it would have created Completed.20120926 as the list of successfully completed backups. If you looked at the log files this morning and found that one or more backups failed, you could use the command:
Code:
backupdbs Completed.20120926

to use the list created last night instead of creating a new file for today (Completed.20120927).

In case someone is reading this doesn't understand the command:
Code:
comp=${1:-$(date "+Completed.%Y%m%d")}

It sets the the variable comp to $1 (the 1st argument to yoiur shell script) if that argument is set and is not an empty string; otherwise, it expands $(date "+Completed.%Y%m%d") and sets comp to that value (i.e., Completed.YYYYMMDD where YYYY is the current year, MM is the current two-digit month, and DD is the current two-digit day within the current month).

If you don't like my proposed naming convention for the list of successfully completed backups, change $(date "+Completed.%Y%m%d") to whatever you want. Or just make up a new name every day and always invoke your shell script with that name as its operand. (Just be sure that the name you choose doesn't contain any whitespace characters nor any characters that would be treated specially by your shell such as *, ?, $, etc.)
This User Gave Thanks to Don Cragun For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Ifconfig Flags

Hi there, I need your help in understanding the below Solaris 10 ifconfig output; athnetspns02>ifconfig -a lo0: flags=2001000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4,VIRTUAL> mtu 8232 index 1 inet 127.0.0.1 netmask ff000000 e1000g0:... (2 Replies)
Discussion started by: wthomas
2 Replies

2. UNIX for Dummies Questions & Answers

WHat are flags?

Can anybody actually tell, what is flag? I know they are termed as permission flags and various others. Please explain (3 Replies)
Discussion started by: nixhead
3 Replies

3. Shell Programming and Scripting

Need help to identify the flags by scripts.

Hi, I have two different scripts sap_ftp.sh and sap_ftp_dd.sh which are running continously in background. I am using another script called start.sh to launch these two scripts. Either one script will process files at a time . During that time other script will sleep.. Each script will... (1 Reply)
Discussion started by: bhargav20
1 Replies

4. IP Networking

arp output (flags)

I'm running an arp -an on a Solaris 10 box. We're using IPMP. One of the systems is not able to see a host on the same network. The only difference between the two systems (one is having a problem, the other isn't) at least so far is the output of arp: # arp -an | grep 224.55 e1000g5... (1 Reply)
Discussion started by: BOFH
1 Replies

5. UNIX for Dummies Questions & Answers

Question about Setting Flags

I have a script which will look for a test folder under the parent directory. If the folder contains test folder then create the same directory structure in other remote machine. Once the directories are created then transfer all the contents of that test folder. this is what i am doing :- ... (2 Replies)
Discussion started by: chris1234
2 Replies

6. UNIX for Advanced & Expert Users

Processes Communication Only with flags!

hello everybody and a happy new year! i am trying the client-server model...i have no problem with sockets etc... especially for server:there is a father who is listening for TCP connections from clients,the later send commands which parent shares to his children. then children execute... (1 Reply)
Discussion started by: vaggelakis
1 Replies

7. Shell Programming and Scripting

Making flags for my script

I have no idea how to make my own flags. (6 Replies)
Discussion started by: rcunn87
6 Replies

8. AIX

question concerning Grep flags

Hey all. I am trying to find a process that is running and appending it to a file. The comman I am using is ps -eaf |grep tctl. The problem is, it returns the tctl process as well as the grep process that I just ran. Is there a flag that will prevent the command from returning itself? ... (2 Replies)
Discussion started by: jalge2
2 Replies

9. Shell Programming and Scripting

makefile not taking -D flags

Hi, I found this strange behaviour while using one of the makefiles. Here is the snippet of the unix.mak that is necessary for this context SO = SvSocket.o SvStmt.o SvOdbcWrapper.o \ OdbcCallReader.o MgrCalls.o OdbcSvProxy.o \ OdbcSvApp.o... (4 Replies)
Discussion started by: vino
4 Replies

10. UNIX for Dummies Questions & Answers

if flags

Hi folks. I'm just starting to teach myself shell scripting and am having some trouble with an if statement. I am working with a directory where only one file will reside at a time and need to evaluate if this file is compressed to determine subsequent steps. I'm using echo for testing purposes.... (2 Replies)
Discussion started by: kristy
2 Replies
Login or Register to Ask a Question