Skip to content

Instantly share code, notes, and snippets.

@paulknulst
Created November 3, 2021 09:33
Show Gist options
  • Save paulknulst/4af45079b2b935de416aca8f01e15278 to your computer and use it in GitHub Desktop.
Save paulknulst/4af45079b2b935de416aca8f01e15278 to your computer and use it in GitHub Desktop.
zip/encrypt (with pass from env) db backups within folder and upload resulting file to gcp using stored credentials on system
#!/bin/bash
TIME=$(date +%Y-%m-%d)
HOST=$(hostname)
BACKUPSAVEPATH=/root/backups_encrypted/
BACKEDUPFILE=$BACKUPSAVEPATH/db-backups-$HOST-$TIME.enc
TARGET=gs://f1nalboss-db-backups/
cd /root/backups/db || exit 1
if [ -z "$(ls -A .)" ]; then
exit 1
else
tar czf - . | openssl enc -e -aes-256-cbc -pbkdf2 -iter 100000 -salt -out $BACKEDUPFILE -pass env:PASS
/root/google-cloud-sdk/bin/gsutil -m rsync -r $BACKUPSAVEPATH $TARGET || exit 1
rm -rf /root/backups/db/*
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment