I want to keep my wal_files
for 30 days, using the pg_archivecleanup.
I've followed these scripts:
https://stackoverflow.com/questions/31346606/postgresql-automatic-archive-purge-not-occuring
and
#!/bin/bash
ARCHIVEDIR='/var/lib/pgsql/wal_archive'
CHECKPOINT=$(find $ARCHIVEDIR -type f -mtime +30 -type f -printf '%f\n' | sort -r | head -1)
cd $ARCHIVEDIR
/usr/bin/pg_archivecleanup $ARCHIVEDIR $CHECKPOINT
find $ARCHIVEDIR -type f -mtime +30 -a -type f -a ! -newer $CHECKPOINT -delete
... but it's not working for me.
I'm getting this error:
pg_archivecleanup: invalid filename input
Try "pg_archivecleanup --help" for more information.
find: `-delete': No such file or directory
my recovery.conf:
archive_cleanup_command = 'pg_archivecleaup_mv.bash -d'
Is there any way to make this work?
UPDATE 1:
I've done some tests...
recovery.conf:
archive_cleanup_command = 'pg_archivecleaup_mv.bash'
pg_archivecleaup_mv.bash:
declare -r -x PATH='/usr/local/bin:/usr/bin:/bin';
ARCHIVEDIR='/var/lib/pgsql/wal_archive'
CHECKPOINT=$(find $ARCHIVEDIR -type f -mmin +3 -type f -printf '%f\n' | sort -r | head -1)
cd $ARCHIVEDIR
exec "pg_archivecleanup" "$ARCHIVEDIR" "$CHECKPOINT" "%r";
find $ARCHIVEDIR -type f -mmin +3 -a -type f -a ! -newer $CHECKPOINT -delete
-mmin +3
for testing purpose...
By doing that, the error changes:
pg_archivecleanup: too many parameters
Try "pg_archivecleanup --help" for more information.
archive_cleanup_command "/var/lib/pgsql/bin/pg_archivecleaup_mv.bash": return code 512
UPDATE 2: Following @Sebastian Webber idea, I changed the pg_archivecleaup_mv.bash
script; I'm getting the same issue that I had using the script I wrote:
#!/bin/bash -x
ARCHIVEDIR='/var/lib/pgsql/wal_archive'
LAST_BACKUP=$(ls -lto ${ARCHIVEDIR})
FILE_LIST=$(/usr/pgsql-9.2/bin/pg_archivecleanup -n "${ARCHIVEDIR}" "${LAST_BACKUP}")
## TEST FIRST
/usr/pgsql-9.2/bin/pg_archivecleanup -n "${ARCHIVEDIR}" "${LAST_BACKUP}" | find -type f -mmin +30 | xargs ls -lh
##THEN UNCOMMENT THIS LINE
#/usr/pgsql-9.2/bin/pg_archivecleanup -n "${ARCHIVEDIR}" "${LAST_BACKUP}" | find -type f -mmin +30 -delete
recovery.conf:
archive_cleanup_command = 'exec /var/lib/pgsql/bin/pg_archivecleaup_mv.bash -d "%r"'
With or without the
"%r"
I get the error:pg_archivecleanup: invalid filename input
Without the
"%r"
, I put the %r into the script:/usr/pgsql-9.2/bin/pg_archivecleanup -n "${ARCHIVEDIR}" "${LAST_BACKUP}" "%r"| find -type f -mmin +30 | xargs ls -lh
- Then I get the error:pg_archivecleanup: too many parameters