Operating System - HP-UX
1748232 Members
3865 Online
108759 Solutions
New Discussion юеВ

Re: Can I set a timeout to cp?

 
SOLVED
Go to solution
Eric Antunes
Honored Contributor

Re: Can I set a timeout to cp?

Ok,

Now I get:

"A ] character is missing"

Any clue??

Eric
Each and every day is a good day to learn.
RAC_1
Honored Contributor

Re: Can I set a timeout to cp?

I would try to address it in different way. Before you shutdown the database, why not check for NFS mount, nfs server and do a test copy?? If that is OK, you shutdown database and start copy.

Now depending upon the size of the data to be copied you can also put a wait time for cp to comlpete. If it does not, kill cp and start database.

One catch here is to take into consideration the load on system/network load that will impact the copy time. And hence copy wait time needs to be adjusted.

To address this you can have another script/check in same script to keep comparing the source data and copied data.

Anil
There is no substitute to HARDWORK
Eric Antunes
Honored Contributor

Re: Can I set a timeout to cp?

RAC,

Seems an excelent idea. With "ping -vr -n 5" for example but how do I put this testing into a script??

Eric

Each and every day is a good day to learn.
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: Can I set a timeout to cp?

Let me suggest a much more elegant Plan C and you won't need to worry about no stinkin' timeouts.

1) Shutdown database
2) Create a vxfs snapshot of all your Oracle filesystems -- this will take only seconds
3) Restart your database
4) NFS exportfs your vxfs snapshots (read-only)
5) NFS Mount (read only) your snapshots on the client
6) Do the copies
7) NFS unmount the snapshots on the client
8) exports -i -u /yoursnapshot(s)
9) umount the snapshots

And yes, vxfs snapshot filesystems can be exported.

This will give you almost all the uptime of a hot backup with all the security of a cold backup. And in fact, now that time is of no consequence, you could backup to tape instead.
If it ain't broke, I can fix that.
A. Clay Stephenson
Acclaimed Contributor

Re: Can I set a timeout to cp?

If you still want a way to timeout a cp command although snapshots are really the better solution, the best approach is Perl because the way it handles timeouts is exactly the way it's done in C. The attached Perl script (timeoutcp.pl) was quickly adapted from a very similar script.

Use it like this:

timeoutcp.pl -t 5400 file1 file2 file3 /mydestdir/xxx/
STAT=${?}
if [[ ${STAT} -ne 0 ]]
then
echo "Cp failed; status ${STAT}" >&2
fi

Invoke as timeoutcp.pl -u for usage; it does a cp -p but you can alter the system() call to do whatever you like.
If it ain't broke, I can fix that.
Sandman!
Honored Contributor

Re: Can I set a timeout to cp?

Eric,

made modifications to the test script so that it first pings the NFS server && if it's up kicks off the copy. Taking this approach the script aborts when either the cp succeeds or the timeout value is exceeded.

============================================
wait_time=30
timeout=300
timer=0

srcdir=/disc1/patches
destdir=//patches

while true
do
ping && cp -R $srcdir/* $destdir
RC=$?
let timer=$timer + $wait_time
if [[ $RC -eq 0 || $timer -ge $timeout ]]
then
echo "\WARNING: ...!\n"
break
fi
sleep $wait_time
done
============================================

regards
David P. Goodsell
New Member

Re: Can I set a timeout to cp?

>while [ $exit_code -eq 1]
>Now I get:
> "A ] character is missing"

you need to put a space between the "1" an "]"

while [ $exit_code -eq 1 ]

hth
bv
"The lyf so short, the craft so long to lerne." - Chaucer
Bob_Vance
Esteemed Contributor

Re: Can I set a timeout to cp?

Ooops, I was logged in as wrong user (David G.)

bv
"The lyf so short, the craft so long to lerne." - Chaucer
Eric Antunes
Honored Contributor

Re: Can I set a timeout to cp?

Thanks for all replies.

Clay,

I'm very interested in your snapshots solution but how can I do it?

"Create a vxfs snapshot of all your Oracle filesystems -- this will take only seconds" -> How can I do this??

Also thanks for your perl script. I'll try to understand it to see what is the better script for me...

Bob,

I've assigned point to your 2├В┬║ login, thanks because that error is solved.

Now, I get another:

"sh[54]: test: Specify a parameter with this command."

Sandman,

I'll also analyse you script and assign you points accordingly.

Best Regards,

Eric Antun
Each and every day is a good day to learn.
Stephen Keane
Honored Contributor

Re: Can I set a timeout to cp?

If this is your line 54 ...

if [$TIMER ge $TIMEOUT]; then


then you need spaces wither side of the [ and ] and ge should be -ge etc

so it should read

if [ "$TIMER" -ge "$TIMEOUT" ] ; then