pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
create schedule job
3+ messages / 3 participants
[nested] [flat]

* create schedule job
@ 2011-08-30 13:29  Karuna Karpe <karuna.karpe@os3infotech.com>
  0 siblings, 2 replies; 3+ messages in thread

From: Karuna Karpe @ 2011-08-30 13:29 UTC (permalink / raw)
  To: pgsql-admin

Hello,

I am create one job using pgAgent in postgres studio.  In that job i want to
backup whole database every day.  But when i check the backup location, then
there is no any backup file created. I create on script and I give this
script location in the definition tab of step window.  My script is
following :

#!/bin/bash
#backup directory can be file server share that the PgAgent daemon account
has access to
BACKUPDIR="/opt/dailybackup"
PGHOST="localhost"
PGUSER="enterprisedb"
PGBIN="/opt/PostgresPlus/9.0AS/bin"
thedate=$(date +%Y-%m-%d-%H)
themonth=$(date +%Y-%m)

#Create a full backup of the server database
$PGBIN/pg_dumpall -h $PGHOST -U $PGUSER | gzip >
$BACKUPDIR/fullbackup-$themonth.sql.gz

#put the names of the database you want to create an individual backup below
dbs=(edb bench_replication bench_parallel pgpool)

#iterate thru dbs in dbs array and backup each one
for db  in ${dbs[@]}
do
        $PGBIN/pg_dump -i -h $PGHOST -U $PGUSER -F c -b -v -f
$BACKUPDIR/$db-$thedate.compressed $db
done

But this is not create backup file.

So please give a solution for that.

Regards,
karuna karpe.

^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: create schedule job
@ 2011-08-30 13:38  Achilleas Mantzios <achill@matrix.gatewaynet.com>
  parent: Karuna Karpe <karuna.karpe@os3infotech.com>
  1 sibling, 0 replies; 3+ messages in thread

From: Achilleas Mantzios @ 2011-08-30 13:38 UTC (permalink / raw)
  To: pgsql-admin

1st run the script by hand  (maybe with -v) to see what is going wrong.
2nd use cron

Στις Tuesday 30 August 2011 16:29:32 ο/η Karuna Karpe έγραψε:
> Hello,
> 
> I am create one job using pgAgent in postgres studio.  In that job i want to
> backup whole database every day.  But when i check the backup location, then
> there is no any backup file created. I create on script and I give this
> script location in the definition tab of step window.  My script is
> following :
> 
> #!/bin/bash
> #backup directory can be file server share that the PgAgent daemon account
> has access to
> BACKUPDIR="/opt/dailybackup"
> PGHOST="localhost"
> PGUSER="enterprisedb"
> PGBIN="/opt/PostgresPlus/9.0AS/bin"
> thedate=$(date +%Y-%m-%d-%H)
> themonth=$(date +%Y-%m)
> 
> #Create a full backup of the server database
> $PGBIN/pg_dumpall -h $PGHOST -U $PGUSER | gzip >
> $BACKUPDIR/fullbackup-$themonth.sql.gz
> 
> #put the names of the database you want to create an individual backup below
> dbs=(edb bench_replication bench_parallel pgpool)
> 
> #iterate thru dbs in dbs array and backup each one
> for db  in ${dbs[@]}
> do
>         $PGBIN/pg_dump -i -h $PGHOST -U $PGUSER -F c -b -v -f
> $BACKUPDIR/$db-$thedate.compressed $db
> done
> 
> But this is not create backup file.
> 
> So please give a solution for that.
> 
> Regards,
> karuna karpe.
> 



-- 
Achilleas Mantzios



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: create schedule job
@ 2011-08-31 00:30  Craig Ringer <ringerc@ringerc.id.au>
  parent: Karuna Karpe <karuna.karpe@os3infotech.com>
  1 sibling, 0 replies; 3+ messages in thread

From: Craig Ringer @ 2011-08-31 00:30 UTC (permalink / raw)
  To: Karuna Karpe <karuna.karpe@os3infotech.com>; +Cc: pgsql-admin

On 30/08/2011 9:29 PM, Karuna Karpe wrote:
> Hello,
>
> I am create one job using pgAgent in postgres studio.  In that job i 
> want to backup whole database every day.  But when i check the backup 
> location, then there is no any backup file created.

Write permissions for PgAgent user to target location?

SELinux involvement?



Also, you seem to be doing both a pg_dumpall that backs up all the 
databases, and individual pg_dump runs for each database. Typically 
you'd do one or the other. If using individual database pg_dump, you 
usually use pg_dumpall with the "--globals-only" option to capture user 
definitions etc.



I recommend that you add error handling to your script. First, add

set -e -u

to the top, so the script treats undefined variables as errors and so 
that it aborts when commands fail. Then add error handling, eg:

$PGBIN/pg_dumpall -h $PGHOST -U $PGUSER | gzip > 
$BACKUPDIR/fullbackup-$themonth.sql.gz

becomes (eg)

if ! "$PGBIN/pg_dumpall" -h "$PGHOST" -U "$PGUSER" | gzip > 
"$BACKUPDIR/fullbackup-$themonth.sql.gz" ; then
   echo >2 "Failed to dump global data from database. Backup FAILED."
   exit 1
fi

Then make *SURE* that cron or pgagent or whatever check the exit status 
of your script and email you the contents of stderr when it fails. Do 
this by temporarily adding:

echo 2>"Manually aborting"
exit 1

to the top of your script and making sure that you get an error email 
containing "Manually aborting" when it is there.

Once that's done, you'll know that if something makes the backup fail, 
you will be notified and the message will contain the error output from 
the failed command.

--
Craig Ringer



^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2011-08-31 00:30 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2011-08-30 13:29 create schedule job Karuna Karpe <karuna.karpe@os3infotech.com>
2011-08-30 13:38 ` Achilleas Mantzios <achill@matrix.gatewaynet.com>
2011-08-31 00:30 ` Craig Ringer <ringerc@ringerc.id.au>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox