Skip to content

clickhouse backup: failed BackupJob attempts leave archives that the sidecar uploads at the next restart #5200

Closed

Description

@myasnikovdaniil

Describe the bug

Each strategy pod attempt starts POST /backup/create_remote with a new timestamped name. clickhouse-backup creates the backup locally and uploads it after, so when the upload fails the local backup stays on the data volume. At start the sidecar resumes unfinished uploads (ResumeOperationsAfterRestart) and uploads those backups. Result is archives in the bucket under <namespace>/<release>/ that no Backup refers to, one per failed attempt (three per failed BackupJob), and local backups are never removed (no BACKUPS_TO_KEEP_LOCAL).

The resumed upload can also hold the API lock. With dead keys it retries about 35 seconds, and the strategy pod got HTTP 423 another operation is currently running on 2 of 3 attempts, which burns the Job backoffLimit: 2 in seconds.

Environment

Cozystack v1.7.0, clickhouse-backup 2.7.4.

To reproduce

  1. Start a ClickHouse app with backup.useSystemBucket: true in a namespace where cozy-backups-creds does not exist yet, so the sidecar has no S3 settings (this is #3986).
  2. Run a BackupJob. It fails after three attempts and GET /backup/list/local on the sidecar shows three local backups.
  3. Restart the ClickHouse pod and run a BackupJob that succeeds.
  4. List the bucket prefix. The three archives of the failed attempts are there next to the real one, and GET /backup/list/remote lists all of them.

Actual behaviour

After my test the bucket held 11 archive prefixes for 4 Backup objects, so 7 orphans. One of them was a full 36 KiB copy of the table data from a failed attempt.

Expected behaviour

A failed attempt leaves nothing behind, or the strategy removes the local backup it created before it exits.

The orphans matter for restore: the strategy takes the newest archive in the prefix (see the issue about ClickHouse restore picking the newest archive), so an orphan can be what gets restored.

Activity

  1. added
    kind/bugCategorizes issue or PR as related to a bug
    area/databaseIssues or PRs related to managed databases (postgres, mariadb, redis, etcd, kafka, clickhouse)
    on Nov 4, 2026
  2. dosubot commented on Nov 4, 2026

    @dosubot

    There is a second gap in the strategy’s startup wait: it checks only whether /backup/status returns HTTP success, not whether an operation is running. It also falls through to create_remote after all 60 checks fail. So that wait does not protect against the resumed-upload lock you observed. [1]

    The archive identity also needs to survive beyond the strategy pod: createAltinityBackupArtifact stores strategy parameters but not the generated archive name, while restore independently selects the newest matching remote archive. Cleaning failed attempts would address this leak, but recording and restoring the exact successful archive would remove the dependency on bucket contents. [2] [3]

    For existing remote orphans, deleting Backup CRs will not purge ClickHouse archives. The controller explicitly delegates manual purge to the sidecar’s authenticated DELETE /backup/<name>/remote API. Only delete names verified as orphaned, not the whole application prefix. [4]

    To reply, just mention @dosu.


    Share context across your team and agents. Try Dosu.

    Leave Feedback Learn about cozystack with Dosu Add Dosu to your team

  3. self-assigned this
    on Nov 4, 2026
  4. scooby87 commented on Nov 13, 2026

    @scooby87
    Contributor

    Fixed by #5229.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area/databaseIssues or PRs related to managed databases (postgres, mariadb, redis, etcd, kafka, clickhouse)kind/bugCategorizes issue or PR as related to a bugtriage/needs-triageIndicates an issue needs triage by a maintainer

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions