pg dump.. issue with when using crontab

Started by Mohamedabout 16 years ago7 messagesgeneral
Jump to latest
#1Mohamed
mohamed5432154321@gmail.com

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

#2APseudoUtopia
apseudoutopia@gmail.com
In reply to: Mohamed (#1)
Re: pg dump.. issue with when using crontab

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.

#3Andreas Kretschmer
akretschmer@spamfence.net
In reply to: Mohamed (#1)
Re: pg dump.. issue with when using crontab

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�

#4Tom Lane
tgl@sss.pgh.pa.us
In reply to: Mohamed (#1)
Re: pg dump.. issue with when using crontab

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

#5Mohamed
mohamed5432154321@gmail.com
In reply to: Tom Lane (#4)
Re: 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:

Show quoted text

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

#6Steeles
steeles@gmail.com
In reply to: Mohamed (#5)
Re: pg dump.. issue with when using crontab

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

-----Original Message-----
From: Moe <mohamed5432154321@gmail.com>
Date: Tue, 26 Jan 2010 19:25:50
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:

Show quoted text

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

In reply to: Steeles (#6)
Re: pg dump.. issue with when using crontab

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