Skip to content

Instantly share code, notes, and snippets.

@jbontech
Created May 24, 2021 12:14
Show Gist options
  • Save jbontech/ddf338ea3f0e0b41cb37b9c82780b43f to your computer and use it in GitHub Desktop.
Save jbontech/ddf338ea3f0e0b41cb37b9c82780b43f to your computer and use it in GitHub Desktop.
#!/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