From 0aa328e350c4fcd43c5dc357d48183d8eea093f7 Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Tue, 1 Jun 2021 10:10:22 -0400 Subject: [PATCH] Add PostgreSQL to daily backup script --- .../templates/etc/cron.daily/pvc-backup.j2 | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/roles/base/templates/etc/cron.daily/pvc-backup.j2 b/roles/base/templates/etc/cron.daily/pvc-backup.j2 index 524011b..858e221 100755 --- a/roles/base/templates/etc/cron.daily/pvc-backup.j2 +++ b/roles/base/templates/etc/cron.daily/pvc-backup.j2 @@ -1,15 +1,22 @@ #!/bin/bash -# Backup the PVC Zookeeper database +# Backup the PVC databases # {{ ansible_managed }} set -o errexit BACKUP_DIR="/srv/backups/" -BACKUP_FILENAME_BASE="pvc-zookeeper-backup" DATE="$( date +%Y%m%d )" -BACKUP_FILENAME="${BACKUP_DIR}/${BACKUP_FILENAME_BASE}.${DATE}.json" +HOSTNAME="$( hostname -s )" -pvc -c local task backup > ${BACKUP_FILENAME} -xz ${BACKUP_FILENAME} -find ${BACKUP_DIR} -type f -name "${BACKUP_FILENAME_BASE}*" -mtime +7 -exec rm {} \; +ZK_BACKUP_FILENAME_BASE="pvc-zookeeper-backup" +ZK_BACKUP_FILENAME="${BACKUP_DIR}/${ZK_BACKUP_FILENAME_BASE}.${DATE}.json.xz" + +pvc -c local task backup | nice xz > ${ZK_BACKUP_FILENAME} +find ${BACKUP_DIR} -type f -name "${ZK_BACKUP_FILENAME_BASE}*" -mtime +7 -exec rm {} \; + +DB_BACKUP_FILENAME_BASE="pvc-postgresql-backup" +DB_BACKUP_FILENAME="${BACKUP_DIR}/${DB_BACKUP_FILENAME_BASE}.${DATE}.sql.xz" + +su postgres -c "pg_dumpall" | nice xz > ${DB_BACKUP_FILENAME} +find ${BACKUP_DIR} -type f -name "${DB_BACKUP_FILENAME_BASE}*" -mtime +7 -exec rm {} \;