Skip to content

Upgrading & Migration

This guide is the operator's safe-upgrade protocol. The DB schema advances forward only — there is no automatic down-migration. Restore from backup if you need to go back.

Always back up data/ (or the bamdude_data Docker volume) before any upgrade. Specifically: bamdude.db (or PostgreSQL dump if you run PG), the archive/ directory (3MFs + thumbnails), and the library/ directory.


Before upgrading

The changelog lists what each release changed. The notes below add up: read every one for a release newer than the version you run now. Updating only an image does not apply changed Compose files or configure query statistics on an external PostgreSQL server; see PostgreSQL.

To 0.7.4

  • Everyone signs in again, and API keys are replaced. Sessions, API keys and long-lived camera/monitor tokens now belong to accounts that cannot be recreated. Old API keys (Bambuddy's bb_… keys included) and long-lived tokens are retired at the first start; reissue a key for each integration with only the printers and rights it needs. See API keys and Authentication.
  • Scheduled Git backups wait for an administrator. They stay paused until an administrator saves each configuration again — see Git backup.
  • Rebuild the slicer containers if you run them: cd slicer-api && docker compose --profile all build --no-cache && docker compose --profile all up -d. The Slice dialog says when they are older than BamDude needs — see Updating the sidecars.
  • The first start runs 62 database migrations (m216–m278). On a large farm database this can take a few minutes; let it finish.

Coming from a version before 0.7.2

  • The first start pauses new work until an operator resumes it. Inspect the farm, then resume new starts; after an unconfirmed shutdown they stay paused until acknowledged. Running prints, completion and table-swap macros carry on. See Farm startup.
  • A failed dispatch halts its printer's queue. Check the printer, Retry the failed job if appropriate, then Resume queue. An attempt that may already have sent its start command is never repeated automatically — see Print queue.

Coming from a version before 0.7.1

  • Swap farms: older archives have an unknown swap declaration. Review the declaration before reprinting them with BamDude's swap macros; queued jobs whose source is unknown may fail before dispatch and need review and Retry. Inspect the plate before resuming a held queue. See Swap mode.
  • STEP previews ship with Docker and the Windows installer; a native install opts in with install/step-preview.sh enable — see STEP previews.

Coming from a version before 0.7.0

Review custom permission groups: Orders, Products, Customers and Stock have independent rights, and filing prints under orders is separate. Integrations creating products from files must read the {product, notes} response described in the API guide. PostgreSQL 18 containers mount their data volume at /var/lib/postgresql, not the old /var/lib/postgresql/data path; keep your existing major version and volume layout when applying an override update.

1. Pre-upgrade checklist

Before touching anything:

  1. Note your current version — open Information (/system) in the web UI, or read the installed version in backend/app/core/config.py for native installs. Useful if you need to roll back.
  2. Back up — see the backup commands below. The UI backup needs BamDude running; a copy of the files needs it stopped (sudo systemctl stop bamdude or docker compose down).
  3. If running behind a reverse proxy (nginx / Caddy / Traefik), copy the config aside so you can verify it after upgrade.
  4. Check log size — if the log directory (logs/ of a native install, the bamdude_logs volume in Docker) is huge, this is a good moment to rotate.

Backup commands

# Data volume — sqlite DB, archives, thumbnails, uploads
docker run --rm \
  -v bamdude_data:/from \
  -v "$(pwd)/backup":/to \
  alpine tar czf /to/bamdude-data-$(date +%Y%m%d).tar.gz -C /from .

# Logs (optional)
docker run --rm \
  -v bamdude_logs:/from \
  -v "$(pwd)/backup":/to \
  alpine tar czf /to/bamdude-logs-$(date +%Y%m%d).tar.gz -C /from .

Open Settings → Backup → Local Backup → Create Backup, then Download Backup to save the zip to your computer. The zip packs the SQLite DB, archive directory, thumbnails, uploads, and config in the same layout install.sh lays out on disk — restore through the backup UI using the backup guide. It also captures encryption-key metadata and scheduled-backup state that a raw tar of data/ leaves behind.

cd /opt/bamdude
tar czf ~/bamdude-data-$(date +%Y%m%d).tar.gz data/
# Use a PostgreSQL client DSN, without SQLAlchemy's +asyncpg driver suffix.
PG_DSN='postgresql://bamdude@your-postgres-host:5432/bamdude'
pg_dump -Fc -f ~/bamdude-$(date +%Y%m%d).dump "$PG_DSN"
# Plus tar up the archive/ + library/ directories from the data volume.

2. Upgrade procedure — Docker

cd bamdude
docker compose pull          # if pinned to :latest
docker compose up -d
docker compose logs -f       # watch migrations apply

Pinning a specific tag in docker-compose.yml is fine and recommended for stable installs — :0.7.4 selects that release; :latest follows the latest stable release tag, while :dev follows beta releases.

# Pinned, recommended
image: ghcr.io/kainpl/bamdude:0.7.4

# Latest stable release
image: ghcr.io/kainpl/bamdude:latest

Watch the startup log for migration progress. Migrations that walk your files log batched progress (e.g. m022 library_files: progress). Wait for Application startup complete. before testing.

Found 3 pending migration(s)
Applying migration 22: label_object_metadata_backfill ...
m022 library_files: progress 100/847 (updated=100, missing=0, unreadable=0)
m022 library_files: progress 200/847 (updated=200, missing=0, unreadable=0)
...
Migration 22 applied successfully
...
Application startup complete.

Sanity-check that http://<host>:8000/health returns 200.


3. Upgrade procedure — Manual (Python venv)

On an install made by install.sh, run the shipped updater, as root:

sudo /opt/bamdude/install/update.sh

It brings the install to the newest commit of the branch it is on (main = the latest stable release), and asks before it changes anything. In order: it checks the install's owner and Python, fetches, asks Install now? (and, if the tree has local edits, whether to overwrite them), stops the service, backs up the data directory, resets the code, installs requirements.lock, refreshes the pinned Node.js for part thumbnails and an enabled STEP component, builds the web interface with npm ci, and starts the service again. If a step after the stop fails, the code goes back to the commit it ran before.

The backup it takes

With the service stopped, the script packs the whole data directory (the database — SQLite or the bundled PostgreSQL — the archive, the library and the key files) and .env into /opt/bamdude/backups/bamdude-data-<timestamp>.tar.gz, leaving out only the regenerable worker cache, and keeps the newest three. Before it stops anything it checks that the copy fits on that disk. A database on a PostgreSQL server of its own is not in the data directory: back it up there (pg_dump). The log ends the step with the two commands that restore the copy.

Variable Default Purpose
INSTALL_DIR /opt/bamdude Where BamDude lives
SERVICE_NAME bamdude systemd unit to stop and start
BRANCH current checked-out branch Update to the head of another branch
BACKUP_DIR /opt/bamdude/backups Where the backups go — point it at a bigger disk if the data does not fit
BACKUP_KEEP_COUNT 3 How many backups to keep
BACKUP_MODE auto auto goes on without a backup when it cannot take one, require stops (nothing changed), skip leaves it out
FORCE 0 1 skips only the question about overwriting local edits

By hand, the same steps for a release tag — as the install's owner, with the service stopped:

cd /opt/bamdude
sudo systemctl stop bamdude

sudo -u bamdude git fetch --tags
sudo -u bamdude git checkout v0.7.4          # the release you want

sudo -u bamdude ./venv/bin/pip install -r requirements.lock

# The release commit carries the built web interface; build only a custom branch.
sudo -u bamdude bash -c 'cd frontend && npm ci && npm run build'

sudo systemctl start bamdude
sudo journalctl -u bamdude -f

The pinned Node.js for part thumbnails is installed by BamDude itself at the next start; an enabled STEP component is refreshed with install/step-preview.sh enable.

While the service is stopped, the script also checks that the unit starts uvicorn with --loop asyncio. Installs created before the installer pinned it (July 2026) never gained the flag, and without it the server runs on uvloop, which can silently truncate Virtual Printer uploads. A plain one-line uvicorn unit gets the flag added (the file is backed up beside itself first); a unit with drop-ins, a wrapper script or a continued command line is left as it is, and the script says what to add by hand. BamDude also logs a warning at startup whenever it finds itself on uvloop.

update.sh runs as the install's owner

update.sh runs git — the rollback included —, pip and npm as the install's owner, and keeps root for systemd only. It used to run git as root in a tree that belongs to the service's user, which git refuses ("dubious ownership"), so on an install made by install.sh the update stopped at its first git command; and root-run writes left root-owned files the in-app update later could not change. It now checks, before anything changes, and stops with the repair named, when:

  • the install's owner is not the user the service runs as (the unit's User=; a unit without one runs as root) — give the install to that user, e.g. sudo chown -R bamdude: /opt/bamdude, or correct the unit's User=, then run the update again;
  • something outside data/, logs/, backups/ and runtime/ belongs to someone else — files an earlier update run as root left behind; the first such file is named, and sudo chown -R bamdude: /opt/bamdude hands them back;
  • the owner of the install, or the unit's User=, cannot be read — the update stops rather than guess;
  • npm runs for root but not for the owner — one from nvm or asdf, say: the frontend is built as the owner, through sudo's own PATH, so install Node.js system-wide (from the distribution or NodeSource);
  • the state of the working tree cannot be read (git status fails as the owner) — the question about local edits is never skipped on a failed read.

