🗃️ Using Docker to archive a service (BookStack)

snowcode

SnowCode

Posted on February 9, 2023

🗃️ Using Docker to archive a service (BookStack)

I was on a process to dockerize my infrastructure and I wanted to archive a service I couldn't simply migrate to a newer version nor really use anymore.

So I used Docker to archive it without depending on any dependency.

# First I go into the website's directory
cd /var/www/BookStack

# I generate a SQL script as a backup of the database named "bookstack_db"
mysqldump -u root bookstack_db > bookstack-backup-db.sql

# Then I used tar to create an archive of files (.env, uploads)
tar -czvf bookstack-backup-files.tar.gz .env public/uploads storage/uploads

# Then I take the version of BookStack
cat version
Enter fullscreen mode Exit fullscreen mode

Then I download those files back to my laptop.

mkdir bookstack-backup
cd bookstack-backup
rsync -rv debian@snowcode.ovh:/var/www/BookStack/bookstack-backup-* .
Enter fullscreen mode Exit fullscreen mode

Then, I created a docker-compose file with the following content to describe my infrastructure.

version: "2"
services:
  bookstack:
    image: ghcr.io/linuxserver/bookstack:version-v0.31.4 # Here goes my bookstack version
    container_name: bookstack
    environment:
      - PUID=1000
      - PGID=1000
      - APP_URL=http://localhost:8080
      - DB_HOST=bookstack_db
      - DB_PORT=3306
      - DB_USER=bookstack
      - DB_PASS=secret
      - DB_DATABASE=bookstackapp
    volumes:
      - ./bookstack_files:/config
    ports:
      - 8080:80
    depends_on:
      - bookstack_db
  bookstack_db:
    image: lscr.io/linuxserver/mariadb:10.6.10
    container_name: bookstack_db
    environment:
      - PUID=1000
      - PGID=1000
      - MYSQL_ROOT_PASSWORD=secret
      - TZ=Europe/Brussels
      - MYSQL_DATABASE=bookstackapp
      - MYSQL_USER=bookstack
      - MYSQL_PASSWORD=secret
    volumes:
      - ./bookstack_db:/config
Enter fullscreen mode Exit fullscreen mode

Finally I can start the server with that config...

sudo docker-compose up
Enter fullscreen mode Exit fullscreen mode

...and place the files into the right volumes/directories.

sudo su # I need to be root for accessing the volumes
mv bookstack-backup-files.tar.gz bookstack_files
mv bookstack-backup-db.sql bookstack_db
cd bookstack_files
tar xvzf bookstack-backup-files.tar.gz
Enter fullscreen mode Exit fullscreen mode

Finally I can enter the running container of my database to import the script

sudo docker exec -it bookstack_db bash -c "mysql -u bookstack -p bookstackapp < /config/bookstack-backup-db.sql"
# The default password is secret as defined in the docker-compose
Enter fullscreen mode Exit fullscreen mode

The website can be accessed at http://localhost:8080

Archiving the Docker images

Now to not depend of the Docker registeries we can also archive the images of mariadb and bookstack

First we can list the images:

sudo docker images
Enter fullscreen mode Exit fullscreen mode

Then take the IDs of the mariadb and bookstack images to export them into a TAR archive.

sudo docker image save aad0c49aebf3 -o bookstack.tar
sudo docker image save 39a4293c3071 -o mariadb.tar
Enter fullscreen mode Exit fullscreen mode

Now it's done ! When we need it we can import the images back from the archives using those commands:

sudo docker image import bookstack.tar ghcr.io/linuxserver/bookstack:version-v0.31.4 
sudo docker image import mariadb.tar lscr.io/linuxserver/mariadb:10.6.10
Enter fullscreen mode Exit fullscreen mode

And now you no longer depends on those registeries either for using this backup.

💖 💪 🙅 🚩
snowcode
SnowCode

Posted on February 9, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related