#!/usr/bin/env bash # Back up Dify installed with https://exe.dev/deploy/dify. Run as root: # sudo DIFY_DIR=/home/exedev/dify/docker ./dify-backup.sh # Writes $DEST/dify-YYYYMMDD-HHMMSS.tar.gz and keeps the newest 14. Inside: # postgres.sql.gz both databases (dify, dify_plugin), from pg_dumpall # volumes.tar.gz uploads and keys, plugins, Weaviate vectors, sandbox config # config.tar.gz .env, the override file, and exe.dev's nginx server set -euo pipefail umask 077 DIFY_DIR=${DIFY_DIR:-/home/exedev/dify/docker} DEST=${DEST:-$(dirname "$(dirname "$DIFY_DIR")")/dify-backups} cd "$DIFY_DIR" owner=$(stat -c %U:%G .) work=$(mktemp -d) trap 'rm -rf "$work"; docker compose start weaviate >/dev/null 2>&1 || true' EXIT mkdir -p "$DEST" out="$DEST/dify-$(date -u +%Y%m%d-%H%M%S).tar.gz" # Postgres dumps consistently while Dify keeps running. docker compose exec -T db_postgres pg_dumpall -U postgres --clean --if-exists \ | gzip > "$work/postgres.sql.gz" # Weaviate writes its files all the time; pause it for the copy. docker compose stop weaviate >/dev/null tar -czf "$work/volumes.tar.gz" \ volumes/app/storage volumes/plugin_daemon volumes/weaviate volumes/sandbox docker compose start weaviate >/dev/null tar -czf "$work/config.tar.gz" \ .env docker-compose.override.yaml nginx/conf.d/exe-public.conf tar -C "$work" -czf "$out.part" postgres.sql.gz volumes.tar.gz config.tar.gz mv "$out.part" "$out" chown -R "$owner" "$DEST" # Keep the 14 newest backups. ls -1t "$DEST"/dify-*.tar.gz | tail -n +15 | xargs -r rm -- echo "$out"