Last active
August 13, 2021 07:29
-
-
Save roydejong/ef9228e608d9f4fe342af93395bff1a4 to your computer and use it in GitHub Desktop.
Cron script: MySQL Nightly Backups to S3
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/bash | |
# /etc/cron.daily/mysql-s3-backup | |
# Before use, install AWS CLI and use "aws configure" to set up credentials with write access to your s3 bucket | |
# See https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2-linux.html#cliv2-linux-install | |
DB_USER=XXX | |
DB_NAME=XXX | |
DB_PASS=XXX | |
BUCKET_NAME=XXX | |
BACKUP_FILENAME=$DB_NAME-$(date +%Y-%m-%dT%H:%M:%S).sql.gz | |
mysqldump $DB_NAME -u $DB_USER -p$DB_PASS | gzip > $BACKUP_FILENAME | |
aws s3 cp $BACKUP_FILENAME s3://$BUCKET_NAME | |
rm $BACKUP_FILENAME |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment