pg_archivecleanup standalone bash script

Started by Patrick Bover 9 years ago6 messagesgeneral
Jump to latest
#1Patrick B
patrickbakerbr@gmail.com

Hi all,

I want to hold the wal_files for 30 days on my slaves.
For that reason, I created a script to do that:

*pg_archivecleaup_mv.bash:*

#!/bin/bash -eu

declare -r -x PATH='/usr/local/bin:/usr/bin:/bin';

# We just wanna delete the wal_files older than 30 days

ARCHIVEDIR='/var/lib/pgsql/9.2/archive/'

CHKPOINT=$(find $ARCHIVEDIR -type f -mtime +30 -name '00*' -printf '%f\n' |
sort -r | head -1)

cd $ARCHIVEDIR

/usr/pgsql-${PG_VERSION}/bin/pg_archivecleanup $ARCHIVEDIR $CHKPOINT

find $ARCHIVEDIR -type f -mtime +30 -a -name '00*' -a ! -newer $CHKPOINT
-delete

*recovery.conf:*

archive_cleanup_command = 'exec nice -n 19 ionice -c 2 -n 7
../../bin/pg_archivecleaup_mv.bash -d /var/lib/pgsql/9.2/archive "%r"'

*PROBLEM:*

I'm getting an error message:

pg_archivecleanup: must specify restartfilename
Try "pg_archivecleanup --help" for more information.
archive_cleanup_command "exec nice -n 19 ionice -c 2 -n 7
../../bin/pg_archivecleaup_mv.bash -d "../archive" "%r"": return code 512

And I can't figure out what is wrong....

Please, do you guys can help?
Cheers;
Patrick

#2David G. Johnston
david.g.johnston@gmail.com
In reply to: Patrick B (#1)
Re: pg_archivecleanup standalone bash script

On Sun, Jul 31, 2016 at 6:11 PM, Patrick B <patrickbakerbr@gmail.com> wrote:

CHKPOINT=$(find $ARCHIVEDIR -type f -mtime +30 -name '00*' -printf '%f\n'
| sort -r | head -1)

/usr/pgsql-${PG_VERSION}/bin/pg_archivecleanup $ARCHIVEDIR $CHKPOINT

​While I'm a bit suspect of this entire script/approach I believe the
problem plaguing you at the moment is that your find command is not finding
any files and thus your attempt to execute pg_archivecleanup only occurs
with a single argument - which is an error.

For something this important I would advise considerably more debugging
output and explicit error handling. Don't rely on set -e

On a related note - I don't understand why you'd use the "exec" command
here...

David J.

#3Patrick B
patrickbakerbr@gmail.com
In reply to: David G. Johnston (#2)
Re: pg_archivecleanup standalone bash script

This has been resolved.

cheers

#4Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Patrick B (#3)
Re: pg_archivecleanup standalone bash script

Patrick B wrote:

This has been resolved.

How?

--
�lvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

#5Patrick B
patrickbakerbr@gmail.com
In reply to: Alvaro Herrera (#4)
Re: pg_archivecleanup standalone bash script

I'll ajust the script and once is done will share here with u guys

Patrick

#6Patrick B
patrickbakerbr@gmail.com
In reply to: Patrick B (#5)
Re: pg_archivecleanup standalone bash script

*recovery.conf:*

archive_cleanup_command = 'exec /var/lib/pgsql/bin/pg_archivecleaup_mv.bash'

*Final pg_archivecleanup script:*

#!/bin/bash
declare -r -x PATH='/usr/local/bin:/usr/bin:/bin';

ARCHIVEDIR='/var/lib/pgsql/archive'
LAST_BACKUP=$(ls -lto ${ARCHIVEDIR})

cd $ARCHIVEDIRexec "/usr/pgsql-9.2/bin/pg_archivecleanup" -d
/var/lib/pgsql/archive ${LAST_BACKUP} | find $ARCHIVEDIR -type f -mmin
+30 -delete

2016-08-03 8:32 GMT+12:00 Patrick B <patrickbakerbr@gmail.com>:

Show quoted text

I'll ajust the script and once is done will share here with u guys

Patrick