Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 579
  • Last Modified:

creating a unix script for dump job in Sybase

Hi ,I am creating a unix job in Sybase to dump the database at certain intervals. I would like ot have 3 copies  of the dump file on the server only at any given time and the job should only email  me if there is any error reported .
The job is as following :
#!/bin/ksh
export SYBASE=/home/sybase/ase1252
export SYBASE_OCS=OCS-12_5
export ISQL=${SYBASE}/${SYBASE_OCS}/bin/isql
export OUTDIR=/backups02/cust2
export USER=sa
export SRVR=sybase2
export PSWD=tables2

${ISQL} -U${USER} -S${SRVR}<<EOF
${PSWD}
dump database cust to '${OUTDIR}/sybase2.cust2.dmp'
go
EOF

Not good in scripting ,appreciate your help .
thanks,Gyans
0
gyans
Asked:
gyans
1 Solution
 
Joe WoodhousePrincipal ConsultantCommented:
That won't work because you'll overwrite the dump file each time if you use the same name. Most sites put the date & time into the filename to get around that.

I'm doing this away from a ksh so my syntax won't be 100%, but it will be enough to get you going.

Add:

DATE=$( date -u %Y%M%D%h%m)
DB="cust"

FILENAME="${SRVR}.${DB}.${DATE}.dmp"


and later:

dump database ${DB}
to "compress::${OUTDIR}/${FILENAME}"        -- usually faster and always takes less space with compression
go


and then finally something like:

ls -t ${OUTDIR}/${SRVR}.${DB}.* | head +3 | xargs rm

(Not every shell has the same "head" functionality - you want everything *but* the first three files when sorted by time.

This won't work if you stripe your backups, you'll need to be more clever there.
0
 
ahoffmannCommented:
> I would like ot have 3 copies
(reusing previous posted code)

DB=cust
SRVR=sybase2
OUTDIR=/backups02/cust2
FILENAME="${OUTDIR}/${SRVR}.${DB}.$(date +%Y%M%D%h%m%S).dmp"

${ISQL} -U${USER} -S${SRVR}<
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now