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
Then I download those files back to my laptop.
mkdir bookstack-backup cd bookstack-backup rsync -rv firstname.lastname@example.org:/var/www/BookStack/bookstack-backup-* .
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
Finally I can start the server with that config...
sudo docker-compose up
...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
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
The website can be accessed at
Archiving the Docker images
Now to not depend of the Docker registeries we can also archive the images of
First we can list the images:
sudo docker images
Then take the IDs of the
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
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
And now you no longer depends on those registeries either for using this backup.
Top comments (0)