Thread: pg dump.. issue with when using crontab

pg dump.. issue with when using crontab

From
Moe
Date:
Hi folks,

I have a simple script file db :
#!/bin/bash
pg_dump -U postgres prodDB > /var/a/db/$(date "+%Y-%m-%d_%H:%M")-prodDB.dump

----------
Which works fine when executed manually ( ./db ).. I get a dump file which is around 1.9 MB


I run this script from the crontab schedueler (crontab -e) :

# m h  dom mon dow   command
33 04 * * * /var/a/scripts/db

Which appears to executing the script file, but what I get is zero sized dump files.
So perhaps it is some use access that is limiting crontab, making it not run as root.

How can I fix this to work with crontab ? I am thinking that I should change :
pg_dump -U postgres prodDB > /var/a/db/$(date "+%Y-%m-%d_%H:%M")-prodDB.dump

Thank you in advance / Moe

Re: pg dump.. issue with when using crontab

From
APseudoUtopia
Date:
On Tue, Jan 26, 2010 at 11:54 AM, Moe <mohamed5432154321@gmail.com> wrote:
> Hi folks,
>
> I have a simple script file db :
> #!/bin/bash
> pg_dump -U postgres prodDB > /var/a/db/$(date "+%Y-%m-%d_%H:%M")-prodDB.dump
>
> ----------
> Which works fine when executed manually ( ./db ).. I get a dump file which
> is around 1.9 MB
>
>
> I run this script from the crontab schedueler (crontab -e) :
>
> # m h  dom mon dow   command
> 33 04 * * * /var/a/scripts/db
>
> Which appears to executing the script file, but what I get is zero sized
> dump files.
> So perhaps it is some use access that is limiting crontab, making it not run
> as root.
>
> How can I fix this to work with crontab ? I am thinking that I should change
> :
> pg_dump -U postgres prodDB > /var/a/db/$(date "+%Y-%m-%d_%H:%M")-prodDB.dump
>
> Thank you in advance / Moe
>

Inside your script, try giving the full path to pg_dump. Cron
generally resets your $PATH.

Re: pg dump.. issue with when using crontab

From
Andreas Kretschmer
Date:
Moe <mohamed5432154321@gmail.com> wrote:

> Hi folks,
>
> I have a simple script file db :
> #!/bin/bash
> pg_dump -U postgres prodDB > /var/a/db/$(date "+%Y-%m-%d_%H:%M")-prodDB.dump
>
> ----------
> Which works fine when executed manually ( ./db ).. I get a dump file which is
> around 1.9 MB
>
>
> I run this script from the crontab schedueler (crontab -e) :
>
> # m h  dom mon dow   command
> 33 04 * * * /var/a/scripts/db
>
> Which appears to executing the script file, but what I get is zero sized dump
> files.
> So perhaps it is some use access that is limiting crontab, making it not run as
> root.
>
> How can I fix this to work with crontab ? I am thinking that I should change :
> pg_dump -U postgres prodDB > /var/a/db/$(date "+%Y-%m-%d_%H:%M")-prodDB.dump

Add the complete path to pg_dump, if it runs under cron it has not your
environment and not the PATH -> pg_dump was not found.


Andreas
--
Really, I'm not out to destroy Microsoft. That will just be a completely
unintentional side effect.                              (Linus Torvalds)
"If I was god, I would recompile penguin with --enable-fly."   (unknown)
Kaufbach, Saxony, Germany, Europe.              N 51.05082°, E 13.56889°

Re: pg dump.. issue with when using crontab

From
Tom Lane
Date:
Moe <mohamed5432154321@gmail.com> writes:
> I have a simple script file db :
> #!/bin/bash
> pg_dump -U postgres prodDB > /var/a/db/$(date "+%Y-%m-%d_%H:%M")-prodDB.dump

> Which works fine when executed manually ( ./db ).. I get a dump file which
> is around 1.9 MB

> I run this script from the crontab schedueler (crontab -e) :

> # m h  dom mon dow   command
> 33 04 * * * /var/a/scripts/db

> Which appears to executing the script file, but what I get is zero sized
> dump files.

cron jobs typically run with a very minimal PATH.  I'll bet pg_dump
isn't in it.  Try putting the full path to pg_dump in the script.

Also consider sending its stderr someplace more useful than /dev/null,
so that you're not flying blind while debugging problems ...

            regards, tom lane

Re: pg dump.. issue with when using crontab

From
Moe
Date:
Thank you both, that did the trick.

Sincerely / Moe

On Tue, Jan 26, 2010 at 7:14 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
Moe <mohamed5432154321@gmail.com> writes:
> I have a simple script file db :
> #!/bin/bash
> pg_dump -U postgres prodDB > /var/a/db/$(date "+%Y-%m-%d_%H:%M")-prodDB.dump

> Which works fine when executed manually ( ./db ).. I get a dump file which
> is around 1.9 MB

> I run this script from the crontab schedueler (crontab -e) :

> # m h  dom mon dow   command
> 33 04 * * * /var/a/scripts/db

> Which appears to executing the script file, but what I get is zero sized
> dump files.

cron jobs typically run with a very minimal PATH.  I'll bet pg_dump
isn't in it.  Try putting the full path to pg_dump in the script.

Also consider sending its stderr someplace more useful than /dev/null,
so that you're not flying blind while debugging problems ...

                       regards, tom lane

Re: pg dump.. issue with when using crontab

From
steeles@gmail.com
Date:
I am new to posgres.
By running Pg-dump like this, do we need to type in pwd for login manually?

Thanks

Sent from my BlackBerry device on the Rogers Wireless Network


From: Moe <mohamed5432154321@gmail.com>
Date: Tue, 26 Jan 2010 19:25:50 +0200
To: <pgsql-general@postgresql.org>
Subject: Re: [GENERAL] pg dump.. issue with when using crontab

Thank you both, that did the trick.

Sincerely / Moe

On Tue, Jan 26, 2010 at 7:14 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
Moe <mohamed5432154321@gmail.com> writes:
> I have a simple script file db :
> #!/bin/bash
> pg_dump -U postgres prodDB > /var/a/db/$(date "+%Y-%m-%d_%H:%M")-prodDB.dump

> Which works fine when executed manually ( ./db ).. I get a dump file which
> is around 1.9 MB

> I run this script from the crontab schedueler (crontab -e) :

> # m h  dom mon dow   command
> 33 04 * * * /var/a/scripts/db

> Which appears to executing the script file, but what I get is zero sized
> dump files.

cron jobs typically run with a very minimal PATH.  I'll bet pg_dump
isn't in it.  Try putting the full path to pg_dump in the script.

Also consider sending its stderr someplace more useful than /dev/null,
so that you're not flying blind while debugging problems ...

                       regards, tom lane

Re: pg dump.. issue with when using crontab

From
Raymond O'Donnell
Date:
On 26/01/2010 22:28, steeles@gmail.com wrote:
> I am new to posgres.
> By running Pg-dump like this, do we need to type in pwd for login manually?

It depends on what access rules are defined in the pg_hba.conf file.
Read about it here:

  http://www.postgresql.org/docs/8.4/interactive/auth-pg-hba-conf.html

Ray.

--
Raymond O'Donnell :: Galway :: Ireland
rod@iol.ie