mirror of
https://codeberg.org/polyteknisk-radiogruppe/the_prg_server_configuration.git
synced 2026-06-14 02:38:58 +02:00
Implented Google Cloud Backups of the databases, and also encrypying them before being pushed to cloud. Let us hope that I didn't heck it up.
This commit is contained in:
parent
458d0d865a
commit
20e27f799c
7 changed files with 193 additions and 7 deletions
|
|
@ -0,0 +1,24 @@
|
|||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
TIMESTAMP=$(date +%Y%m%d%H%M%S)
|
||||
BACKUP_DIR=$(mktemp -d)
|
||||
trap 'rm -rf "$BACKUP_DIR"' EXIT
|
||||
|
||||
# Import GPG key for encryption
|
||||
gpg --batch --import "${GPG_KEY_FILE}"
|
||||
|
||||
DATABASES=$(psql -U postgres -t -c "SELECT datname FROM pg_database WHERE datistemplate = false AND datname != 'postgres';" | grep -v '^$')
|
||||
|
||||
for DB in $DATABASES; do
|
||||
DB=$(echo "$DB" | xargs)
|
||||
echo "Backing up PostgreSQL database: $DB"
|
||||
FILENAME="pgsql_${DB}_${TIMESTAMP}.sql.gz.gpg"
|
||||
if pg_dump -U postgres -d "$DB" | gzip | gpg --batch --encrypt --recipient "${GPG_RECIPIENT}" > "$BACKUP_DIR/$FILENAME"; then
|
||||
gsutil cp "$BACKUP_DIR/$FILENAME" "gs://${GCS_BUCKET}/postgresql/$FILENAME"
|
||||
echo "Successfully uploaded encrypted $FILENAME"
|
||||
else
|
||||
echo "Failed to backup $DB" >&2
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
Loading…
Add table
Add a link
Reference in a new issue