Operating System - HP-UX
1824993 Members
2097 Online
109678 Solutions
New Discussion юеВ

Re: weekly backups of db exports - Scripting question

 
SOLVED
Go to solution
rmueller58
Valued Contributor

weekly backups of db exports - Scripting question

All,

Have a question to pose to the group, On a nightly basis my informix creates exports of our databases,

for each night there is 17 files, One night a week I want to create a CYA tape of the prior week's exports.

the Format of the file name is
`date +%Y%m%d`.tar.gz

I am wanting to create a backup scheme to roll these files out on a weekly basis to one weekly tape for the entire full week.

I want to build a test file using the ls command for STDIN to use in my `cat week##.log`
mt -f /dev/rmt/0m rew
tar -cvf /dev/rmt/0m `cat /restore/logs/week42.log` 2>&1 > /restore/4mmdat.log

I was assuming week## = `date +%W`,

and week## - 1 ( would be defined as
expr `date +%W` -1


mt -f /dev/rmt/0m rew
tar -cvf /dev/rmt/0m `cat /restore/logs/week42.log` 2>&1 > /restore/4mmdat.log

How would you do this scenario and make it fly. I am currently (manually) creating the "week##.log" files, I would like to parse and check "date +%Y%m%d` against "expr `date +%W` -1

So essential I need a process where I can build the "week##.log" the rest is fairly straight forward..

Any insight and suggestions appreciated as always.

Rex Mueller - Ed Svrc Unit #3
7 REPLIES 7
Ivan Ferreira
Honored Contributor

Re: weekly backups of db exports - Scripting question

Maybe my English is not good enough, but, why don't you just use the find -mtime +7 to find the files and save them to the tape?
Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?
rmueller58
Valued Contributor

Re: weekly backups of db exports - Scripting question

Ivan I've not thought about the find command.. I will see what it looks like.
Mel Burslan
Honored Contributor
Solution

Re: weekly backups of db exports - Scripting question

If I am understanding your question correctly, simply putting it, you want to have a mechanism to build the file called week##.log. Is that right ? Assuming it is...

(1)
I am under the impression that, you are going to run this out of cron once a week on the same day, and lets assume this day is Sunday.

Also I will assume the dB exports gets generated everyday including the weekends but your job will run after the exports complete for Sunday.

I think all you need to do is set what today's date is, as in :

TODAY=`date %Y%m%d` # this is Sunday

then use Clay's date hammer which can be obtained from:

http://mirrors.develooper.com/hpux/
(scroll to the bottom of the page for Date Hammer links)

Using this utility, figure out what the dates for Monday thru Saturday were, with respect to the $TODAY variable. Then the rest is pretty easy in my opinion.

LOGFILE=week$(date +%W).log
for day in $TODAY $SAT $FRI $THU $WED $TUE $MON
do
for dbname in $DBNAMES #set DBNAMES string prior to this point
do
echo ${day}${dbname}.tar.gz >> $LOGFILE
done
done


then use this as STDIN for your two-liner.

HTH
________________________________
UNIX because I majored in cryptology...
rmueller58
Valued Contributor

Re: weekly backups of db exports - Scripting question

Mel, that is about right.

I want to build a file either daily or one a cutoff day once a week, that I can use STDIN retaining the logfile as a catalog, whether it is with -mtime in a find string or ls..

currently my manual process is to create the log file, then read the file into a script.

I want to read into the script based on "CURRENT_WEEK" - 1 where log would be for
week42 reading the week41 log.

Say I cron the job on Sunday AM at 0600.

I've been playing with the date stuff, but my brain isn't working too well for a Friday. in addition to the normal distractions.
rmueller58
Valued Contributor

Re: weekly backups of db exports - Scripting question

Mel,

I get a bunch of errors when I try to run the script on my UX system..

I think I am going to the following:

export wk=`date +%W`
export W=week"$wk"

tar -cvf /dev/rmt/0m `find /snapfileserver -name '*.tar.gz' -mtime -7 -print` 2
>&1 > /restore/"$W"dat.log
Mel Burslan
Honored Contributor

Re: weekly backups of db exports - Scripting question

maybe I should have clarified myself about the use of caljd script for your purpose. (the one I use is the shell version as my perl seems to vary wildy between servers and for my purpose shell version is okay)

#place the caljd.sh script in a directory in the search path.
#mine is in /usr/contrib/bin
#
TODAY=$(caljd.sh)
(( DAY1=${TODAY}-1 ))
(( DAY2=${TODAY}-2 ))
(( DAY3=${TODAY}-3 ))
(( DAY4=${TODAY}-4 ))
(( DAY5=${TODAY}-5 ))
(( DAY6=${TODAY}-6 ))

DBNAMES="PERSONNEL SALES ACCOUNTS" # example for testing
LOGFILE=week$(date +%W).log
# if you are running the week's worth of files
# on Sunday, you are still in that calendar week
# as far as date command is concerned

for day in $TODAY $DAY1 $DAY2 $DAY3 $DAY4 $DAY5 $DAY6
do
td=`caljd.sh $day`
dayf=`echo $td|awk {'print $3'}``echo $td|awk {'print $1'}``echo $td|awk {'print $2'}`

for dbname in $DBNAMES
do
echo ${dayf}${dbname}.tar.gz >> $LOGFILE
done
done


The output I get from this right now is below:

# cat week42.log
20051021PERSONNEL.tar.gz
20051021SALES.tar.gz
20051021ACCOUNTS.tar.gz
20051020PERSONNEL.tar.gz
20051020SALES.tar.gz
20051020ACCOUNTS.tar.gz
20051019PERSONNEL.tar.gz
20051019SALES.tar.gz
20051019ACCOUNTS.tar.gz
20051018PERSONNEL.tar.gz
20051018SALES.tar.gz
20051018ACCOUNTS.tar.gz
20051017PERSONNEL.tar.gz
20051017SALES.tar.gz
20051017ACCOUNTS.tar.gz
20051016PERSONNEL.tar.gz
20051016SALES.tar.gz
20051016ACCOUNTS.tar.gz
20051015PERSONNEL.tar.gz
20051015SALES.tar.gz
20051015ACCOUNTS.tar.gz


HTH
________________________________
UNIX because I majored in cryptology...
rmueller58
Valued Contributor

Re: weekly backups of db exports - Scripting question

thanks all, points assigned..