Last active
July 28, 2023 20:42
-
-
Save sebastian13/cc58304f7b177ac1d16d7671dc67efb9 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
| # Change to the script's directory & create directory | |
| cd $(dirname "$(readlink -f "$0")") | |
| mkdir -p ./dbdumps | |
| # Start mysql service of your compose file | |
| docker-compose up -d mysql | |
| # Load database name + root password | |
| source .env | |
| # Delete old Backups | |
| find ./dbdumps/* -atime +7 -exec rm {} \; | |
| docker-compose exec mysql /usr/bin/mysqldump -u root \ | |
| --password=$MYSQL_ROOT_PASSWORD $MYSQL_DATABASE \ | |
| | gzip --rsyncable > ./dbdumps/`date +\%Y\%m\%d`-$MYSQL_DATABASE.sql.gz |
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
| # Start mysql service of your compose file | |
| docker-compose up -d mysql | |
| # Load database name + root password | |
| source .env | |
| # Find latest dump | |
| latest=$(ls -1t ./dbdumps/*.sql.gz | head -1) | |
| # Restore | |
| gunzip $latest | docker-compose exec mysql \ | |
| /usr/bin/mysql -u root --password=${MYSQL_ROOT_PASSWORD} ${MYSQL_DATABASE} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I just had a problem with
source .env, but replacing this line with. ./.envworked. Thanks for these scripts, amazing work!