Bash rsync Mirror with Safe-Deletion Guard Prompt
Build a Bash rsync mirroring script with dry-run defaults, delete-protection guards, and confirmation before any destructive --delete operation
- Target user
- engineers who automate ops with Bash and Python
- Difficulty
- Advanced
- Tools
- Claude, ChatGPT
The prompt
You are a senior automation engineer who has seen a misconfigured rsync --delete wipe a production directory and now builds mirroring scripts that make that impossible by default. I will provide: - The source and destination paths (local or remote over SSH) - Whether the mirror should delete extraneous files at the destination - Constraints like bandwidth limits, exclude patterns, or required permissions/ownership Your job: 1. **Scaffold safely** — write the script in strict mode with a mandatory dry-run that runs first and shows exactly what would change. 2. **Guard the delete** — make `--delete` opt-in via an explicit flag, refuse to run if source is empty or unreadable, and require interactive confirmation (or an explicit `--yes`) before any deletion. 3. **Add sanity checks** — verify source exists and is non-empty, destination is the expected path, and abort if rsync's deletion count exceeds a configurable threshold. 4. **Build the rsync invocation** — assemble flags for archive mode, excludes, bandwidth limit, and itemized changes, quoting all paths. 5. **Log and report** — capture a timestamped log, summarize bytes transferred and files deleted, and exit with a meaningful code. Output as: the full script in one fenced block, followed by example invocations for dry-run, mirror-without-delete, and confirmed mirror-with-delete. Default to dry-run and no deletion; never perform a --delete mirror without an explicit flag, a passed sanity threshold, and operator confirmation.
Run this prompt with AI
Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.
Related prompts
-
Bash Safe In-Place sed Edit Wrapper Prompt
Build a Bash wrapper around sed -i that backs up, validates, and atomically applies in-place edits so a bad expression can never corrupt or truncate config files
-
Bash Script Safety & Portability Review Prompt
Audit an existing Bash script line by line for unsafe quoting, missing strict mode, destructive commands, race conditions, and bashisms that break portability, and return prioritized fixes.
-
Trap-Driven Cleanup & Rollback Bash Script Prompt
Write a robust Bash script that uses set -euo pipefail plus EXIT/ERR/INT traps to guarantee temp-file cleanup and partial-work rollback even when a command fails midway.
-
Bash Dry-Run Mode Pattern Prompt
Add a first-class `--dry-run` mode to a Bash automation script so every mutating action is previewed instead of executed — with a single `run()` wrapper, clear PLAN output, and no accidental side effects.
More Bash & Python Automation prompts & error guides
Browse every Bash & Python Automation prompt and troubleshooting guide in one place.
Reading prompts? Get all 500 in one free PDF
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.