Add PostgreSQL to daily backup script

This commit is contained in:
Joshua Boniface 2023-09-01 15:42:25 -04:00
parent c9742fe2e5
commit 5466df7065
1 changed files with 13 additions and 6 deletions

View File

@ -1,15 +1,22 @@
#!/bin/bash #!/bin/bash
# Backup the PVC Zookeeper database # Backup the PVC databases
# {{ ansible_managed }} # {{ ansible_managed }}
set -o errexit set -o errexit
BACKUP_DIR="/srv/backups/" BACKUP_DIR="/srv/backups/"
BACKUP_FILENAME_BASE="pvc-zookeeper-backup"
DATE="$( date +%Y%m%d )" DATE="$( date +%Y%m%d )"
BACKUP_FILENAME="${BACKUP_DIR}/${BACKUP_FILENAME_BASE}.${DATE}.json" HOSTNAME="$( hostname -s )"
pvc -c local task backup > ${BACKUP_FILENAME} ZK_BACKUP_FILENAME_BASE="pvc-zookeeper-backup"
xz ${BACKUP_FILENAME} ZK_BACKUP_FILENAME="${BACKUP_DIR}/${ZK_BACKUP_FILENAME_BASE}.${DATE}.json.xz"
find ${BACKUP_DIR} -type f -name "${BACKUP_FILENAME_BASE}*" -mtime +7 -exec rm {} \;
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 {} \;