Schedule icon
Webhook icon
Get icon
Commands icon
Docker icon
If icon
SlackIncomingWebhook icon
Pause icon
Set icon

rclone Offsite Mirror with Mass-Deletion Guard and Approved Sync

Keep an rclone offsite mirror safe. Compare each sync plan to the last verified mirror in KV, require approval for mass deletes, back up, cap and verify.

Categories
Infrastructure

A nightly rclone sync makes the offsite copy identical to production, including the day production loses its data. A deleted bucket prefix, a ransomware pass that rewrites every object in place, or an export job that wrote nothing is faithfully mirrored, and the backup is gone with the original. This blueprint keeps the mirror but refuses to copy a disaster without a human.

How it works

  1. load_baseline (io.kestra.plugin.core.kv.Get) reads the source object count and size recorded by the last mirror that was applied and verified.
  2. plan (io.kestra.plugin.scripts.shell.Commands in the rclone image) measures source and mirror with rclone size --json, then runs rclone check --combined to list what a sync would copy (+), overwrite (*) and delete (-). A missing source stops the run, because treating it as empty would plan to erase the mirror.
  3. The same task sets verdict REVIEW when the source is empty while the mirror is not, the source count or size fell more than max_shrink_pct since the baseline, the sync would delete more than max_delete_pct of the mirror, or it would overwrite more than max_rewrite_pct. Changes up to free_changes objects never count.
  4. review_gate posts the reasons to Slack and approve_sync (io.kestra.plugin.core.flow.Pause) waits for a person to tick Approve. The default is false and a timeout resumes with the default, so silence never applies the sync.
  5. apply_gate runs apply_sync for a clean plan or an approved one. It uses --backup-dir so deleted and overwritten objects move to a trash prefix named after the run, and --max-delete set to the planned deletions, so anything that became deletable after the review stops the run.
  6. verify_mirror compares again, requires no extra objects in the mirror and that the trash holds every planned deletion. Only then save_baseline stores the new source size. A declined or failed run leaves the baseline alone, so the same collapse is flagged again.

What you get

  • A mirror that follows normal change automatically and stops on abnormal change.
  • A hard ceiling on deletions enforced by rclone, equal to what was reviewed.
  • An undo window: every deleted or overwritten object is kept under the run's trash folder.
  • A baseline that only advances after verification, with the approval note stored beside it.

Who it's for

  • Platform and SRE teams that keep an offsite or cross-account copy of object storage.
  • Security teams that need a mirror which cannot be emptied by the same incident that empties production.

Why orchestrate this with Kestra

rclone has no memory between runs, no approval step and no way to compare tonight's plan with last week's source. Kestra supplies the KV baseline, the pause-and-resume gate, per-step containers with secrets, a webhook that runs the mirror when the export finishes, and an error handler that tells the on-call where the trash folder is.

Prerequisites

  • A Kestra worker that can run Docker containers and reach both storage endpoints.
  • An rclone config with the production and mirror remotes. The mirror credentials should be able to write and delete only on the mirror and trash paths, and production credentials need read access only.
  • The trash path on the same remote as the mirror, outside the mirror path.

Secrets

  • RCLONE_CONFIG: the full contents of an rclone.conf defining the remotes used by source, destination and trash_path.
  • SLACK_WEBHOOK_URL: Slack incoming webhook for review requests and results.
  • RCLONE_MIRROR_WEBHOOK_KEY: key for the webhook trigger.

Quick start

  1. Add the three secrets and set source, destination and trash_path.
  2. Run with dry_run: true and read the plan in Slack. It changes nothing.
  3. Run with dry_run: false. The first run seeds the mirror, since an empty destination plans only copies, and records the baseline.
  4. Delete a few hundred test objects from a copy of the source and run again to see the review request, then approve or decline.
  5. Scheduled and webhook runs use the input defaults, so set the dry_run default to false once the plan looks right, then enable nightly_mirror or call the webhook when your export finishes.

How to extend

  • Expire old trash folders with a second task running rclone delete --min-age 30d on the trash path.
  • Run several pairs by wrapping the tasks in a Loop over a list of source and destination paths.
  • Page the on-call through a PagerDuty task when a review is not answered in time.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.