Skip to content

How to restore a Nextcloud PostgreSQL database

Nextcloud on aux uses Postgres inside the compose stack (nextcloud-db-1), data bind-mounted at ~/nextcloud/db/. Do not confuse this with host postgresql@16-main unless you have knowingly moved the DB.

Prerequisites

  • Maintenance window (users locked out or in read-only)
  • A known-good dump or restic snapshot
  • Disk space for a second copy of ~/nextcloud/db

Steps (logical dump)

  1. Stop the app (keep DB up for dump/restore as needed):
    bash
    cd ~/nextcloud
    docker compose stop app
  2. Take a safety copy of current DB files (if disk allows):
    bash
    cp -a ~/nextcloud/db ~/nextcloud/db.bak-$(date -u +%Y%m%dT%H%M%SZ)
  3. Restore from SQL dump (example):
    bash
    # dump was created with:
    # docker exec -t nextcloud-db-1 pg_dump -U nextcloud nextcloud > nextcloud.sql
    cat /path/to/nextcloud.sql | docker exec -i nextcloud-db-1 psql -U nextcloud nextcloud
  4. Start app and watch logs:
    bash
    docker compose start app
    docker logs nextcloud-app-1 --tail 50 -f

Steps (restic file-level)

  1. Restore ~/nextcloud/db and ~/nextcloud/config from snapshot to a temp path.
  2. Stop stack: docker compose down.
  3. Replace directories carefully; fix ownership if required by the postgres image user.
  4. docker compose up -d and run pg_isready.

Verify

bash
docker exec nextcloud-db-1 pg_isready -U nextcloud
curl -sI https://cloud.cadenceworks.tech | head -5

Log in as a known user and open a recent file.

Northeast Systems · Aux Server · Infra Server