Skip to content

Instantly share code, notes, and snippets.

@benduncan
Last active April 5, 2018 06:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benduncan/c6fa0db5fdb8f615fa4f1d525d6b2bc7 to your computer and use it in GitHub Desktop.
Save benduncan/c6fa0db5fdb8f615fa4f1d525d6b2bc7 to your computer and use it in GitHub Desktop.
Mysql backup using PGP and Google storage via gsutil
#!/bin/sh
# Grab the date, captain!
DATE=`date`
# Dump all databases
mysqldump -u root --all-databases > /root/backup-sql/$DATE.sql
# Encrypt the backup based on a specified users PGP public key
gpg -e -r security@mydomain.com -a --trust-model always "/root/backup-sql/$DATE.sql"
# Upload to the specified bucket on GCP
gsutil cp "/root/backup-sql/$DATE.sql.asc" gs://mystoragename/
# Remove the non encrypted copy
rm /root/backup-sql/$DATE.sql
# Delete any backups over 7 days old, reference the bucket instead
find /root/backup-sql/ -ctime +7 | xargs -I{} rm {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment