Cross-Version Upgrades and Reliable Rollback for Local Containerized Applications

    This guide explains how to upgrade locally deployed containerized applications across versions without breaking the system. It covers building a deployment inventory, identifying data stored outside the install directory, creating consistent and restorable backups, avoiding full-overwrite upgrades, treating database migration as a separate risk, starting services in dependency order with business validation, and rolling back the entire system state rather than only the code. Readers will get a repeatable checklist for upgrades that stay version-verifiable, data-recoverable, config-traceable, and result-validated.

    1. The Real Challenge Is State Consistency, Not File Replacement

    For applications deployed locally through container orchestration, an upgrade often looks like just two steps: back up the install directory, then overwrite it with the new version’s files. This only works when data, configuration, and deployment are simple enough. It is not a complete approach for cross-version upgrades.

    A healthy running system is made up of four kinds of state:

    • Application code and deployment files, which determine how services start;
    • Environment configuration and credentials, which determine which resources services connect to;
    • Databases, uploaded files, and indexes, which hold the actual business content;
    • Container images and the runtime, which determine whether the code runs as expected.

    During an upgrade, if any one of these states does not match the others, you can end up with “the container started, but the business is unusable.” For example, new code reads a field that does not exist in the old configuration, or an old application connects to a database whose structure has already changed.

    A more reliable upgrade approach is therefore: first confirm compatibility, then create a recoverable backup, then perform a controlled change, and finally use business validation to decide whether to open the service.

    This article discusses a general method for upgrading local containerized applications. It does not assume that any specific version supports direct upgrading. Before you begin, defer to the target version’s official upgrade notes and compatibility requirements.

    2. Build a Deployment Inventory Before Upgrading

    2.1 Confirm the Version Actually Running

    The source version in the install directory is not necessarily the version of the running service. If the deployment configuration uses a pinned container image, replacing only the source directory may leave the running application completely unchanged.

    Before upgrading, record:

    • The current application version and its image identifier;
    • The location of the orchestration configuration files;
    • How the main services start and how they depend on each other;
    • The current environment configuration file;
    • Persistent directories and data volumes;
    • External access addresses, listening ports, and proxy settings.

    For runtimes that support immutable image digests, save both the version tag and the digest to reduce the risk of inconsistent recovery when a tag changes.

    The inventory is not just a convenience. It gives rollback a clear target: what you restore should be the system that was actually running before the upgrade, not an old directory recalled from memory.

    2.2 Find Data Outside the Install Directory

    The biggest risk of copying the install directory directly is assuming that all data lives inside it.

    Common places data is stored include:

    • A host directory mounted into the container;
    • A separate data volume managed by the container runtime;
    • An external database;
    • Attachments stored in separate file storage;
    • Search or retrieval data kept in a dedicated service.

    Local container runtimes may also store data through a virtualization layer, so the project directory a user sees does not necessarily contain the actual database files.

    It helps to put together a data inventory:

    Data Category What to Confirm Backup Approach
    Database Instance location, data size, recovery requirements Consistent export or a supported physical backup
    Uploaded files Host path or storage location File copy or storage snapshot
    Search index Whether it holds unique data, whether it can be rebuilt Back up, or define a rebuild plan
    Environment config File location, how secrets are stored Keep an encrypted copy of the configuration
    Custom extensions Scope of changes, dependencies Archive separately and verify compatibility

    For indexes that can be rebuilt, also estimate the rebuild time. Theoretically recoverable does not mean recoverable within the allowed maintenance window.

    2.3 Check Cross-Version Upgrade Requirements

    When crossing major versions, do not assume a one-step upgrade is supported. Focus on verifying:

    • Whether upgrading directly from the current version is allowed;
    • Whether an intermediate version is required;
    • Which service performs the database migration;
    • Whether service components are added or removed;
    • Whether configuration keys are renamed, deprecated, or changed in meaning;
    • Whether custom extensions need to be adjusted accordingly;
    • Whether the old version can still run after data migration.

    If you cannot find clear compatibility notes, validate in an isolated environment first. Do not overwrite the only working deployment.

    3. Backups Must Be Consistent and Restorable

    3.1 A Directory Copy Can Be Kept, but It Does Not Replace a Data Backup

    A copy of the install directory is good for preserving orchestration files, environment configuration, and local modifications. It is a valuable first layer of protection. However, copying the underlying files of a running database directly may produce an inconsistent state.

    The reason is that database writes typically involve data pages, transaction logs, and caches. During a copy, individual files may come from different points in time, and even if the directory size looks normal, that does not mean the database can be recovered.

    More reliable approaches include:

    • Using the database’s supported consistency backup mechanism;
    • Pausing writes as required, then performing the backup;
    • Performing a supported physical backup after fully stopping the relevant services;
    • Using a snapshot mechanism that guarantees consistency.

    Which one to choose depends on the database type, data size, and recovery goals.

    3.2 Freeze Asynchronous Writes Too

    Blocking user access to the pages does not necessarily stop all writes. Background tasks, scheduled jobs, and message consumers may still update the database or generate files.

    Within the maintenance window, operate in dependency order:

    1. Pause new requests and task submissions;
    2. Wait for in-flight tasks to finish, or terminate them safely per the plan;
    3. Pause background write services;
    4. Confirm the system no longer produces new business data;
    5. Perform the database and file backups;
    6. Record the backup timestamp and the service state at that time.

    Database records and attachments should be as close as possible to the same business point in time. Otherwise, after recovery you may find records that exist without their files, or files that exist without corresponding records.

    3.3 Verify the Backup Is Actually Usable

    A completed backup is not a successful backup. At minimum, check that files are complete, sizes are reasonable, checksums match, and that configuration, credentials, and custom files are not missing.

    A more reliable method is to perform a recovery test in an isolated environment: restore the database, start the old version of the service, and spot-check key records and attachments.

    Store backups in a location the upgrade will not overwrite. To also guard against local disk failure, keep another copy in a separate storage location. Backups containing access keys and user data must have restricted permissions and be encrypted when necessary.

    4. Do Not Treat “Full Overwrite” as the Standard Upgrade Method

    4.1 Keep Old and New Directories Side by Side

    Rather than overwriting the old directory, it is better to place the target version in a separate directory and then migrate the verified configuration.

    A sample structure:

    1. deployment/
    2. previous/
    3. candidate/
    4. recovery/
    5. upgrade-notes/

    This preserves the old version’s file state, making it easy to compare differences and roll back, and it avoids mixing old and new files.

    Overwriting directly has two common problems: files deprecated in the old version may linger, while the original environment configuration and local modifications may be overwritten by new files. The result is a directory that looks updated but is actually a mixed state whose origin cannot be confirmed.

    4.2 Merge Configuration Field by Field

    Configuration migration should not be an all-or-nothing choice between “keep everything” and “replace everything.”

    Use the target version’s configuration template as the baseline and check the old configuration item by item:

    • Keep connection addresses and credentials that are still valid;
    • Add newly required configuration;
    • Remove deprecated fields;
    • Confirm whether default values have changed;
    • Verify path mappings for uploaded files, databases, and indexes;
    • Check for port conflicts.

    For keys used to decrypt existing data, and other secret values with business-continuity requirements, do not regenerate them casually. Whether they must be kept, and whether rotation is supported, must be confirmed against the actual implementation.

    4.3 Confirm Whether You Are Upgrading Source or Image

    If the application runs directly from a prebuilt image, the upgrade focuses on the image version, orchestration files, and configuration, not merely replacing source code.

    If the application must be built locally, also verify the build context, dependency files, build arguments, and final artifacts. After a successful build, confirm the running service actually uses the new artifacts.

    Either way, verify that the “prepared version” and the “actually running version” match, avoiding a false upgrade where files are updated but the container still runs the old image.

    5. Treat Database Migration as a Separate Risk

    Application code is usually easy to replace, but database schema changes may be irreversible. For example, dropping a field, converting a data format, or adjusting a constraint may leave the old version unable to read the upgraded data.

    So before upgrading, you must answer two questions: first, how does the target version perform the migration? Second, how do you recover if the migration fails?

    It is worth doing a rehearsal before the maintenance window:

    1. Restore an independent database from a backup;
    2. Perform the migration using the method the target version requires;
    3. Check the migration results and logs;
    4. Verify key business data;
    5. Record the actual time taken and the steps for handling anomalies.

    During the real upgrade, avoid having multiple service instances repeatedly run a migration that is not safe to run concurrently. If the migration fails, do not immediately restart repeatedly or retry blindly. First confirm whether there are partially completed changes, then choose to resume, repair, or fully restore based on the migration mechanism.

    6. Start in Dependency Order and Run Business Validation

    6.1 Start Services in Stages

    Usually you can first confirm that base dependencies such as the database and file storage are available, then start the application services and background tasks, and finally open the access entry point. The exact order should still follow the actual deployment requirements.

    Checks should go beyond whether a process exists and also include:

    • Whether base services can establish connections;
    • Whether the application has finished initialization;
    • Whether the data structures match the application version;
    • Whether background tasks keep throwing errors;
    • Whether persistent paths have the correct permissions;
    • Whether logs show missing configuration or failed dependency connections.

    For local upgrades, also check available disk space in advance. Old data, new backups, new images, and build caches may all exist at once, and estimating space by the application directory size alone is often not enough.

    6.2 Run a Minimal Business Loop

    A homepage that opens only shows that part of the chain works. A more meaningful validation is to complete a business loop with a small amount of non-sensitive test data:

    • Log in and check permissions;
    • View data that existed before the upgrade;
    • Create and modify a test record;
    • Upload and read a test file;
    • Run a background task;
    • Check search or query results;
    • Restart the service and confirm the data still exists.

    Post-restart validation is especially important, because it exposes problems such as data written to a temporary directory or an incorrect mount path.

    Also leave a comparable baseline before the upgrade, such as key page response times, background task durations, and common error counts. Compare post-upgrade results under similar conditions, rather than judging stability by subjective impression alone.

    7. Rollback Must Restore the Whole State, Not Just Swap the Code Back

    7.1 Define Rollback Triggers

    It helps to agree on rollback criteria before upgrading, for example:

    • A key business flow cannot be completed;
    • The data migration cannot be resolved within the maintenance window;
    • Severe errors persist;
    • Data integrity validation fails;
    • Service behavior clearly deviates from the acceptable range.

    Clear criteria prevent endless improvised patches after a failure, which can ultimately exhaust the recovery time.

    7.2 When Data Has Been Migrated, Reverting Code Alone Is Usually Not Enough

    A full rollback may need to restore all of the following together:

    • The old version image or build artifacts;
    • The old orchestration files and configuration;
    • The pre-upgrade database;
    • Uploaded files matching the database’s point in time;
    • Any required indexes and extension components.

    If the database schema has already changed, restoring only the old code can cause more serious incompatibility.

    Also consider data created after the upgrade. If the new version has already accepted writes, restoring the old backup may lose that data. So during the initial validation stage, it is best to restrict writes or stay in maintenance mode. If business writes must be allowed, design a way to handle incremental data in advance; do not promise that rollback is inherently lossless.

    8. Build a Repeatable Upgrade Checklist

    Before the actual operation, confirm each item:

    • The current version, image, and deployment method are recorded;
    • The upgrade path supported by the target version is confirmed;
    • All persistent data is identified;
    • Relevant writes are paused and a consistent backup is complete;
    • The backup is verified to be restorable;
    • The old deployment is preserved and target files are placed separately;
    • Configuration is merged item by item and required keys are retained;
    • The database migration has been rehearsed;
    • Resources, ports, and path permissions are checked;
    • The business loop and restart validation are complete;
    • Rollback conditions and steps are defined;
    • Backups and operation records are properly retained.

    A reliable cross-version upgrade should achieve all of the following at once: version verifiable, data recoverable, configuration traceable, and results validatable. Copying the directory is the starting point for protecting deployment files, and replacing code is one action within the upgrade. What truly determines whether an upgrade is sound is the operational loop built around data consistency, compatibility validation, and complete rollback.