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
23
nix-system-configs/modules/system_scripts/backup_mariadb.zsh
Normal file
23
nix-system-configs/modules/system_scripts/backup_mariadb.zsh
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
#!/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
|
||||
|
||||
gpg --batch --import "${GPG_KEY_FILE}"
|
||||
|
||||
DATABASES=$(mysql -u root -e "SHOW DATABASES;" | grep -Ev "^(Database|information_schema|performance_schema|mysql|sys)$")
|
||||
|
||||
for DB in $DATABASES; do
|
||||
echo "Backing up MariaDB database: $DB"
|
||||
|
||||
FILENAME="mariadb_${DB}_${TIMESTAMP}.sql.gz.gpg"
|
||||
if mysqldump -u root "$DB" | gzip | gpg --batch --encrypt --recipient "${GPG_RECIPIENT}" > "$BACKUP_DIR/$FILENAME"; then
|
||||
gsutil cp "$BACKUP_DIR/$FILENAME" "gs://${GCS_BUCKET}/mariadb/$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