In order to use AWS S3 dor backups configure your credentials in ~/.aws/credentials:
[bucket-name]
aws_access_key_id = SOME_ACCESS_KEY_ID
aws_secret_access_key = SOMEKEY| #/bin/env bash | |
| # First configure aws cli to authenticate on aws. | |
| # See https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-quickstart.html#cli-configure-quickstart-creds | |
| CURRENT_DIR=$(dirname $(readlink -f $0)) | |
| CURRENT_DATE=$(date +%Y%m%d%H%M) | |
| source .env # path to MySQL credentials | |
| mysqldump -h$MYSQL_HOST -u$MYSQL_USER -p$MYSQL_PASSWORD $MYSQL_DB > /tmp/$CURRENT_DATE.sql | |
| gzip /tmp/$CURRENT_DATE.sql | |
| if [[ $1 = "aws" ]] | |
| then | |
| # do not forget to convigure versioning and autoremove policy | |
| aws s3 --profile=$AWS_PROFILE_NAME cp /tmp/$CURRENT_DATE.sql.gz s3://$AWS_PROFILE_NAME/last.sql.gz | |
| rm /tmp/$CURRENT_DATE.sql.gz | |
| else | |
| mv /tmp/$CURRENT_DATE.sql.gz . | |
| # kill backups older two month | |
| find . -type f -name '*.sql.gz' -mtime +60 -exec rm -f {} \; | |
| fi |
In order to use AWS S3 dor backups configure your credentials in ~/.aws/credentials:
[bucket-name]
aws_access_key_id = SOME_ACCESS_KEY_ID
aws_secret_access_key = SOMEKEY