Bookstack in Docker Database Recovery

I recently ran into an issue where my old Bookstack database in Docker was having an issue. I wanted to make a new “Stack” using Portainer instead of having two separate containers, and of course while doing this it pulled the latest app and mariadb images. Well it just would not come back up. So I tried hacking together a few things to make it work but just could not get there. After making small progress I hopped into the Bookstack Discord server and the Dev gave me a few pointers that finally solved it for me. So if you use Docker for your Bookstack app and want to know how to back it up and/or import it into a brand new instance… here are the steps I used.

Warning! You must know the database password!

  1. Spin up just the database container with your old docker Volume or bind mount.

  2. From the command line of the host system docker exec -it bookstack_db bash to enter the running container.

  3. Once inside the container run mysqldump -u USER -p DATABASE > DATABASE.backup.sql in my case this looked like mysqldump -u root -p bookstackapp > bookstack.backup.sql

  4. Next I copied that .sql file into /config so that I could use Filezilla to FTP it somewhere safe (my PC).

  5. Now that you have your backup file, kill the old db container. Spin up a new stack (portainer or compose) with the new app and database. Check logs to ensure it’s up without errors.

  6. Now stop the just the bookstack app container.

  7. Move/Copy or FTP the backup.sql file into the /config of the new db container.

  8. From the command line of the host system run docker exec -it bookstack_db bash where “bookstack_db” is the name of your db container.

  9. Now run mysql -u root -p to login to the database but not into a specific database.

  10. At the prompt run DROP DATABASE bookstackapp; and CREATE DATABASE bookstackapp;

  11. Type \q to exit mysql back to the container bash shell.

  12. From the command line run mysql -u root -p bookstackapp < bookstack.backup.sql to import your old database.

  13. Spin up the bookstack app container and login with your normal user/pass.

If you have attachments and pictures you may need to backup the /config folder from your old bookstack app container and copy to the new container. This will save any images or attachments that you may have added. But if you only care about he books and pages from the database, you’re done.

Please let me know if you have any questions!