This project provides a lightweight, containerized backup solution for BookStack, including optional upload to a Nextcloud WebDAV folder and alerting via Nextcloud Talk and email.
  • Shell 94.9%
  • Dockerfile 5.1%
Find a file
2025-06-27 21:28:04 +02:00
scripts Version 1.0.0 2025-06-27 21:28:04 +02:00
docker-compose.yml Version 1.0.0 2025-06-27 21:28:04 +02:00
Dockerfile Version 1.0.0 2025-06-27 21:28:04 +02:00
README.md Version 1.0.0 2025-06-27 21:28:04 +02:00

📚 BookStack Backup Docker

This project provides a lightweight, containerized backup solution for BookStack, including optional upload to a Nextcloud WebDAV folder and alerting via Nextcloud Talk and email.


🚀 Features

  • Export BookStack books as PDF (default)

  • Upload backups to Nextcloud WebDAV

  • Cleanup old backups (both local and remote)

  • Scheduled backups via cron

  • Error notifications via:

    • 📧 Email
    • 💬 Nextcloud Talk Bot
  • Docker Healthcheck support


🐳 Usage (Docker Compose)

version: "3.9"

services:
  bookstack-backup:
    image: bookstack-backup:latest
    container_name: bookstack-backup
    volumes:
      - ./logs:/logs
      - ./backup:/backup
    environment:
      CRON_SCHEDULE: "0 0 * * *"
      EXPORT_FORMAT: "pdf"
      RETENTION_DAYS: 30
      BACKUP_DIR: "/backup"
      LOG_DIR: "/logs"

      BOOKSTACK_SERVERS: |
        server1|https://bookstack1.example.com|token_id_1|token_secret_1
        server2|https://bookstack2.example.com|token_id_2|token_secret_2

      NC_WEBDAV_UPLOAD: "off"
      NC_WEBDAV_URL: "https://cloud.example.com/remote.php/dav/files/USERNAME/BookStackBackups"
      NC_USER: "USERNAME"
      NC_PASSWORD: "APP_PASSWORD"

      NC_TALK_NOTIFY: "off"
      NC_TALK_URL: "https://cloud.example.com"
      NC_TALK_BOT_CHANNEL: "channel_id"
      NC_TALK_BOT_SECRET: "secret"

      EMAIL_NOTIFY: "off"
      EMAIL_TO: "admin@example.com"
      EMAIL_FROM: "bookstack-backup@example.com"
      SMTP_SERVER: "smtp.example.com"
      SMTP_PORT: 587
      SMTP_USER: "smtp-user"
      SMTP_PASS: "smtp-pass"
      SMTP_TLS: "on"

    healthcheck:
      test: ["CMD", "/app/healthcheck.sh"]
      interval: 5m
      timeout: 10s
      retries: 3
      start_period: 30s

Setup

1. Configure BookStack API

  • Create tokens in Settings > API Tokens (admin panel)
  • Ensure the token has access to the /api/books and /api/books/:id/export/pdf endpoints

2. Enable WebDAV upload (optional)

  • Set NC_WEBDAV_UPLOAD=on
  • Provide valid credentials and NC_WEBDAV_URL

3. Enable Nextcloud Talk notifications (optional)

  • Set NC_TALK_NOTIFY=on
  • Fill in NC_TALK_URL, NC_TALK_BOT_CHANNEL, and NC_TALK_BOT_SECRET

4. Enable Email alerts (optional)

  • Set EMAIL_NOTIFY=on
  • Configure SMTP_SERVER, EMAIL_FROM, EMAIL_TO, etc.

🤖 Create a Nextcloud Talk Bot

To enable Nextcloud Talk notifications, a bot must be created:

# Configuration
BOT_NAME="BookStack"  # Display name
BOT_SECRET=$(openssl rand -hex 40)
BOT_BASE_URL="https://cloud.example.com/ocs/v2.php/apps/spreed/api/v1/bot"

# Sanitize for URL (lowercase, no spaces)
BOT_NAME_LOWER=$(echo "$BOT_NAME" | tr '[:upper:]' '[:lower:]' | tr -cd 'a-z0-9_-')
BOT_URL="${BOT_BASE_URL}/${BOT_NAME_LOWER}"

# Register bot
php occ talk:bot:install \
  --feature message \
  "$BOT_NAME" \
  "$BOT_SECRET" \
  "$BOT_URL" \
  && echo "✅ Bot installed"
echo "🔑 Secret: $BOT_SECRET"
echo "🌐 URL:    $BOT_URL"

Set NC_TALK_BOT_SECRET to the value of $BOT_SECRET in your compose file.


📁 Output

  • Logs saved to /logs/backup_YYYY-MM-DD.log
  • Book exports saved to /backup/<server_name>/YYYY-MM-DD/*.pdf
  • Remote uploads (if enabled) stored in Nextcloud under matching folder structure

🧑‍💻 Author


📝 License

MIT License free for commercial and private use.


Build

Multi Platform Builder

docker buildx create --use --platform=linux/arm64,linux/amd64 --name multi-platform-builder
docker buildx inspect --bootstrap

Build

docker buildx build --platform linux/amd64,linux/arm64 --push --tag onesystems/bookstackbackup:v1.0.0 --tag onesystems/bookstackbackup:latest --file Dockerfile .