diff --git a/README.md b/README.md index 33c61fe..203d563 100644 --- a/README.md +++ b/README.md @@ -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 \ No newline at end of file diff --git a/env.sh b/env.sh new file mode 100644 index 0000000..e4f565b --- /dev/null +++ b/env.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +MYSQL_VERSION= +MYSQL_HOST= +MYSQL_PORT= +MYSQL_DATABASE= +MYSQL_USER= +MYSQL_PWD= +AWS_ACCESS_KEY_ID= +AWS_SECRET_ACCESS_KEY= +AWS_DEFAULT_REGION= +BUCKET_NAME= +FOLDER_IN_BUCKET= +TZ= \ No newline at end of file diff --git a/run.sh b/run.sh new file mode 100755 index 0000000..1f0c817 --- /dev/null +++ b/run.sh @@ -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