backup and clean of wal files

This commit is contained in:
Tommaso Piccioli 2021-09-16 23:54:17 +02:00
parent 8af951180e
commit 7f799023d9
3 changed files with 31 additions and 0 deletions

4
files/backuppc_pg_wal.sh Executable file
View File

@ -0,0 +1,4 @@
#!/bin/bash
su - postgres -c "/usr/local/sbin/postgresql_wal_backup_and_removal > /var/log/postgresql/wal_removal.log 2>&1"

View File

@ -43,6 +43,15 @@
when: psql_wal_files_archiving_enabled
tags: [ 'pg_backup', 'postgresql', 'postgres' ]
- name: Backup script for the postgresql streaming replication database(s)
template: src=postgresql_wal_backup_and_removal.j2 dest=/usr/local/sbin/postgresql_wal_backup_and_removal owner=root mode=0744
tags: [ 'pg_stream_backup', 'postgresql', 'postgres' ]
- name: backuppc root script for the postgresql streaming replication database(s)
copy: src=backuppc_pg_wal.sh dest=/usr/local/sbin/backuppc_pg_wal.sh owner=root mode=0744
when: psql_wal_files_archiving_enabled
tags: [ 'pg_stream_backup', 'postgresql', 'postgres' ]
- name: authorization file for the psql command
template: src=pgpass.j2 dest={{ pg_backup_pass_file }} owner=root mode=0600
tags: [ 'pg_backup', 'postgresql', 'postgres', 'pgpass', 'pg_db' ]

View File

@ -0,0 +1,18 @@
#!/bin/bash
BASE_BACKUP_DIR={{ psql_base_backup_dir }}
WAL_ARCHIVES_LOG_DIR={{ psql_wal_archiving_log_dir }}
WAL_LATEST_BACKUP=
# The base backup dir needs to be empty
rm -f $BASE_BACKUP_DIR/*
pg_basebackup -F t -z -D $BASE_BACKUP_DIR
cd $WAL_ARCHIVES_LOG_DIR
WAL_LATEST_BACKUP=$( /bin/ls -1tr *.backup | tail -1 )
pg_archivecleanup $WAL_ARCHIVES_LOG_DIR $WAL_LATEST_BACKUP
exit $?