Wiki
Installation of a wiki with Bookstacks
Installation
Installation
-
Create a new directory and the necessary files
mkdir -p bookstack/config && cd bookstack touch docker-compose.yml .env
-
Edit the
.env
file to include the following:DB_PASSWD=<password> #do not change later on or stuff may break APP_URL=example.com:6875 PORT=6875 PUID=1000 PGID=1000
-
Edit the docker-compose.yml to include the following:
version: "3" services: bookstack_db: restart: unless-stopped image: lscr.io/linuxserver/mariadb container_name: bookstack_db environment: - PUID=${PUID} - PGID=${PGID} - MYSQL_ROOT_PASSWORD=${BOOKSTACK_PASSWD} - TZ=${TZ} - MYSQL_DATABASE=bookstackapp - MYSQL_USER=${BOOKSTACK_USER} - MYSQL_PASSWORD=${BOOKSTACK_PASSWD} volumes: - ./data/bookstack_db_data:/config bookstack: restart: unless-stopped image: lscr.io/linuxserver/bookstack container_name: bookstack environment: - PUID=${PUID} - PGID=${PGID} - APP_URL=https://${SITE} - DB_HOST=bookstack_db - DB_PORT=3306 - DB_USER=${BOOKSTACK_USER} - DB_PASSWORD=${BOOKSTACK_PASSWD} - DB_DATABASE=bookstackapp volumes: - ./data/bookstack_app_data:/config - ./backup:/backup ports: - 6875:80 labels: traefik.enable: "true" traefik.http.routers.bookstack.rule: "Host(`${SITE}`)" traefik.http.routers.bookstack.entrypoints: websecure traefik.http.routers.bookstack.middlewares: secured@file
-
Start the container with
docker compose up -d
-
Go to the
APP-URL
that you specified, e.g.http://server:6785
and login. The default login isadmin@admin.com
and the password ispassword
. -
Make sure to change email and password after your first login
See Also
Backup & Restore
Preparations
- Make sure to have php installed on your system
- Get an
API token_id
andAPI token_secret
from your user preferences in the webgui - Create a directory, where you want to store the backups
mkdir backup && cd backup mkdir zip md pdf
- Downlaod the
export-books.php
script from githubcurl https://raw.githubusercontent.com/BookStackApp/api-scripts/main/php-export-all-books/export-books.php > export-books.php
- Edit the
export-books.php
sciprt and enter the needed variablesBS_URL=https://bookstack.example.com # Set to be your BookStack base URL BS_TOKEN_ID=abc123 # Set to be your API token_id BS_TOKEN_SECRET=123abc # Set to be your API token_secret
- Create a file
backup.sh
that specifies the kind of backup and deletes backup older than X days#!/bin/bash # go to the correct directory cd $(dirname "$0") CURRENTDATE=$(date +%Y-%m-%d_%H-%M-%S) # Create a new backup using the bookstack-system-cli command docker exec -it bookstack /app/www/bookstack-system-cli backup /backup/zip/bookstack_$(date +%Y-%m-%d_%H-%M-%S).zip # create a backup in pdf and md format mkdir -p ./pdf/$CURRENTDATE ./md/$CURRENTDATE php export-books.php pdf ./pdf/$CURRENTDATE php export-books.php markdown ./md/$CURRENTDATE # delete backups older than 10 days find ./pdf -maxdepth 1 -mtime +10 -exec rm -r -f {} \; find ./md -maxdepth 1 -mtime +10 -exec rm -r -f {} \; find ./zip/*.zip -mtime +10 -exec rm -f {} \;
- Make the added files executable
chmod +x export-books.php backup.sh
- Make sure to bindmount your
backup
folder in the volumes section of the bookstack container by adding- ./backup:/backup
Backing up
With the above setup, pdf and markdown backups will be found inside the backups
folder. Inside the zip backup/zip
folder are the backups of the website.
To start backing up, simply create a cronjob that runs repeatedly. To save the books every day at 3am, simply add the following cronjob
0 3 * * * /path/to/bookstack/backup/backup.sh
Now simply backup the whole backup folder regularly to a different place and you should be good to go
Restoring
To restore the data simply start a container and run the following command
docker exec -it bookstack /app/www/bookstack-system-cli restore backup/<<nameofbackup>>.zip
See also:
-
https://gist.github.com/ssddanbrown/3d5dbebc51ac6ca45837d8a030b07b65
-
https://github.com/BookStackApp/api-scripts/tree/main/php-export-all-books
Troubleshooting
After changing APP_URL
in the env file, it might be necessary to run the following:
docker exec -it bookstack php /app/www/artisan bookstack:update-url <OLD_APP_URL> <NEW_APP_URL>