Last active
June 27, 2024 11:10
-
-
Save DominikStyp/8f2c6178efd882b55d01fa565dbb61d6 to your computer and use it in GitHub Desktop.
Backup MySQL database from the docker container to the output SQL file
This file contains 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 | |
# REQUIRES ROOT ACCESS TO DUMP ALL THE PROCEDURES TRIGGERS ETC. | |
source .env | |
DATE_TIME=$(date +%Y-%m-%d__%H_%M_%S) | |
BACKUP_FILE="${DB_DATABASE}_backup_${DATE_TIME}.sql" | |
docker exec project-mysql_database-1 mysqldump -h $DB_HOST -u root -p"$DB_ROOT_PASSWORD" $DB_DATABASE --single-transaction --routines --triggers > $BACKUP_FILE | |
echo "Backup of the database saved as $BACKUP_FILE" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
docker ps
will tell you how your database container is named