From b1a9ac3c58cdc32865ebf0b92883875633e72b40 Mon Sep 17 00:00:00 2001 From: matthiasberner Date: Thu, 2 Oct 2025 12:00:25 +0200 Subject: [PATCH] =?UTF-8?q?BastilleBSD/Paperless-ngx/upgrade.sh=20hinzugef?= =?UTF-8?q?=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BastilleBSD/Paperless-ngx/upgrade.sh | 60 ++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 BastilleBSD/Paperless-ngx/upgrade.sh diff --git a/BastilleBSD/Paperless-ngx/upgrade.sh b/BastilleBSD/Paperless-ngx/upgrade.sh new file mode 100644 index 0000000..5f420c5 --- /dev/null +++ b/BastilleBSD/Paperless-ngx/upgrade.sh @@ -0,0 +1,60 @@ +#!/bin/sh +# +# upgrade-paperless-postgres.sh +# Ablauf: Paperless -> Postgres -> Paperless (im BastilleBSD-Jail) +# + +set -e # bei Fehler abbrechen + +JAIL="paperless" +DB_NAME="paperless" +DB_USER="paperless" +OLD_PG_VER="16" +NEW_PG_VER="17" +BACKUP_DIR="/root/pg_backup" +DUMPFILE="$BACKUP_DIR/paperless_$(date +%Y%m%d_%H%M%S).sql" + +echo ">>> Schritt 1: Paperless-Services im Jail stoppen" +bastille cmd $JAIL service paperless stop || true +bastille cmd $JAIL service redis stop || true + +echo ">>> Schritt 2: Postgres-Dump ziehen" +bastille cmd $JAIL mkdir -p "$BACKUP_DIR" +bastille cmd $JAIL su - postgres -c "\"pg_dump -U $DB_USER $DB_NAME > $DUMPFILE\"" +echo "Backup gespeichert unter: $DUMPFILE" + +echo ">>> Schritt 3: Alte Postgres-Instanz im Jail stoppen" +bastille cmd $JAIL service postgresql stop || true + +echo ">>> Schritt 4: Neue Postgres-Version installieren" +bastille cmd $JAIL pkg install -y postgresql${NEW_PG_VER}-server postgresql${NEW_PG_VER}-client + +echo ">>> Schritt 5: Neues Datenverzeichnis initialisieren" +bastille cmd $JAIL mv /var/db/postgres/data${OLD_PG_VER} /var/db/postgres/data${OLD_PG_VER}.old.$(date +%s) || true +bastille cmd $JAIL sysrc postgresql_enable="YES" +bastille cmd $JAIL service postgresql initdb +bastille cmd $JAIL service postgresql start + +echo ">>> Schritt 6: Backup einspielen" +bastille cmd $JAIL su - postgres -c "\"psql -U $DB_USER -d $DB_NAME -f $DUMPFILE\"" + +echo ">>> Schritt 7: Paperless-Upgrade (auto erkennen)" +if bastille cmd $JAIL pkg info paperless-ngx >/dev/null 2>&1; then + echo ">>> Paperless via pkg erkannt – Upgrade mit pkg" + bastille cmd $JAIL pkg upgrade -y paperless-ngx +elif bastille cmd $JAIL pip show paperless-ngx >/dev/null 2>&1; then + echo ">>> Paperless via pip erkannt – Upgrade mit pip" + bastille cmd $JAIL pip install -U paperless-ngx +else + echo ">>> WARNUNG: Paperless-Installation nicht gefunden!" + exit 1 +fi + +echo ">>> Schritt 8: Datenbankmigration Paperless" +bastille cmd $JAIL sh -c "cd /usr/local/lib/python3.11/site-packages/paperless && python3.11 manage.py migrate" + +echo ">>> Schritt 9: Dienste starten" +bastille cmd $JAIL service redis start +bastille cmd $JAIL service paperless start + +echo ">>> Upgrade abgeschlossen ✅"