Thread: pg_dumpall in crontab doesn't work
I'm doing some backup action for my database using crontab. Unfortunately the following entry doesn't work and I can't figure out the problem: ----------------------------- /etc/crontab --------------------------- 05 22 * * 1-5 postgres /usr/bin/pg_dumpall -D > /disks/postgres/db.pg_dumpall ---------------------------------------------------------------------- The message I get is: ---------------------------- stderr ---------------------------------- connected to template1... /usr/bin/pg_dumpall: 0: Bad file descriptor ---------------------------------------------------------------------- The outputfile looks like: ----------------------- the output file ------------------------------ -- -- pg_dumpall (7.2) -D -- \connect template1 DELETE FROM pg_shadow WHERE usesysid <> (SELECT datdba FROM pg_database WHERE datname = 'template0'); CREATE USER "werner" WITH SYSID 100 CREATEDB CREATEUSER; CREATE USER "martin" WITH SYSID 101 NOCREATEDB NOCREATEUSER; CREATE USER "juergen" WITH SYSID 102 CREATEDB NOCREATEUSER; CREATE USER "www" WITH SYSID 103 NOCREATEDB NOCREATEUSER; CREATE USER "procad" WITH SYSID 99 NOCREATEDB NOCREATEUSER; DELETE FROM pg_group; ---------------------------------------------------------------------- That's all. No databases dumped. Calling pg_dumpall manually works fine. Whe is the problem? Any hints? - Werner -
> 05 22 * * 1-5 postgres /usr/bin/pg_dumpall -D > > /disks/postgres/db.pg_dumpall > connected to template1... > /usr/bin/pg_dumpall: 0: Bad file descriptor Filedescriptor 0 is STDIN. I would guess pg_dumpall want's to read something from stdin, pherhaps ask you a question? -- /Nils Höglund, Naqua KB E-mail: nils@naqua.se Web: http://www.naqua.se/ Home Phone: +46 (0)18 30 09 19 Cellular Phone: +46 (0)709 91 97 65 Address: Nya Valsätrav. 26 B SE-756 46 Uppsala, Sweden
Nils Höglund wrote: > >> 05 22 * * 1-5 postgres /usr/bin/pg_dumpall -D > >> /disks/postgres/db.pg_dumpall >> connected to template1... >> /usr/bin/pg_dumpall: 0: Bad file descriptor > > Filedescriptor 0 is STDIN. I would guess pg_dumpall want's to read something > from stdin, pherhaps ask you a question? > But it doesn't ask in interactive (shell) mode.
keep in mind that cronjobs don't get your login environment, so things that work in interactive mode often fail in cron unless you make sure to set up the environment there too. john guthrie -----Original Message----- From: Werner Modenbach [mailto:modenbach@alc.de] Sent: Tuesday, July 02, 2002 3:51 AM To: pgsql-admin@postgresql.org Subject: Re: [ADMIN] pg_dumpall in crontab doesn't work Nils Höglund wrote: > >> 05 22 * * 1-5 postgres /usr/bin/pg_dumpall -D > >> /disks/postgres/db.pg_dumpall >> connected to template1... >> /usr/bin/pg_dumpall: 0: Bad file descriptor > > Filedescriptor 0 is STDIN. I would guess pg_dumpall want's to read something > from stdin, pherhaps ask you a question? > But it doesn't ask in interactive (shell) mode. ---------------------------(end of broadcast)--------------------------- TIP 3: if posting/reading through Usenet, please send an appropriate subscribe-nomail command to majordomo@postgresql.org so that your message can get through to the mailing list cleanly
Werner Modenbach <modenbach@alc.de> writes: >> Filedescriptor 0 is STDIN. I would guess pg_dumpall want's to read >> something from stdin, pherhaps ask you a question? >> > But it doesn't ask in interactive (shell) mode. I was going to suggest that it's trying to read a password. Are you sure you don't have password authentication enabled? You might try adding < /dev/null to the cron entry. I would have thought that would be the default, but perhaps it isn't on your machine. regards, tom lane
Guthrie, John wrote: > keep in mind that cronjobs don't get your login environment, so things that > work in interactive mode often fail in cron unless you make sure to set up > the environment there too. > Thanks John, actually I didn't know that :-( In the meantime I added the "</dev/null" as proposed by Tom and it works fine now :-)) Seems like pg_dump needs it. Maybe this can be improved in future? - Werner -
Guthrie, John wrote: > keep in mind that cronjobs don't get your login environment, so things that > work in interactive mode often fail in cron unless you make sure to set up > the environment there too. That is very important to remember! First try adding "< /dev/null" to the command. If that doesn't work, you can also try adding ". $HOME/.profile ; " to the command. HTH, Kevin >>>05 22 * * 1-5 postgres /usr/bin/pg_dumpall -D > >>>/disks/postgres/db.pg_dumpall
Werner Modenbach wrote: > Guthrie, John wrote: > > > keep in mind that cronjobs don't get your login environment, so things > that > > work in interactive mode often fail in cron unless you make sure to set up > > the environment there too. > > > Thanks John, > > actually I didn't know that :-( > In the meantime I added the "</dev/null" as proposed by Tom and it works > fine now :-)) > Seems like pg_dump needs it. Maybe this can be improved in future? Is there a password involved in any of the databases? -- Bruce Momjian | http://candle.pha.pa.us pgman@candle.pha.pa.us | (610) 853-3000 + If your life is a hard drive, | 830 Blythe Avenue + Christ can be your backup. | Drexel Hill, Pennsylvania 19026