We're using named pipes with Sybase bcp so that we can compress output on-the-fly.
This is a paraphrase of the error handling idiom, some error checking in the non-bcp parts of the script has been removed to shorten the example.
while :
do
{
rm -f $fifo
mkfifo $fifo
cat $fifo &
CatPid=$!
bcp $db.$owner.$table out $fifo -c $db_creds >$log 2>&1
grep -qi deadlock $log || break
# Must have been a deadlock, clean up.
kill $CatPid
} > $output
done
Basically, if the word 'deadlock' appears in bcp output messages, we try again.
Two questions
- Does this approach look reasonable?
- What other bcp errors than deadlock might we need to worry about?
I'm specifically interested in handling of intermittent bcp errors - no need to worry about table not found, permissioning, credentials wrong, etc. - they shouldn't happen in this case. (Having said that, when a permissioning error did once come up with this code the fact that the error was not caught and reported caused much consternation.)
We use a compound statement so that we can insert headers and footers around the bcp data before the compression, but I've omitted that to simplify the example.