MySQL
When you have a MySQL Database and want to do a backup/restore from the host machine you can use the following commands:
Backupdocker exec CONTAINER /usr/bin/mysqldump -u root --password=root DATABASE > backup.sql
Restorecat backup.sql | docker exec -i CONTAINER /usr/bin/mysql -u root --password=root DATABASE
MongoDB
Backup
You can perform a backup of your mongo db using a temporary container. You have to know the following:
– network name of running mongo db service
– service name of running mongo db service
– password of admin user
– database name to export
docker run --network <networkname>--rm mongo mongodump --host <mongoservice>:27017 --username=root --password=<password> --authenticationDatabase admin --db=<dbname> --archive --gzip | cat >export .gz
Restorecat export.gz | docker run --network <networkname> --rm -i mongo mongorestore --host
<mongoservice>:27017 --username=root --password=<password< -db=<
dbname> --archive --gzip --drop