Add directory creation to backup script

This commit is contained in:
Joshua Boniface 2021-06-01 10:16:08 -04:00 committed by Joshua Boniface
parent 0aa328e350
commit 998e5a8752
1 changed files with 10 additions and 2 deletions

View File

@ -5,14 +5,20 @@
set -o errexit set -o errexit
BACKUP_DIR="/srv/backups/" BACKUP_DIR="/srv/backups"
DATE="$( date +%Y%m%d )" DATE="$( date +%Y%m%d )"
HOSTNAME="$( hostname -s )" HOSTNAME="$( hostname -s )"
if [[ ! -d ${BACKUP_DIR} ]]; then
mkdir -p ${BACKUP_DIR}
fi
pushd ${BACKUP_DIR} &>/dev/null
ZK_BACKUP_FILENAME_BASE="pvc-zookeeper-backup" ZK_BACKUP_FILENAME_BASE="pvc-zookeeper-backup"
ZK_BACKUP_FILENAME="${BACKUP_DIR}/${ZK_BACKUP_FILENAME_BASE}.${DATE}.json.xz" ZK_BACKUP_FILENAME="${BACKUP_DIR}/${ZK_BACKUP_FILENAME_BASE}.${DATE}.json.xz"
pvc -c local task backup | nice xz > ${ZK_BACKUP_FILENAME} pvc -q -c local task backup | nice xz > ${ZK_BACKUP_FILENAME}
find ${BACKUP_DIR} -type f -name "${ZK_BACKUP_FILENAME_BASE}*" -mtime +7 -exec rm {} \; find ${BACKUP_DIR} -type f -name "${ZK_BACKUP_FILENAME_BASE}*" -mtime +7 -exec rm {} \;
DB_BACKUP_FILENAME_BASE="pvc-postgresql-backup" DB_BACKUP_FILENAME_BASE="pvc-postgresql-backup"
@ -20,3 +26,5 @@ DB_BACKUP_FILENAME="${BACKUP_DIR}/${DB_BACKUP_FILENAME_BASE}.${DATE}.sql.xz"
su postgres -c "pg_dumpall" | nice xz > ${DB_BACKUP_FILENAME} su postgres -c "pg_dumpall" | nice xz > ${DB_BACKUP_FILENAME}
find ${BACKUP_DIR} -type f -name "${DB_BACKUP_FILENAME_BASE}*" -mtime +7 -exec rm {} \; find ${BACKUP_DIR} -type f -name "${DB_BACKUP_FILENAME_BASE}*" -mtime +7 -exec rm {} \;
popd &>/dev/null