Last active
July 14, 2022 12:51
-
-
Save muradddd/c352c7647a848f79b6956c08c6aff648 to your computer and use it in GitHub Desktop.
Backup and restore a mysql database from a running Docker mysql container
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
docker exec -t {CONTAINER} mysqldump -u {USER} --password={PASSWORD} {DATABASE} > {BACKUP_FILE_PATH} | |
docker exec -t db mysqldump -u root --password=yelobank YeloBankProjectDB > _backups/data.sql |
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
cat {BACKUP_FILE_PATH} | docker exec -i {CONTAINER} /usr/bin/mysql -u {USER} --password={PASSWORD} {DATABASE} | |
cat _backups/data.sql | docker exec -i db /usr/bin/mysql -u root --password=yelobank YeloBankProjectDB |
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
docker exec -t your-db-container pg_dumpall -c -U postgres > dump_`date +%d-%m-%Y"_"%H_%M_%S`.sql |
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
cat your_dump.sql | docker exec -i your-db-container psql -U postgres |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment