pvc-ansible/roles/pvc/templates/pvc/pvc-vacuum.j2

32 lines
1.0 KiB
Django/Jinja
Executable File

#!/bin/bash
# Daily vaccuum script for PVC daemons
# {{ ansible_managed }}
# This script cleans up the PostgreSQL databases as well as the Zookeeper
# database. This prevents filesystem growth balooning after loong running
# periods.
echo -e "----------------------------" &>>/var/log/pvc/vacuum.log
echo -e "$( date )" &>>/var/log/pvc/vacuum.log
echo -e "----------------------------" &>>/var/log/pvc/vacuum.log
#
# PostgreSQL
#
# Don't run if we aren't the Patroni primary
HOSTNAME="$( hostname -s )"
PRIMARY="$( patronictl -c /etc/patroni/config.yml -d zookeeper://localhost:2181 list --format json \
| jq -r '.[] | select(.Role == "Leader") | .Member' )"
if [[ $HOSTNAME == $PRIMARY ]]; then
# Analyze the database
su postgres -c 'vacuumdb --verbose --analyze --all' &>>/var/log/pvc/vacuum.log
fi
#
# Zookeeper
#
export ZOOCFG=/etc/zookeeper/conf/zoo.cfg
/usr/share/zookeeper/bin/zkCleanup.sh -n 7 &>>/var/log/pvc/vacuum.log