Last active
April 5, 2018 06:12
-
-
Save benduncan/c6fa0db5fdb8f615fa4f1d525d6b2bc7 to your computer and use it in GitHub Desktop.
Mysql backup using PGP and Google storage via gsutil
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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