Created
April 3, 2019 19:34
-
-
Save RanKey1496/6ac3256a3592fabcb170c6e0801791f1 to your computer and use it in GitHub Desktop.
Backup a dockerized MySQL and upload to S3
This file contains hidden or 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 | |
# Configuration | |
CONTAINER="mysql" | |
FILENAME="databasename-`date +%Y-%m-%d`.sql" | |
MYSQL_USER='user' | |
MYSQL_PASSWORD='password' | |
DATABASE_NAME='databasename' | |
S3_BUCKET_NAME='bucket' | |
S3_BUCKET_PATH='backups' | |
# Backup from Docker | |
docker exec -it $(docker ps -f name=$CONTAINER -q --no-trunc | head -n1) mysqldump -u$MYSQL_USER -p$MYSQL_PASSWORD $DATABASE_NAME > /tmp/$FILENAME | |
# Upload to Digital Ocean Spaces | |
# s3cmd should be configured before | |
s3cmd put /tmp/$FILENAME s3://$S3_BUCKET_NAME/$S3_BUCKET_PATH/$FILENAME |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment