diff --git a/postgresql/templates/postgresql_wal_backup_and_removal.j2 b/postgresql/templates/postgresql_wal_backup_and_removal.j2 new file mode 100644 index 0000000..bdb4ae2 --- /dev/null +++ b/postgresql/templates/postgresql_wal_backup_and_removal.j2 @@ -0,0 +1,17 @@ +#!/bin/bash + +BASE_BACKUP_DIR=/var/lib/pgsql/base_backup +WAL_ARCHIVES_LOG_DIR=/var/lib/postgresql/9.5/archive_log +WAL_LATEST_BACKUP= + +# The base backup dir needs to be empty + +rm -f $BASE_BACKUP_DIR/* +pg_basebackup -F t -z -D /var/lib/pgsql/base_backup + +cd $WAL_ARCHIVES_LOG_DIR +WAL_LATEST_BACKUP=$( /bin/ls -1 *.backup | sort | tail -1 ) +pg_archivecleanup $WAL_ARCHIVES_LOG_DIR $WAL_LATEST_BACKUP + +exit $? + diff --git a/postgresql/templates/wal_archive_cleanup.j2 b/postgresql/templates/wal_archive_cleanup.j2 new file mode 100644 index 0000000..7679274 --- /dev/null +++ b/postgresql/templates/wal_archive_cleanup.j2 @@ -0,0 +1,6 @@ +#!/bin/bash + +su - postgres -c "/usr/local/sbin/postgresql_wal_backup_and_removal > /var/log/postgresql/wal_removal.log 2>&1" + +exit 0 +