-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
109b997
commit 4f9b4a9
Showing
3 changed files
with
58 additions
and
2 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,36 @@ | ||
# mysqldump-s3-backup | ||
Docker-enabled tool to backup MySQL database and upload to S3 bucket. | ||
# MDSB - MySQL Dump S3 Backup | ||
|
||
MySQL Dump S3 Backup (MDSB) provides scripts to perform dump of a MySQL database and upload the result to an S3 bucket. | ||
|
||
## Requirements | ||
|
||
- Linux Bash | ||
- Docker | ||
|
||
## Configuration | ||
|
||
Configure the following variables in [env.sh](./env.sh) file: | ||
| Key | Value | | ||
|--|--| | ||
| MYSQL_VERSION | MySQL version (e.g. 5.7, 8.0) | | ||
| MYSQL_HOST | Hostname of MySQL instance | | ||
| MYSQL_PORT | Port of MySQL instance | | ||
| MYSQL_USER | MySQL username | | ||
| MYSQL_PWD | MySQL password | | ||
| MYSQL_DATABASE | Name of the database to dump | | ||
| AWS_ACCESS_KEY_ID | IAM user's access key | | ||
| AWS_SECRET_ACCESS_KEY | IAM user's secret key | | ||
| AWS_DEFAULT_REGION | S3 bucket region | | ||
| BUCKET_NAME | S3 bucket name | | ||
| FOLDER_IN_BUCKET | S3 folder where to store dump file | | ||
| TZ | Timezone (e.g. Europe/Rome) | | ||
|
||
## Run | ||
|
||
./run.sh | ||
|
||
## Scheduling | ||
You can programmatically run it using a cron job. | ||
|
||
## Next? | ||
- Dockerize application |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/bin/bash | ||
|
||
MYSQL_VERSION=<mysql-version> | ||
MYSQL_HOST=<mysql-hostname> | ||
MYSQL_PORT=<mysql-port> | ||
MYSQL_DATABASE=<mysql-database-name> | ||
MYSQL_USER=<mysql-username> | ||
MYSQL_PWD=<mysql-password> | ||
AWS_ACCESS_KEY_ID=<aws-access-key> | ||
AWS_SECRET_ACCESS_KEY=<aws-secret-key> | ||
AWS_DEFAULT_REGION=<aws-region> | ||
BUCKET_NAME=<aws-s3-bucket-name> | ||
FOLDER_IN_BUCKET=<aws-s3-folder> | ||
TZ=<timezone> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/bash | ||
|
||
source ./env.sh | ||
|
||
current_time=$(date "+%Y.%m.%d-%H.%M.%S") | ||
docker run --rm -e MYSQL_PWD=$MYSQL_PWD mysql:$MYSQL_VERSION mysqldump -u $MYSQL_USER -h $MYSQL_HOST -P $MYSQL_PORT $MYSQL_DATABASE 1> $MYSQL_DATABASE_backup_$current_time.sql | ||
docker run --network host -e AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID -e AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY -e AWS_DEFAULT_REGION=$AWS_DEFAULT_REGION -v "$PWD":/app -w /app amazon/aws-cli s3 cp $MYSQL_DATABASE_backup_$current_time.sql s3://$BUCKET_NAME/$FOLDER_IN_BUCKET/$MYSQL_DATABASE_backup_$current_time.sql | ||
rm $MYSQL_DATABASE_backup_$current_time.sql |