Last active
June 6, 2022 11:29
-
-
Save muradddd/a1fd9a498888fe7c173448e6e307393b to your computer and use it in GitHub Desktop.
Backup / restore SQL DB
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 {CONTAINER} /usr/bin/mysqldump -u {USER} --password={PASSWORD} {DATABASE} > {BACKUP_FILE_PATH} | |
# For ignoring some tables | |
docker exec {CONTAINER} /usr/bin/mysqldump -u {USER} --password={PASSWORD} --ignore-table={DATABASE}.{TABLE} {DATABASE} > {BACKUP_FILE_PATH} |
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} |
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 -it ${DB_CONTAINER} bash # create a new Bash session in the container | |
pg_dumpall -c -U ${DB_USER} > ${FILENAME} # dump sql data | |
docker cp ${DB_CONTAINER}:${FILENAME} ./${DESTIONATION_PATH} # copying dumped data from container to host |
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 cp ${DUMPED_FILE_PATH} ${DB_CONTAINER}:. # copying dumped data from host to container | |
docker exec -it ${DB_CONTAINER} bash # create a new Bash session in the container | |
psql -U ${DB_USER} ${DB_NAME} < ${FILENAME} # restore sql data |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment