Skip to content

Publish transfer archives atomically without destroying an existing backup on failure #4

Open

Description

@LunaStev

Problem

export-server.sh writes directly to the requested destination with tar -czf "$archive_path" -- .env data. Reusing an existing archive path truncates the previous backup before the new export has succeeded. If tar later fails, the script exits unsuccessfully but the last good backup has already been replaced by incomplete output.

The script checks for .env before export but not for the complete input tree. A missing data directory provides a small deterministic example; read errors and output failures require the same preservation guarantee.

Code references:

Reproduction

Use a disposable directory and a Docker command double; no real server or credentials are needed.

  1. Create a valid tar.gz backup at an explicit output path and save its bytes or checksum.
  2. Put a dummy .env beside the export script, but leave data/ absent.
  3. Make the Docker double return an empty container ID for compose ps -q wave-platform.
  4. Run the export script with the existing backup path.
  5. Compare the destination with its saved bytes.

The current script returns exit 2 with tar: data: Cannot stat: No such file or directory, but the existing archive bytes have changed. This result was observed by executing the actual script with Bash and tar against the fixture.

Expected behavior and scope

Write each export to a uniquely named temporary file beside the intended destination. Make it owner-readable/writable only before secret contents are written. Complete archive creation and any required validation before publishing the new file through a same-filesystem atomic replacement.

On a preparation, archive-write, validation, or replacement failure, preserve any existing destination byte-for-byte and remove incomplete temporary output. Preserve the existing policy of stopping and restoring only a service that was running before export.

Completion criteria

  • The supplied failure case leaves an existing destination unchanged and reports a nonzero status.
  • A failed first export does not leave a partial file at the final archive path.
  • Successful export publishes a readable archive containing the expected .env and complete fixture data with restrictive permissions.
  • Temporary archive names are unique, reside on the destination filesystem, and are cleaned up on handled errors and supported termination signals.
  • Test archive-write and final-publication failures with controlled command/filesystem doubles where necessary; do not rely on filling the developer's disk.
  • Preserve running/stopped service state and error reporting, including failure to restart a previously running service.
  • Define and reject an output location inside the archived data tree, or otherwise prove that temporary/final archives cannot be included recursively in their own export.
  • Add isolated shell tests asserting archive bytes, permissions, cleanup, and Docker call order.

Difficulty: medium. Related #3 owns import validation and restoration; this issue owns export artifact publication.

Activity

  1. added
    bug
    help wanted
    on Sep 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bughelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions