Major Version Upgrades and Data Migration for Containerized Applications
A practical playbook for self-hosted, container-orchestrated apps: backup and rollback first, run a new release in parallel, merge config carefully, migrate stateful data once, then validate in layers before restoring traffic.
Major Version Upgrades and Data Migration for Containerized Applications
A major version upgrade is not “overwrite files and restart.” For self-hosted systems running under container orchestration, a main-version jump usually touches the application image, configuration contract, database schema, extension mechanism, cache format, async jobs, file storage paths, health checks, reverse proxy, and permission model. A miss on any of those can leave the service “up” but unusable, data unmigrated, extensions broken, or rollback hard.
The following is a general approach for upgrading a self-hosted containerized application to a new major version. Version numbers, paths, image names, and service names are placeholders. Follow the target release notes, migration notes, and your actual deployment layout.
1. Principles and boundaries
Establish four principles before you change anything:
- Backup before change. Any database change, directory swap, or config edit needs a recoverable, consistent backup first.
- Rehearse before production. When possible, run the full migrate-and-verify path in a test environment.
- Migrate, verify, then ramp traffic. Do not send all traffic until health checks pass on the new version.
- Keep a rollback point before irreversible steps. Especially schema migrations: once the new version writes a new data format, switching back to the old directory may not restore the business.
Separate stateless from stateful. Images, frontend static assets, and API processes can usually be redeployed. Databases, object-storage attachments, caches, queues, search or vector indexes, and extension config carry real business state. The hard part of a major upgrade is usually not replacing the image; it is compatible migration of that state.
2. Pre-upgrade assessment and checklist
1. Read release notes and migration notes
Look for: new or deprecated environment variables; renamed config fields; required database migrations; extension or plugin API changes; async job format changes; file storage path changes; default ports, health-check paths, or start commands; whether you must upgrade through an intermediate version.
If notes are incomplete, fill gaps by comparing new vs. old config templates, database migration scripts, migration version numbers in startup logs, and API compatibility notes. Do not guess on irreversible operations.
2. Inventory current runtime state
Record at least: current image tag or digest; orchestration and env files; volume mount paths; database version and data volume; object storage or file directories; extension list; scheduled jobs; reverse-proxy rules; current health-check results; critical business functions.
You will need this for migration, rollback, and incident response.
3. Capacity and maintenance window
A major upgrade may need extra disk for old directories, new packages, images, and database backups, plus rollback space. Prefer an off-peak window. Name an upgrade owner, a business validator, and a rollback decision-maker.
4. Prepare a test environment
It need not be a full production clone, but it should include typical business objects, attachments, permission relationships, extension config, and sample async jobs. Backup, migrate, verify, and rollback there first to catch most compatibility issues.
3. Step one: full, verifiable backups
Backup is not copying one install directory. Cover:
- App deploy directory, orchestration files, env files, start scripts
- Current image tag or digest
- Consistent database snapshot
- File volumes, attachment directories, object-storage inventory
- Unprocessed cache and queue work
- Extensions, plugins, or custom components
- Reverse proxy, auth, certificates, and domain-related config
- Current version, migration version, and key log snippets
If the database is still writing, a file copy can be inconsistent. Enter maintenance mode or pause writes, then snapshot. Combine logical export and physical snapshot as needed, and record checksums.
Example:
APP_ROOT=/path/to/appBACKUP_ROOT=/path/to/backupSTAMP=$(date +%Y%m%d-%H%M%S)mkdir -p "${BACKUP_ROOT}/${STAMP}"cp -a "${APP_ROOT}" "${BACKUP_ROOT}/${STAMP}/app-dir"# Also archive: orchestration files, env files, image tags,# database snapshot, volume snapshot, object-storage inventory, extension list
After backup, verify restore: files readable, DB snapshot mountable or importable, key attachments present. An unverified backup is not a rollback point.
4. Step two: prepare the new version in parallel—do not overwrite the old tree
Copying new files over the old directory can work in simple cases, but it is risky: a missed config merge, wrong mount, or failed migration leaves the old tree already overwritten.
Prefer parallel directories plus a switch (or a dedicated release directory). Leave the old version in place. Unpack the new version into its own directory, merge config, validate migration, then point the service at the new path.
Example:
ROOT=/srv/myappOLD_VERSION=<old-version>NEW_VERSION=<new-version>mkdir -p "${ROOT}/releases" "${ROOT}/backups"# Unpack the new package into ${ROOT}/releases/${NEW_VERSION}diff -ru "${ROOT}/releases/${OLD_VERSION}" \"${ROOT}/releases/${NEW_VERSION}" | less
Focus the diff on:
- New env templates
- Added or removed config keys
- Start command, working directory, ports, health checks
- Volume mounts and permissions
- DB migration scripts or init jobs
- Extension service URLs and auth fields
- Reverse-proxy keep-alives, timeouts, upload size limits
- Log, cache, and temp directories
Do not overlay old config wholesale onto the new version, and do not blindly replace all old config with the new template. Use the new template as baseline, merge required old values, and fill new required fields.
5. Step three: pre-pull images and check runtime architecture
Image pull is often the slowest step. Do it before the maintenance window. Confirm architecture match, pin tags, and record digests.
NEW_VERSION=<new-version>for IMAGE in \"<core-api-image>:${NEW_VERSION}" \"<async-worker-image>:${NEW_VERSION}" \"<frontend-image>:${NEW_VERSION}" \"<extension-image>:${NEW_VERSION}"do[pull image using your container runtime] "${IMAGE}"done
In production, pin tags or digests; avoid floating tags during the window. On multi-node setups, ensure every node has the image, or that the platform can pull quickly from the registry.
Also check CPU architecture, storage driver, network mode, mount permissions, and port conflicts. Images that work on a laptop often fail on servers because of arch or file-permission mismatches that were never checked here.
6. Step four: merge config and update orchestration
1. Environment variables
Fill new required variables before start. Deprecated variables may stay temporarily and be cleaned after verification. Inject secrets via env files or a secrets manager; do not commit them to a public repo.
2. Volume mounts
Major versions may change directory layout. Keep old data mounted where the new version expects it, and check owner and read/write permissions. If the container runs as non-root, wrong host permissions can yield a “healthy” process that cannot upload attachments.
3. Health checks and start order
The new version may add dependency checks. Confirm start order and readiness for database, cache, queue, object storage, and extensions. Do not treat “main process exists” as enough; dependencies must be ready.
4. Reverse proxy
Check streaming responses, long-lived connections, larger uploads, longer timeouts, and CORS. If the frontend uses new static paths, confirm cache and compression settings.
7. Step five: standard cutover sequence
Suggested order:
- Announce maintenance; enter read-only or maintenance mode
- Pause scheduled jobs; wait for long-running work to finish
- Stop all old write instances
- Take a final incremental backup
- Switch the service directory to the new release
- Start dependencies
- Run one-shot database migration or init
- Start core API, frontend, and async workers
- Health checks and business verification
- Restore traffic and jobs gradually
- After a soak period, clean old images and temp files
Directory switch example:
ROOT=/srv/myappNEW_VERSION=<new-version>[stop all old write services][final database snapshot and directory backup]ln -sfn "${ROOT}/releases/${NEW_VERSION}" "${ROOT}/current"[start dependencies with the new compose/orchestration][run new-version migration][start core services and async workers]
For multi-replica deployments, run the database migration once, using a migration lock or a dedicated init job. Do not accept write traffic until migration finishes.
8. Data migration is the real work
Treat data in classes:
- Relational business metadata, config, users, permissions, history
- Attachments, import/export files, static assets in volumes or object storage
- Cache: sessions, query results, page data
- Queue: async jobs, events, retries
- Search indexes, vector indexes, or other derived data
- Extension/plugin config and credentials
Strategy: do not lose source data; derived data can be rebuilt; migration should be repeatable; verification should be measurable.
A generic flow:
- Baseline: row counts, attachment counts, index document counts, queue depth, sample business objects
- Maintenance mode: pause writes so data does not change mid-migration
- Consistent backup: database, files, necessary queue state
- Schema migration: run once; record version and logs
- Rebuild derived data: search/vector indexes, cache—prefer rebuild from source
- Validate source data: counts, key fields, readable attachments
- Sample business path: create, edit, query, delete or archive
- Restore traffic: small share first, then ramp
- Keep old snapshots through the observation window
Pseudo-flow:
[enter maintenance mode and pause writes][consistent database backup][new-version schema migration][required data transforms][rebuild search or vector indexes if applicable][flush cache and warm as needed][record migration version, row counts, duration, and error logs]
If the extension model changed, disable incompatible extensions, upgrade the core, then restore them against the new APIs. Recheck auth, callbacks, and permission scopes.
9. Step six: layered verification
Do not stop at “the homepage loads.”
1. Processes and logs
Core, async, and extension services stay up. Watch for DB connection errors, failed migrations, permission denials, incompatible extensions, missing routes.
2. Health checks
Health endpoints, dependency connectivity, DB pool, cache, queue depth, object-storage read/write.
3. Core business
Login and auth, create objects, save edits, list queries, upload/download, workflows or jobs, history, permission isolation, import/export. Use more than one admin account; sample different roles.
4. Async jobs
Enqueue a job, wait for completion, check backlog, retries, and failure logs. Jobs often break on message format, serialization, or extension APIs.
5. Data consistency
Compare pre/post row counts, attachment counts, sample records, file paths, and permission relations. Confirm search or vector indexes retrieve correctly.
6. Performance and stability
Error rate, latency, resource use, slow queries, queue buildup. Empty caches after a major upgrade often cause a short load spike; plan warmup and rate limits.
10. An executable rollback plan
Rollback is not only “point at the old directory,” especially after a schema migration. Define triggers in advance: core features down, migration failure, severe data mismatch, sustained API error rate, critical extensions incompatible.
Typical steps:
- Stop new-version write services
- Record incremental data produced on the new version
- Restore the consistent database snapshot
- Restore file or object-storage snapshot
- Clear new-version cache and queue data
- Switch back to the old release directory
- Start old-version services
- Re-run core business checks
- Analyze failure and revise the upgrade plan
If the new version already wrote new data, restoring an old snapshot drops that increment. Stay in maintenance or read-only until core verification finishes. If writes are required, plan incremental export and compensation. Do not let the old version connect to an already-migrated database unless compatibility is confirmed.
11. Common risks and how to avoid them
- Replace files without merging config: missing required vars, wrong ports or mounts
- Skip database migration: process starts, reads/writes fail or old data is invisible
- Unverified backup: rollback discovers the backup is unusable
- Image arch or permissions mismatch: crash loops or failed attachment writes
- No extension compatibility test: core upgrades, extensions fail
- Uncleared async jobs: old-format messages fail or retry forever
- Proxy not updated: long jobs, streams, or large uploads timed out
- Concurrent migration on many replicas: lock conflicts or bad data
- Cleaning old version too soon: no rollback path when issues appear
12. After the upgrade
Update deploy docs and version records, document new and deprecated env vars, archive migration logs and checks, remove unused old images and temp files, and watch for at least one business cycle.
If you already use object storage, logging, monitoring, and secrets management, wire backup archival, log search, alerts, and secret handling through those capabilities. Keep upgrade scripts driven by environment variables and wrapped generic commands so they are not tightly coupled to one runtime.
Closing checklist:
- Recoverable backup taken and verified?
- Old vs. new config and migration notes compared?
- Images pre-pulled; arch, permissions, ports checked?
- Full rehearsal in test?
- Writes paused and pre-migration baseline recorded?
- Database migration run once with full logs?
- Core business, async jobs, extensions, attachments, and permissions verified?
- Rollback triggers and owners defined?
- Old directory, images, and DB snapshot retained?
- Docs updated and follow-up observation scheduled?
A major upgrade is not about clicking a button. It is about turning uncontrolled risk into steps you can verify and reverse: solid backups, accurate config merge, one migration, layered checks, and a rollback you can actually run.
