How to Restore MySQL Backup in Docker Compose Setup

Hello everyone,

I’ve successfully created a backup of my MySQL database running in a Docker container using the following command:

docker exec mg-ghostcms-db-1 /bin/bash -c "mysqldump -u root -p'password' ghost" > $(pwd)/db_backup.sql

I now need to restore this backup, but I’m not sure of the exact steps. Could someone please guide me through the process of restoring this backup to the different MySQL Docker containers?

I am running Ghost as a Docker Compose setup with Ghost 5 and MySQL 8.

Thank you in advance for your assistance!

Best regards,
Pavan Patil

Hey Pavan, welcome to Ghost!

Give this a go:

docker exec -i mg-ghostcms-db-1 mysql -u root -p'password' ghost < $(pwd)/db_backup.sql

Make sure that the location of the database dump, the container name, password, etc. are all correct, of course.

Dear @jannis,

Thank you for your prompt response and the solution provided.

I have a doubt: Will this command restore my full Ghost data?

Regards,
Pavan

It will load the mysql dump you took earlier and put it back into the database. So, it will reset your Ghost site to the database state that you backed up. It will, however, not restore any files that were saved in the /content folder (images, themes, etc.).

Okay, got it.

I have the content folder in a Ghost Docker volume, but I’m not sure of the exact steps to move it to a new setup.

If you have any idea, could you please assist? Do I need to mount all content to a new Docker volume?

I usually archive the content of the volume, then move it wherever I need it, and extract it into the new volume.

Here’s a rough guide you can adapt for your needs:

Okay, got it.

Thank you so much for your help. I will try it.

By the way, I don’t see any guide related to Ghost backup and restore for Docker Compose setup. If you have any reference, please share it.

Docker setups aren’t officially supported and the docker setups out there are usually very individual.

However, backing up docker volumes and/or databases is pretty universal, independent of what software you run inside the container.

So, rather than looking for a Ghost-specific docker tutorial, I’d try to understand how Docker works (e.g. the link I shared above). That way you’ll then be able to put that knowledge to use in your own setup.

1 Like

Got it, thank you for the clarification.

I appreciate your guidance and will apply that knowledge to my setup.

Thank you again for your assistance!

Regards,
Pavan

1 Like