pg_basebackup exit codes

Started by John Donathover 6 years ago3 messagesgeneral
Jump to latest
#1John Donath
John.Donath@detron.nl

Hi,

I was unpleasantly surprised to see that pg_basebackup will return a zero (Success) exit code even when it has actually failed like below:

pg_basebackup: could not write to compressed file "/var/lib/pgsql/10/inst1/backup/cust-pg02_inst1_Fri_20190816/base.tar.gz": No space left on device
pg_basebackup: removing data directory "/var/lib/pgsql/10/inst1/backup/cust-pg02_inst1_Fri_20190816"

A reliable exit code is of great importance in backup scripts using a statement like below:

pg_basebackup -D ${backup_dest} -Ft -z 2>&1 | tee -a ${log_file}; rv=$?
[ $rv -eq 0 ] || error "pg_basebackup failed with rcode $rv; also see ${log_file}"

Pg_basebackup version: (PostgreSQL) 10.10

Anybody else encountering this problem?

Regards, John

#2Magnus Hagander
magnus@hagander.net
In reply to: John Donath (#1)
Re: pg_basebackup exit codes

On Mon, Aug 19, 2019 at 12:18 PM John Donath <John.Donath@detron.nl> wrote:

Hi,

I was unpleasantly surprised to see that pg_basebackup will return a zero
(Success) exit code even when it has actually failed like below:

pg_basebackup: could not write to compressed file
"/var/lib/pgsql/10/inst1/backup/cust-pg02_inst1_Fri_20190816/base.tar.gz":
No space left on device

pg_basebackup: removing data directory
"/var/lib/pgsql/10/inst1/backup/cust-pg02_inst1_Fri_20190816"

A reliable exit code is of great importance in backup scripts using a
statement like below:

pg_basebackup -D ${backup_dest} -Ft -z 2>&1 | tee -a ${log_file}; rv=$?

[ $rv -eq 0 ] || error "pg_basebackup failed with rcode $rv; also see
${log_file}"

Pg_basebackup version: (PostgreSQL) 10.10

Anybody else encountering this problem?

I think your problem is that you are looking at the exit code from "tee"
and not from pg_basebackup. If you are using bash, you can look at
something like $PIPESTATUS to get the exit code from the actual comman
dbefore the pipe. Or you can try removing the tee command to verify if this
is indeed where the problem is coming from.

--
Magnus Hagander
Me: https://www.hagander.net/ <http://www.hagander.net/&gt;
Work: https://www.redpill-linpro.com/ <http://www.redpill-linpro.com/&gt;

#3John Donath
John.Donath@detron.nl
In reply to: Magnus Hagander (#2)
RE: pg_basebackup exit codes

Thanks a lot Magnus!

I should have known better … ☺

But thanks for the PIPESTATUS hint which comes in uttermost handy

Regards, John

Van: Magnus Hagander <magnus@hagander.net>
Verzonden: maandag 19 augustus 2019 13:46
Aan: John Donath <John.Donath@detron.nl>
CC: pgsql-general@lists.postgresql.org
Onderwerp: Re: pg_basebackup exit codes

On Mon, Aug 19, 2019 at 12:18 PM John Donath <John.Donath@detron.nl<mailto:John.Donath@detron.nl>> wrote:
Hi,

I was unpleasantly surprised to see that pg_basebackup will return a zero (Success) exit code even when it has actually failed like below:

pg_basebackup: could not write to compressed file "/var/lib/pgsql/10/inst1/backup/cust-pg02_inst1_Fri_20190816/base.tar.gz": No space left on device
pg_basebackup: removing data directory "/var/lib/pgsql/10/inst1/backup/cust-pg02_inst1_Fri_20190816"

A reliable exit code is of great importance in backup scripts using a statement like below:

pg_basebackup -D ${backup_dest} -Ft -z 2>&1 | tee -a ${log_file}; rv=$?
[ $rv -eq 0 ] || error "pg_basebackup failed with rcode $rv; also see ${log_file}"

Pg_basebackup version: (PostgreSQL) 10.10

Anybody else encountering this problem?

I think your problem is that you are looking at the exit code from "tee" and not from pg_basebackup. If you are using bash, you can look at something like $PIPESTATUS to get the exit code from the actual comman dbefore the pipe. Or you can try removing the tee command to verify if this is indeed where the problem is coming from.

--
Magnus Hagander
Me: https://www.hagander.net/&lt;https://eur01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.hagander.net%2F&amp;data=02%7C01%7CJohn.Donath%40detron.nl%7C3ddf6b96e5cc4364586a08d7249ad514%7Cbbc691a314da4e9099e1065a3f4a8527%7C0%7C1%7C637018119725483795&amp;sdata=uPJd6SkXoZZb6I05rF9bjgTmBFGNrFu7O%2FegHUIUjOc%3D&amp;reserved=0&gt;
Work: https://www.redpill-linpro.com/&lt;https://eur01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.redpill-linpro.com%2F&amp;data=02%7C01%7CJohn.Donath%40detron.nl%7C3ddf6b96e5cc4364586a08d7249ad514%7Cbbc691a314da4e9099e1065a3f4a8527%7C0%7C1%7C637018119725483795&amp;sdata=vpL8fVODSBZBCjhKjUPWSYTPT2ZcjuF8PCpepXS0y0E%3D&amp;reserved=0&gt;