ansible_drone/templates/pg_backup.sh.j2

17 lines
445 B
Plaintext
Raw Normal View History

2021-02-21 00:05:41 +01:00
#!/bin/bash
set -xeo pipefail
NOW=$(date +%Y-%m-%d_%H:%M:%S)
BACKUP_PATH="{{ backup_path }}/backup"
RESTORE_PATH="{{ backup_path }}/restore"
cd ${BACKUP_PATH}
docker exec postgres pg_dump -U drone -d drone -f /var/lib/pgbackup/backup_${NOW}.sql
LATEST_BACKUP=$(ls -1t *.sql | head -n1)
if [ "z${LATEST_BACKUP}" != "z" ]; then
cp "${BACKUP_PATH}/${LATEST_BACKUP}" "${RESTORE_PATH}/latest_backup.sql"
fi
# vim: set ft=sh et sw=0 ts=2 sts=0: