Created
May 24, 2021 12:14
-
-
Save jbontech/ddf338ea3f0e0b41cb37b9c82780b43f to your computer and use it in GitHub Desktop.
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 | |
| FILE=/home/ubuntu/mysql_backup/mysql-credentials.cnf | |
| if [ -f "$FILE" ]; then | |
| echo "$FILE exists." | |
| rm $FILE | |
| else | |
| echo "$FILE does not exist." | |
| fi | |
| credentialsFile=/home/ubuntu/mysql_backup/mysql-credentials.cnf | |
| echo "[client]" > $credentialsFile | |
| echo "user=root" >> $credentialsFile | |
| echo "password=XXXXXXXXXX" >> $credentialsFile | |
| echo "host=localhost" >> $credentialsFile | |
| #COPYING THE FILE inside the docker container | |
| docker cp $FILE mysql:/ | |
| docker exec -it mysql mysqldump --defaults-extra-file=/mysql-credentials.cnf --all-databases > all_databases-$(date +%Y%m%d).sql | |
| #COPY THE MYSQL BACKUP TO S3 | |
| aws s3 cp /home/ubuntu/mysql_backup/all_databases-$(date +%Y%m%d).sql s3://test-bucket/backup/Demo/mysql-backup/all_databases-$(date +%Y%m%d).sql |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment