diff --git a/files/backuppc_pg_wal.sh b/files/backuppc_pg_wal.sh new file mode 100755 index 0000000..ed29342 --- /dev/null +++ b/files/backuppc_pg_wal.sh @@ -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" + diff --git a/tasks/postgres_pgpool.yml b/tasks/postgres_pgpool.yml index 2957159..15889c4 100644 --- a/tasks/postgres_pgpool.yml +++ b/tasks/postgres_pgpool.yml @@ -117,6 +117,11 @@ - name: Install a script that cleans up the wal log archives template: src=postgresql_wal_backup_and_removal.j2 dest=/usr/local/sbin/postgresql_wal_backup_and_removal owner=root group=root mode=0755 + tags: [ 'postgres', 'postgresql', 'sudo', 'pgpool' ] + + - name: backuppc root script to syncronize backup and wal clean up + copy: src=backuppc_pg_wal.sh dest=/usr/local/sbin/backuppc_pg_wal.sh owner=root mode=0744 + tags: [ 'postgres_backuppc', 'postgres', 'postgresql', 'pgpool' ] # The script is started by the backup server after the file copy, crontab action must be deleted #- name: Install a cron job to cleanup the wal log archives diff --git a/templates/postgresql_wal_backup_and_removal.j2 b/templates/postgresql_wal_backup_and_removal.j2 old mode 100644 new mode 100755 index 22d6454..b85672b --- a/templates/postgresql_wal_backup_and_removal.j2 +++ b/templates/postgresql_wal_backup_and_removal.j2 @@ -1,5 +1,12 @@ #!/bin/bash +ISMASTER=`psql -t -c "SELECT pg_is_in_recovery();"` +if [ $ISMASTER != 'f' ] +then + echo "Not on master, nothing to do." + exit 0 +fi + BASE_BACKUP_DIR={{ psql_base_backup_dir }} WAL_ARCHIVES_LOG_DIR={{ psql_wal_archiving_log_dir }} WAL_LATEST_BACKUP= @@ -15,3 +22,4 @@ pg_archivecleanup $WAL_ARCHIVES_LOG_DIR $WAL_LATEST_BACKUP exit $? +