Skip to content

Commit

Permalink
paperless postgres upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
fabio-garavini committed Jan 28, 2025
1 parent 6f9f10b commit 63bf0bb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion paperless/config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Paperless
version: "2.14.5-v3"
version: "2.14.5-v4"
slug: paperless
codenotary: [email protected]
description: Document management system that transforms your physical documents into a searchable online archive
Expand Down
12 changes: 11 additions & 1 deletion paperless/rootfs/etc/s6-overlay/s6-rc.d/init-db-migration/run
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
#!/command/with-contenv /usr/bin/bash
set -e

mkdir -p /config/postgres-backups
chown postgres:postgres -R /config/postgres-backups

if [ -d "${PGDATA}-15-backup" ]; then
mv $PGDATA "/config/postgres-backups/$(date +"%Y-%m-%d_%H-%M-%S")"
mv "${PGDATA}-15-backup" $PGDATA
fi

if [ -f "$PGDATA/PG_VERSION" ] && ! grep -q "$PG_MAJOR" "$PGDATA/PG_VERSION"; then

current_pg_major=$(cat "$PGDATA/PG_VERSION" | cut -d '.' -f 1)
Expand All @@ -22,9 +30,11 @@ if [ -f "$PGDATA/PG_VERSION" ] && ! grep -q "$PG_MAJOR" "$PGDATA/PG_VERSION"; th

su postgres -c '/usr/lib/postgresql/$PG_MAJOR/bin/initdb --username="$POSTGRES_USER" --pwfile=<(printf "%s\n" "$POSTGRES_PASSWORD") -c log_directory="/config/logs/postgres" -c log_rotation_size=10MB -D $PGDATA'

su postgres -c '/usr/lib/postgresql/$PG_MAJOR/bin/pg_upgrade -d '"${PGDATA}-${current_pg_major}-backup"' -D '"$PGDATA"' -b '"/usr/lib/postgresql/$current_pg_major/bin"' -B '"/usr/lib/postgresql/$PG_MAJOR/bin"' --username="$POSTGRES_USER"'
su postgres -c '/usr/lib/postgresql/$PG_MAJOR/bin/pg_upgrade --clone -d '"${PGDATA}-${current_pg_major}-backup"' -D '"$PGDATA"' -b '"/usr/lib/postgresql/$current_pg_major/bin"' -B '"/usr/lib/postgresql/$PG_MAJOR/bin"' --username="$POSTGRES_USER"'

apt-get remove -y postgresql-${current_pg_major}
apt autoremove -y
apt autoclean -y

mv "${PGDATA}-${current_pg_major}-backup" "/config/postgres-backups/$(date +"%Y-%m-%d_%H-%M-%S")"
fi

0 comments on commit 63bf0bb

Please sign in to comment.