Cleanup Failed Backups (cleanback) 🚮⚡
Repository: https://github.com/kevinveenbirkenbach/cleanup-failed-backups
cleanback validates and (optionally) cleans up failed Docker backup directories in a production-safe way.
It scans backup folders under a configurable backups root (for example /Backups), uses dirval to validate each backup subdirectory, and removes only those backups that are confirmed to be invalid.
Validation runs in parallel for performance; deletions are explicitly controlled and can be interactive or fully automated.
✨ Highlights
- Parallel validation of backup subdirectories
- Uses
dirval(directory validator) via CLI - Safe deletion model: only truly invalid backups are removed
- Interactive or non-interactive cleanup (
--yes) - Supports validating a single backup ID or all backups
- Clear exit code semantics for CI and system services
- Clean Python package with
pyproject.toml - Unit tests and Docker-based E2E tests
📦 Installation
Via pip (recommended)
pip install cleanback
This installs:
- the
cleanbackCLI dirvalas a dependency (declared inpyproject.toml)
Editable install (for development)
git clone https://github.com/kevinveenbirkenbach/cleanup-failed-backups
cd cleanup-failed-backups
pip install -e .
🔧 Requirements
- Python 3.8+
- Read/write access to the backups root directory tree (e.g.
/Backups) dirval(installed automatically via pip dependency)
🚀 Usage
CLI entrypoint
After installation, the command is:
cleanback
Validate a single backup ID
cleanback --backups-root /Backups --id <ID>
Validates directories under:
/Backups/<ID>/backup-docker-to-local/*
Validate all backups
cleanback --backups-root /Backups --all
Scans:
/Backups/*/backup-docker-to-local/*
⚙️ Common options
| Option | Description |
|---|---|
--dirval-cmd <cmd> |
Path or name of dirval executable (default: dirval) |
--workers <n> |
Number of parallel validator workers (default: CPU count, minimum 2) |
--timeout <sec> |
Per-directory validation timeout in seconds (float supported, default: 300.0) |
--yes |
Non-interactive mode: automatically delete invalid backups (dirval rc=1 only) |
--force-keep <n> |
In --all mode: skip the last n timestamp subdirectories inside each backup folder |
Note: Backups affected by timeouts or infrastructure errors are never deleted automatically, even when
--yesis used.
🧪 Examples
# Validate a single backup and prompt before deleting invalid ones
cleanback --backups-root /Backups --id 2024-09-01T12-00-00
# Validate all backups and automatically delete invalid ones
cleanback --backups-root /Backups --all --workers 8 --yes
# Use a custom dirval binary and a short timeout (testing only)
cleanback \
--backups-root /Backups \
--all \
--dirval-cmd /usr/local/bin/dirval \
--timeout 5.0
🔒 Safety & Design Notes
- Validation and deletion are strictly separated
- Only backups explicitly marked invalid by
dirvalare eligible for deletion - Timeouts and infrastructure errors are NOT treated as invalid backups
- Backups affected by timeouts are never deleted automatically
- Infrastructure problems (timeouts, missing
dirval) cause a non-zero exit code - Deletions require confirmation unless
--yesis specified - Tests never touch the host filesystem (E2E tests run inside Docker only)
This design makes cleanback safe for unattended operation on production systems.
🚦 Exit codes
cleanback uses exit codes to clearly distinguish between backup issues and infrastructure problems:
| Exit code | Meaning |
|---|---|
0 |
All backups valid, or invalid backups were successfully removed |
1 |
Validation infrastructure problem (e.g. timeout, missing dirval) |
2 |
CLI usage or configuration error |
This makes the tool suitable for CI pipelines, systemd services, and other automation.
🧪 Tests
Run all tests (unit + Docker-based E2E):
make test
🪪 License
This project is licensed under the GNU Affero General Public License v3.0. See the LICENSE file for details.
👤 Author
Kevin Veen-Birkenbach 🌐 https://www.veen.world 📧 kevin@veen.world
Metadata
Release files for cleanback 1.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| cleanback-1.3.0.tar.gz | 44.7 kB | Without provenance | Details for cleanback-1.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| cleanback-1.3.0-py3-none-any.whl | Python 3 | none | any | Details for cleanback-1.3.0-py3-none-any.whl |
Total release size: 76.1 kB
Release files / cleanback-1.3.0.tar.gz
| Download URL | cleanback-1.3.0.tar.gz |
|---|---|
| Size | 44.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6baddb01fcab8492aa3888a2a561680434b87ce2e746757518b10566127d4a70
|
|
BLAKE2b-256 checksum How to use checksums |
00e3b09008ab88558fb1bb646e9a0cab6b6a98d6adb2119eac8594e6a9f35fd2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.11
|
Release files / cleanback-1.3.0-py3-none-any.whl
| Download URL | cleanback-1.3.0-py3-none-any.whl |
|---|---|
| Size | 31.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fd8c8a3351794581be3137a88c7565968fc20bb224622c973ac4a85c8a431bb4
|
|
BLAKE2b-256 checksum How to use checksums |
5d3b3d4550f45d3598cf28b2067943571044eefb91875cfbdaaef2d13ab489da
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.11
|
Security for cleanback 1.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.