An install reached through a symlink is checked through the link: the owner and the files are the tree's.

The update never changes ownership on its own.

The STEP preview component on update

Updates keep an enabled STEP preview component current: update.sh and an update from Settings refresh it, never install one you declined, and never fail because of it. update.sh removes the older version of the component last, just before it starts the service again, and only when it can prove the service stopped — right after the stop and again then (cgroup v2: the unit's group is empty); otherwise it keeps it and says so. The version the code before the update runs on is always kept — a failed build or a failed start rolls the code back to it — and goes with the next update. A refresh that fails ends in STEP preview update failed; run install/step-preview.sh status to see why. — the update itself goes on. An update from Settings says The STEP preview component was not updated (reason); BamDude itself was. under its result; the reasons and their repairs are in Installation → STEP previews.


4. Upgrade procedure — In-app updater (Settings → General)

For native installs the easiest path is the in-app updater. Settings → General → Updates, under BamDude Software: Check now shows the latest release, and Install Update does the full sequence without leaving the UI: it fetches the release tag and resets the code to it, installs requirements.lock, refreshes the pinned Node.js for part thumbnails and an enabled STEP component, and, when npm is available, rebuilds the web interface and the AI client packages with npm ci, as update.sh does. It makes no backup — make one first — and it does not restart BamDude: restart the service when it says Update complete (sudo systemctl restart bamdude).

Toggles in the same panel:

  • Check for updates — turn off to stop GitHub polling entirely.
  • Include beta versions — surface vX.Y.ZbN releases too. Off by default. The updater respects either the version-name convention OR GitHub's prerelease flag, so a release explicitly marked prerelease in the GitHub UI is also gated behind this toggle.

Docker installs reject the in-app Install Update button — running git fetch / pip install / npm build inside a live container would corrupt the image. Instead, the panel surfaces two side-by-side blocks with the resolved tag pre-filled: image-based (pull && up -d with the right image: line, including a beta-specific hint that :latest doesn't track betas), and source-build (git fetch --tags && git checkout v<tag> && compose build --pull && up -d). Copy-paste either block depending on your install shape — full reference in System Info → Update checker.

The in-app updater is hardened against the pre-release tag mismatch that 0.4.3-and-earlier silently fell into: clicking Install Update on a beta release used to no-op because the apply path hard-reset to origin/main, which doesn't carry the beta tag. Fixed in 0.4.4.


5. Migration overview — what each version changes

BamDude records applied migrations in the _migrations table. The first start after an update runs every pending migration in order and logs each one as Applying migration N: name ...; let it finish before you stop the service. The schema moves forward only. A fresh install creates its tables from the current models, marks m000 and m001 as applied and runs the rest.

What each migration changes, and why, is written in its own docstring in backend/app/migrations/. The table says which release brought which migrations, so you can tell how many will run when you skip releases.

Release Migrations Count
0.3.2 m000–m009 10
0.4.0 m010–m021 12
0.4.1 m022–m023 2
0.4.2 m024–m041 18
0.4.3 m042–m045 4
0.4.4 m046–m059 14
0.4.5 m060–m082 23
0.4.6 m083–m085 3
0.5.0 m086–m112 27
0.5.1 m113–m114 2
0.5.1.2 m115–m119 5
0.5.2 m120–m133 14
0.5.3 m134–m136 3
0.5.4 m137–m141 5
0.5.5 m142–m156 15
0.6.0 m157–m179 23
0.6.1 m180–m181 2
0.7.0 m182–m194 13
0.7.1 m195–m204 9
0.7.2 m205–m208 4
0.7.3 m209–m215 7
0.7.4 m216–m278 62

The numbers m196 and m236 were never used; the counts leave them out.

Migrations that work on your files

Most migrations change the database only and finish in moments. These open every file they concern, so on a large archive or library the first start after crossing them takes noticeably longer. Each runs once.

Migration Release What it does
m022 0.4.1 Reads each 3MF's object-label flags, for skipping objects.
m023 0.4.1 Reads each 3MF's per-plate breakdown, for the plate gallery.
m038 0.4.2 Finds which plate of a multi-plate archive was printed.
m057 0.4.4 Reads each archive's build-plate type.
m114 0.5.1 Reads skip-objects support and the object counts of library files and archives.
m121 0.5.2 Reads each archive's bed temperature.
m132 0.5.2 Reads the layer count of each plate of a library file.
m137 0.5.4 Checks whether each 3MF in the library is sliced (the file list inside the ZIP only).
m177 0.6.0 Moves archive/library, archive/projects and archive/products to their own folders in the data directory. A name present on both sides, or a move across devices, stops the start with the path in the message; nothing is copied or deleted, so resolve it and start again.

5. Notable upgrade paths

From Bambuddy HE 3.0.x → BamDude 0.4.x

Your bambuddy.db is BamDude's own — the startup rename turns it into bamdude.db, m002 adapts the schema, m005+ are BamDude-native. (This is unaffected by the removal of the Bambuddy v0.2.2.2 import in 0.6.0; that only ever concerned upstream's files.)

Docker: the old install's volumes are named bambuddy_he_*, which the BamDude compose does not mount. Before the first start, run bash install/migrate-volumes.sh once from the folder that holds BamDude's docker-compose.yml: it copies them into the volumes Compose mounts there (<folder>_bamdude_data, <folder>_bamdude_logs) and keeps the old ones. For a plain docker run install, set NEW_DATA=bamdude_data NEW_LOGS=bamdude_logs; if the old volumes have other names (docker volume ls), set OLD_DATA / OLD_LOGS.

Always upgrade to 0.4.0.1 or later

Going from a legacy 3.0.1 install straight to 0.4.0 crashed at m005_swap_profiles.seed() with no such column: printers.awaiting_plate_clear — the seed used ORM select(Printer) which loaded every column from the current model, including columns that don't exist yet at m005's point in the chain. Fixed in 0.4.0.1 by rewriting the seed to use raw SQL with explicit column lists.


Coming from Bambuddy

Not supported since 0.6.0. BamDude forked from Bambuddy at v0.2.2.2 and the two schemas have diverged far past the point where a one-time import could be trusted, so the importer was removed.

Start BamDude with an empty data directory and re-add your printers and spools.

A bambuddy.db left sitting in the data directory is not read and not touched. BamDude's startup names it in the log on every start, so you can see it was found and ignored; remove it yourself once you no longer need it.

This is not the same as upgrading from Bambuddy HE / BamDude 3.0.x

Those are BamDude's own lineage, and they are still supported — see Notable upgrade paths above. A bambuddy.db written by BamDude 3.0.1 is recognised as BamDude's own and renamed to bamdude.db, exactly as before.


Switching install method

You can change install method at any time without touching data — just point the new instance at the existing data/ directory or copy the volume contents.

Native → Docker

sudo systemctl stop bamdude

# Copy native data into a Docker volume
docker volume create bamdude_data
docker run --rm \
  -v /opt/bamdude/data:/from \
  -v bamdude_data:/to \
  alpine cp -a /from/. /to/

# Start the GHCR image against the new volume
docker run -d --name bamdude --network host \
  -v bamdude_data:/app/data -v bamdude_logs:/app/logs \
  --restart unless-stopped ghcr.io/kainpl/bamdude:latest

# Only after you've verified the Docker instance works, disable/remove the native service:
sudo systemctl disable bamdude

If the native install runs on DATABASE_URL=embedded, don't copy data/: Docker cannot run the bundled server, so the container would start as a fresh SQLite install. Take a Settings → Backup ZIP instead and restore it into the Docker instance, or point Docker at a PostgreSQL server.

Docker → Native

docker compose down

# Copy the volume out to disk (use your volume's real name: docker volume ls)
docker run --rm \
  -v bamdude_data:/from \
  -v /var/lib/bamdude:/to \
  alpine cp -a /from/. /to/

# Install native pointing at the copied data
curl -fsSL https://raw.githubusercontent.com/kainpl/bamdude/main/install/install.sh -o install.sh
sudo bash install.sh --data-dir /var/lib/bamdude --yes

Docker Hub → GHCR (or vice versa)

Registry swap only, no data touch:

# docker-compose.yml
# image: kainpl/bamdude:latest      ← Docker Hub
# image: ghcr.io/kainpl/bamdude:latest  ← GitHub Container Registry
docker compose pull
docker compose up -d

Both registries publish the same tags. GHCR is the preferred source (built in CI on every release); Docker Hub is a mirror.


6. Post-upgrade verification

After the service is back up:

  1. curl http://<host>:8000/health returns {"status":"healthy"}.
  2. Information page → version reflects the new release.
  3. Connect to a printer that was working pre-upgrade — should reconnect within 30 seconds; check the printer card on the Printers page.
  4. Open the latest few archives — thumbnails should still render, the 3D preview should work, the printer-icon click should jump to the owning printer.
  5. Trigger a queue dispatch on two printers at once — the bottom-right toast should show both jobs progressing in parallel. The DB-insert phase is briefly serialised (startup-lock), but FTP upload + start happen concurrently. See Per-Printer Queues → Dispatch behaviour.
  6. Log in again — needed after 0.3.x → 0.4.x and after any upgrade to 0.7.4 from an earlier version. On 0.7.4, also reissue retired API keys and long-lived tokens (see To 0.7.4).

Migration log fragments to grep for:

INFO  [backend.app.migrations] Found 3 pending migration(s)
INFO  [backend.app.migrations] Applying migration 278: <name> ...
INFO  [backend.app.migrations] Migration 278 applied successfully
INFO:     Application startup complete.

Failure indicators:

ERROR  [backend.app.migrations] Migration 278 failed during DDL (OperationalError)
sqlite3.OperationalError: no such column: ...

no such column / no such table on startup almost always means a migration didn't run — usually a filesystem permissions issue on data/. Fix with sudo chown -R bamdude:bamdude /opt/bamdude/data and restart.


7. Rollback (if things break)

Because the schema advances forward only, the rollback plan is always restore the pre-upgrade backup. There is no automatic down-migration — you can't, for example, "undo" m019's archive↔queue refactor in place. Restoring a backup is the only path.

docker compose down

# Wipe the new volume contents
docker volume rm bamdude_data
docker volume create bamdude_data

# Restore from backup tarball
docker run --rm \
  -v "$(pwd)/backup":/from \
  -v bamdude_data:/to \
  alpine sh -c 'cd /to && tar xzf /from/bamdude-data-YYYYMMDD.tar.gz'

# Pin compose to the previous Docker tag before starting:
# image: ghcr.io/kainpl/bamdude:<previous-version>   # e.g. 0.7.3
docker compose up -d

On a fresh install of the older tag, after first-run setup, open Settings → Backup → Local Backup → Restore Backup → Restore, pick the downloaded zip, then restart the service. The zip restores DB + archives + uploads + config in one go.

sudo systemctl stop bamdude
cd /opt/bamdude
sudo rm -rf data
sudo tar xzf ~/bamdude-data-YYYYMMDD.tar.gz
sudo -u bamdude git checkout v<previous-version>   # the version that made the backup
sudo -u bamdude ./venv/bin/pip install -r requirements.lock   # requirements.txt on a tag without the lock
sudo systemctl start bamdude
docker compose down       # or stop the native service
pg_restore -c -d "$DATABASE_URL" ~/bamdude-YYYYMMDD.dump
# Then restore archive/ + library/ from the data tarball.
docker compose up -d      # with image pinned to the previous tag

The version you roll back to must be the one that created the backup — otherwise the schema in the DB will be newer than what that code expects, and startup fails with a column-not-found error on the first read.

Forward-only is intentional

Down-migrations would need code paths that BamDude doesn't carry — restoring from a backup is structurally simpler and always correct. Every release keeps its :X.Y.Z image tag and vX.Y.Z git tag, so you can always return to the version that made your backup.


8. Database backend notes

SQLite (default)

The DB file lives at data/bamdude.db. SQLite pragmas: WAL journal, 15 s busy timeout, NORMAL synchronous. WAL means there's also bamdude.db-wal and bamdude.db-shm next to the main file — back up all three together (or stop the service first so the WAL is checkpointed into the main file).

If a bambuddy.db (or bambutrack.db) written by BamDude 3.0.1 is in the data directory, BamDude recognises it as its own and renames it to bamdude.db on start, before any migration runs — that is how native installs swapping the binary in-place carry their data forward. It takes the place only of an empty bamdude.db: when the bamdude.db already there holds data, that database stays in use, the 3.0.1 file is left untouched, and every start names it in the log as not in use — remove it once you no longer need it. An upstream Bambuddy file is neither renamed nor read; see Coming from Bambuddy.

PostgreSQL — bundled or your own

DATABASE_URL has three states, and switching between them is a migration in its own right:

DATABASE_URL Backend
empty / unset SQLite at data/bamdude.db
embedded the PostgreSQL 18 bundled with BamDude, under DATA_DIR/postgres/18
postgresql+asyncpg://… your own server

Existing PostgreSQL installs run the same migration chain on every boot — same _migrations table, same versions, same sequencing. The dialect helpers route DDL through PG-native paths where SQLite needs recreate_table (FK changes, column drops), and PG enforces FK constraints SQLite lets pass silently (m018 is a good example, where SET NULL only really bites on PG).


Moving from SQLite to PostgreSQL

This is a one-shot automatic copy, the same for the bundled server and your own.

  1. Back up first (see Backup commands). This is the one step nothing does for you.
  2. Set DATABASE_URL — embedded, or your server's URL. For an external server the database must already exist; BamDude creates tables, not databases.
  3. Restart BamDude.

On that start BamDude sees a PostgreSQL with no printers table content (i.e. a fresh database) next to an existing bamdude.db, and copies everything across. In the log:

Found local SQLite database: /…/bamdude.db - migrating to PostgreSQL...
...
SQLite → PostgreSQL migration complete (N tables). Original renamed to bamdude.db.migrated

The file is copied as it is, at its own migration level, so only the migrations it had not reached yet run afterwards, and the app comes up. On a real farm's data the copy takes on the order of a minute or two; the schema chain afterwards is what you usually wait for.

What the copy does

Every table and row moves, with type conversion (SQLite 0/1 → boolean, datetime strings → timestamps). Auto-increment sequences are reset to the right values, and the full-text index is rebuilt as PostgreSQL tsvector + GIN. The migration history (_migrations) comes along. After the chain, the constraints SQLite never enforced (foreign-key rules, NOT NULL, UNIQUE, CHECK) and the full-text index are added. FTS5 virtual tables and WAL/SHM files are not copied — they are SQLite-specific.

Orphan rows are removed or unlinked, and it is logged

PostgreSQL enforces foreign keys that SQLite never did, so rows pointing at records that no longer exist cannot come across. The importer deletes them — or, where the reference may be empty, clears it — and says exactly what it did, for example:

Purged 3 orphaned row(s) in label_jobs (dangling print_archives reference)
Nulled 5 orphaned row(s) in spool_usage_history (dangling spool reference)
Import repaired orphaned rows the source database was carrying: …

This is by design — those rows were already unreachable. Read the lines; if a count looks wrong for your install, stop and restore the backup rather than carrying on.

A failed import aborts the start — it does not fall through

If the copy fails part-way, BamDude stops with an error instead of continuing as a fresh install. PostgreSQL is left as it is and bamdude.db is not renamed, so your SQLite data is untouched and you can simply unset DATABASE_URL and restart to get back exactly where you were. (Older builds could silently continue with an empty database — hence the rename happening only after a fully successful copy.)

Once the copy has committed, the last step — adding the constraints — is owned by a repair record that survives restarts. If it fails, BamDude stays in maintenance (only /health answers, with 503) until it succeeds. With BamDude stopped, python -m backend.app.cli schema_repair status shows what is pending and schema_repair retry runs it again.

Going back to SQLite

Unset DATABASE_URL (or set it empty) and rename the file back:

mv data/bamdude.db.migrated data/bamdude.db

Anything created after the switch lives only in PostgreSQL, so take a backup from the running PostgreSQL instance first if you want to keep it — the UI backup format is portable and restores onto either backend.

The bundled server (DATABASE_URL=embedded) on upgrades

Path What it holds
DATA_DIR/postgres/18/ the cluster, in a directory named after the PostgreSQL major
DATA_DIR/postgres/password the generated password (mode 0600)
DATA_DIR/postgres/port the port it settled on, unless you pinned EMBEDDED_PG_PORT

Back these up together with the rest of data/ — the cluster is just files in your data directory, so a tar of data/ with the service stopped is a valid copy. For a portable copy that restores onto any backend, use Settings → Backup instead.

The PostgreSQL major is pinned

BamDude refuses to open a cluster created by a different PostgreSQL major and says so plainly rather than touching the data:

the data directory ... was created by PostgreSQL 17, but the bundled server is
PostgreSQL 18. Refusing to start: a major upgrade needs a migration step, not a
silent open.

A future major ships as its own release with an explicit migration step. Routine BamDude upgrades within the same major need nothing from you.

Upgrade with the server stopped

On a native install, pip install -r requirements.lock cannot replace the bundled PostgreSQL package while a server from it is still running — stop BamDude (which stops the server) before updating dependencies. install/update.sh already stops the service first.

Windows: the two service layouts

The Windows installer offers the bundled server either as its own BamDudePostgres service (started before BamDude by the service manager) or as a child of BamDude. Re-running the installer keeps whichever you already use — it reads the current backend from the installed service's environment and preselects it, so an upgrade never quietly moves you back to SQLite. Uninstalling stops and removes both services, and asks separately (defaulting to No) whether to delete your data.

Docker

  • DATABASE_URL=embedded is not available in Docker — use the PostgreSQL container below or your own server. The shipped compose file allows 60 s on docker compose down so BamDude closes its database cleanly — don't shorten that.
  • For PostgreSQL in its own container, use the shipped docker-compose.postgres.yml override. Mind the host-networking note in PostgreSQL Support: with the default network_mode: host, BamDude cannot reach another container by its Compose name.

9. Data persistence — "new container started empty"

The most common upgrade-time disaster is starting a fresh BamDude container and finding no printers, no archives, no settings — like a clean install. The data is almost never actually gone; it's still in a Docker volume or container layer that the new instance isn't reading from. This section walks every cause we've seen and the fix for each.

Quick diagnostic

Run this on the host and read back what it prints. It enumerates BamDude-related containers, every volume that could plausibly hold data, the size of each volume, and the mount layout of any "old" container you kept around as a backup.

echo "=== Containers ==="
docker ps -a --format "table {{.Names}}\t{{.Image}}\t{{.Status}}\t{{.CreatedAt}}" \
  | grep -iE "bamdude|bambuddy"
echo

echo "=== Volumes ==="
for v in $(docker volume ls -q | grep -iE "bamdude|bambuddy"); do
  size=$(docker run --rm -v "$v":/d alpine du -sh /d 2>/dev/null | awk '{print $1}')
  printf "%-50s  %s\n" "$v" "$size"
done
echo

echo "=== Old container mounts (replace 'bamdude-old' with the actual name) ==="
docker inspect bamdude-old --format '{{range .Mounts}}{{.Type}}: {{.Source}} → {{.Destination}}{{"\n"}}{{end}}'
echo

echo "=== Old container DATA_DIR contents ==="
docker exec bamdude-old sh -c 'echo "DATA_DIR=$DATA_DIR"; ls -la "$DATA_DIR" 2>/dev/null | head'

A healthy data volume is tens of MB minimum (SQLite + thumbnails) and typically GBs with archive history. A fresh / empty volume is a few hundred KB at most. That contrast usually pinpoints where the data lives in two seconds.


Scenario A — Compose project name changed (most common)

Docker Compose v2 namespaces every named volume by the project name, which by default is the basename of the directory the compose file lives in. The volume entry that reads bamdude_data in your docker-compose.yml becomes <project>_bamdude_data on disk:

Setup Real volume name
~/bambuddy/docker-compose.yml (upstream Bambuddy) bambuddy_bambuddy_data
~/bamdude/docker-compose.yml bamdude_bamdude_data
~/bamdude-new/docker-compose.yml bamdude-new_bamdude_data
~/3d/bamdude/docker-compose.yml (with COMPOSE_PROJECT_NAME=3d) 3d_bamdude_data

Renaming the compose folder (mv ~/bamdude ~/bamdude-old) and unpacking a fresh checkout at the original path therefore creates a brand-new namespace, and docker compose up -d provisions an empty bamdude_bamdude_data while your real data sits in bamdude-old_bamdude_data. Both volumes show up in docker volume ls; only one has the data.

Fix — point the new project at the existing volume:

The cleanest path is to declare the existing volume as external in the new compose file so Docker Compose doesn't try to manage it:

services:
  bamdude:
    # ... unchanged ...
    volumes:
      - bamdude_data:/app/data
      - bamdude_logs:/app/logs

volumes:
  bamdude_data:
    external: true
    name: bamdude-old_bamdude_data    # the volume that has your data
  bamdude_logs:
    external: true
    name: bamdude-old_bamdude_logs    # likewise for logs

After docker compose up -d, the new container reads/writes the same physical volume the old one used. Once you've verified everything works, you can stop the old container and free its name.

Or — copy the data into the new volume:

If you'd rather keep the new project's namespacing clean and end up with a single <new>_bamdude_data volume:

# Stop the new container so it doesn't race the copy.
docker compose down

# Recreate the (empty) target volume just to be safe.
docker volume rm <new>_bamdude_data
docker volume create <new>_bamdude_data

# One-shot copy with a throw-away alpine container that mounts both volumes.
docker run --rm \
  -v bamdude-old_bamdude_data:/from:ro \
  -v <new>_bamdude_data:/to \
  alpine sh -c 'cp -a /from/. /to/'

# Start the new compose project.
docker compose up -d

Scenario B — Container layer (no volume at all)

If the original install was a bare docker run ghcr.io/kainpl/bamdude:latest without a -v bamdude_data:/app/data flag, all writes landed in the container's writable layer. Renaming that container with docker rename preserves the layer (and therefore the data), but starting a fresh container from the same image creates a new layer. New layer = no bamdude.db, no archives.

You can detect this by running docker inspect <old_container> and checking .Mounts. If there's no entry mounting /app/data, the data is in the layer.

Fix — extract the data, then move to a proper volume-backed setup:

# Copy the data out of the old container's layer onto the host.
docker cp bamdude-old:/app/data ./bamdude-data-recovered

# Create a proper named volume and seed it.
docker volume create bamdude_bamdude_data    # match your new project's namespace
docker run --rm \
  -v "$(pwd)/bamdude-data-recovered":/from:ro \
  -v bamdude_bamdude_data:/to \
  alpine sh -c 'cp -a /from/. /to/'

# Use the official compose file — it always declares a volume.
cd ~/bamdude
docker compose up -d

Going forward, always declare a volume (named or bind-mount) for /app/data and /app/logs. The shipped docker-compose.yml does this; raw docker run commands need an explicit -v.


Scenario C — Bind-mount path changed

If your compose used a bind-mount (./data:/app/data or /srv/bamdude:/app/data) instead of a named volume, moving the compose folder also moves the bind-mount target. The new install lands at a fresh empty path.

volumes:
  - ./data:/app/data    # path is RELATIVE TO THE COMPOSE FILE

Detect with docker inspect <container> --format '{{range .Mounts}}{{.Source}}{{"\n"}}{{end}}'. If a /srv/... or /home/... host path appears, that's where the data really is.

Fix — copy the host directory into the new location, or point the new compose at the old path:

# Option 1: relocate the bind directory.
mv ~/bamdude-old/data ~/bamdude/data
docker compose up -d

# Option 2: keep the data where it is, point the new compose at it.
# Edit volumes: in docker-compose.yml to use the absolute old path:
#   - /home/user/bamdude-old/data:/app/data
docker compose up -d

Scenario D — PUID / PGID mismatch (data is there but the app can't read it)

The shipped compose runs BamDude as ${PUID:-1000}:${PGID:-1000} (the entrypoint drops to it). If your old container ran as 1000:1000 and the new run uses different IDs (e.g. you set PUID=$(id -u) in a shell where id -u != 1000), the volume's files belong to a UID the new process cannot read or write. Symptoms vary:

  • Startup logs show PermissionError: [Errno 13] Permission denied: '/app/data/bamdude.db'
  • Or the app silently falls back to a fresh DB next to the unreadable old one
  • Or init_db fails on the first migration write

Check ownership with:

docker run --rm -v bamdude_bamdude_data:/d alpine ls -ln /d

The numeric UID / GID in the third and fourth columns must match what id -u / id -g returns for the user the new container runs as.

Fix — chown the volume contents to the new IDs:

docker compose down
docker run --rm -v bamdude_bamdude_data:/d alpine chown -R 1000:1000 /d
# Or whatever PUID:PGID your compose uses now.
docker compose up -d

On every start the entrypoint gives /app/data and /app/logs to PUID:PGID when their top-level owner differs, so a changed PUID/PGID fixes itself on the next start. You need the chown above only when the container runs with user: / --user (the entrypoint then cannot chown) or when only files below the top level are mis-owned.


Scenario E — docker compose down -v (volumes deleted)

The -v flag on docker compose down permanently removes the project's named volumes. If you ran this before the upgrade ("just to be safe"), the data is gone from Docker's perspective — there is no Recycle Bin. The renamed-old container only helps if it was started with a bind-mount (host directory survives) or kept its data in the container layer (Scenario B).

Sanity check: docker volume ls | grep bamdude should show the old volumes too if they exist. If only the freshly created ones appear and none has the GB-scale size, the data was deleted.

Recovery — restore from the application-level backup:

The only reliable recovery in this case is the BamDude UI backup zip, which you should have pre-upgrade per §1. The flow:

  1. Bring the new BamDude up (it lands in the setup-required state).
  2. Complete first-run setup with throwaway credentials — the next step replaces the DB anyway.
  3. Open Settings → Backup → Local Backup → Restore Backup → Restore and pick the pre-upgrade zip.
  4. Restart the container so the migration system reconciles against the restored DB.

This restores bamdude.db, archives, library files, thumbnails, uploads, and every Settings row. Encrypted secrets (TOTP, OIDC client_secret) restore correctly because the backup carries the key file .mfa_encryption_key. If you pin MFA_ENCRYPTION_KEY in the environment, it overrides that file and must be the same key, otherwise those rows will fail to decrypt.

If you have no backup and none of the prior scenarios apply, the data is unrecoverable.


Scenario F — Container manager UI (Portainer / Dockge / Komodo) creates its own namespace

GUI Docker managers often create their own Compose project on import — Portainer's "stacks" become projects named after the stack, Dockge mounts each compose under /opt/stacks/<name> and uses that name as the project. Importing the same compose file under a different stack name produces a fresh volume namespace just like Scenario A.

The fix is identical to Scenario A: declare the existing volume as external and point at it by its real name. Run docker volume ls to see what name the GUI created and which one your old install used.


Scenario G — Image moved DATA_DIR between versions (rarely the cause)

BamDude has shipped ENV DATA_DIR=/app/data since the first Docker release and we've never moved it — this scenario is documented for completeness in case you're upgrading from a private fork or a custom image. If you ever moved data into /data instead of /app/data in your own image, the volume mounted at the old path won't be picked up by the new image. Move the data:

docker run --rm \
  -v <volume>:/v \
  alpine sh -c 'mkdir -p /v/app/data && mv /v/data/* /v/app/data/ 2>/dev/null'

Or simply re-mount the volume at the new path the image expects:

volumes:
  - bamdude_data:/app/data    # not /data

Why our legacy-DB rename doesn't always fire

BamDude's startup (migrations/__init__.py) renames bambuddy.db / bambutrack.db to bamdude.db — but only when the file is BamDude's own 3.0.1-era database, which it recognises by the telegram_chats table inside it. A genuine upstream Bambuddy file is left untouched and merely named in the log; see Coming from Bambuddy. For a 3.0.1 file the rename then only fires when the legacy file is inside the new container's /app/data — i.e. when the volume mount is correct — and no bamdude.db holding data is already there. If the new container is reading from a fresh empty volume (Scenarios A, C, D, E), there is no legacy file to rename in the first place; the rename logic is irrelevant.

The fix is always the same shape: get the new container reading from the volume that holds your data, by either pointing at the existing volume (external: true) or copying the data into the new one.


Troubleshooting

Startup log shows setup_required 503s on every endpoint
First boot creates no admin. Open / in a browser to go through the setup flow. This is normal for fresh installs and after every cli reset_admin.
no such column / no such table on startup
A migration didn't run. Check the log for the stack trace; usually it means the file permissions on data/ don't allow the service user to write. Fix with sudo chown -R bamdude:bamdude /opt/bamdude/data.
A Bambuddy database sits in data/ and nothing happened to it
That is now the expected behaviour. The import was removed in 0.6.0 — BamDude's startup names the file in the log on every start and leaves it alone. Nothing will import it; delete it when you no longer need it.
Docker volume copy fails with device or resource busy
Stop both the source and the destination container first. The --rm alpine container mounting both volumes cannot share the filesystem with a running service holding open files.
Native update leaves the service broken
update.sh puts the code back on the previous commit by itself when a step after the service stop fails. If the data needs to go back too, stop the service, empty the data directory and unpack the newest bamdude-data-*.tar.gz from /opt/bamdude/backups/ with the two commands the update logged (see Native update).
Long pause on 0.4.1 first boot
That's m022 walking every 3MF on disk. Tail the log — you should see m022 library_files: progress N/M lines every batch of 100. Don't kill the process; restarting just resumes from where the batch commit left off.
database is locked mid-migration
You started the service before the previous instance fully stopped. Stop, wait for the old process to exit (check with pgrep -f bamdude / docker compose ps), then start again. The migration system is idempotent — failed-mid-run migrations re-run cleanly on next boot.