Put the backups on the FS so we can just back them up later on the same way

This commit is contained in:
Salt 2025-01-20 20:01:36 -06:00
parent 09bdb80712
commit e651396604

View File

@ -75,6 +75,9 @@ backup() {
# Dump Postgres DBs, if possible
if command -v psql > /dev/null 2>&1; then
# Put down a place for us to store backups, if we don't have it already
backupdir="/opt/postgres-backups"
mkdir -p "$backupdir"
# Populate a list of databases
declare -a DATABASES
while read line; do
@ -89,13 +92,11 @@ if command -v psql > /dev/null 2>&1; then
echo "Will upload resultant backups to {{ backup_s3_bucket }}"
for db in "${DATABASES[@]}"; do
echo "Backing up $db"
path="$backupdir/$db.pgsql.gz"
sudo -u postgres pg_dump "$db" \
| gzip -v9 \
| aws s3 cp - \
{% if backup_s3_aws_endpoint_url is defined %}
--endpoint-url="{{ backup_s3_aws_endpoint_url }}" \
{% endif %}
"s3://{{ backup_s3_bucket }}/$HOSTNAME/pgdump/$db/$(date "+{{ backup_dateformat }}").pgsql.gz"
| gzip -v9 >
"$path"
DIRS+=("$path")
done
fi