2025-09-11 19:41:57 +02:00
# Cleanup Failed Backups (cleanback) 🚮⚡
2025-03-12 20:52:47 +01:00
2025-09-11 19:41:57 +02:00
[](https://github.com/sponsors/kevinveenbirkenbach)
[](https://www.patreon.com/c/kevinveenbirkenbach)
[](https://buymeacoffee.com/kevinveenbirkenbach)
[](https://s.veen.world/paypaldonate)
2023-06-19 13:11:57 +02:00
2025-09-11 19:41:57 +02:00
**Repository:** https://github.com/kevinveenbirkenbach/cleanup-failed-backups
2023-06-19 13:11:57 +02:00
2026-01-06 17:23:05 +01:00
`cleanback` validates and (optionally) cleans up **failed Docker backup directories** in a **production-safe** way.
2025-12-28 19:55:15 +01:00
2026-01-06 17:23:05 +01:00
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.
2023-06-19 13:11:57 +02:00
2025-09-11 19:41:57 +02:00
---
2023-06-19 13:11:57 +02:00
2025-09-11 19:41:57 +02:00
## ✨ Highlights
2023-06-19 13:11:57 +02:00
2025-09-11 19:41:57 +02:00
- **Parallel validation** of backup subdirectories
2026-01-06 17:23:05 +01:00
- Uses ** `dirval` ** (directory validator) via CLI
- **Safe deletion model**: only truly invalid backups are removed
- **Interactive** or **non-interactive** cleanup (`--yes` )
2025-09-11 19:41:57 +02:00
- Supports validating a single backup **ID** or **all** backups
2026-01-06 17:23:05 +01:00
- Clear **exit code semantics** for CI and system services
2025-12-28 19:55:15 +01:00
- Clean **Python package** with `pyproject.toml`
2026-01-06 17:23:05 +01:00
- **Unit tests** and **Docker-based E2E tests**
2023-06-19 13:11:57 +02:00
2025-09-11 19:41:57 +02:00
---
2023-06-19 13:11:57 +02:00
2025-09-11 19:41:57 +02:00
## 📦 Installation
2025-12-28 19:55:15 +01:00
### Via pip (recommended)
2023-06-19 13:11:57 +02:00
```bash
2025-12-28 19:55:15 +01:00
pip install cleanback
2026-01-06 17:23:05 +01:00
```
2025-09-11 19:41:57 +02:00
2025-12-28 19:55:15 +01:00
This installs:
* the `cleanback` CLI
* `dirval` as a dependency (declared in `pyproject.toml` )
### Editable install (for development)
```bash
git clone https://github.com/kevinveenbirkenbach/cleanup-failed-backups
cd cleanup-failed-backups
pip install -e .
```
2025-09-11 19:41:57 +02:00
---
## 🔧 Requirements
2025-12-28 19:55:15 +01:00
* Python **3.8+**
2026-01-06 17:23:05 +01:00
* Read/write access to the backups root directory tree (e.g. `/Backups` )
2025-12-28 19:55:15 +01:00
* `dirval` (installed automatically via pip dependency)
2025-09-11 19:41:57 +02:00
---
## 🚀 Usage
2025-12-28 19:55:15 +01:00
### CLI entrypoint
After installation, the command is:
2025-09-11 19:41:57 +02:00
```bash
2025-12-28 19:55:15 +01:00
cleanback
2023-06-19 13:11:57 +02:00
```
2026-01-06 17:23:05 +01:00
---
2025-12-28 19:55:15 +01:00
### Validate a single backup ID
```bash
2025-12-31 08:31:43 +01:00
cleanback --backups-root /Backups --id <ID>
2025-12-28 19:55:15 +01:00
```
Validates directories under:
```
/Backups/<ID>/backup-docker-to-local/*
```
2026-01-06 17:23:05 +01:00
---
2025-12-28 19:55:15 +01:00
### Validate all backups
```bash
2025-12-31 08:31:43 +01:00
cleanback --backups-root /Backups --all
2025-12-28 19:55:15 +01:00
```
Scans:
```
/Backups/*/backup-docker-to-local/*
```
---
2026-01-06 17:23:05 +01:00
## ⚙️ Common options
2023-06-19 13:11:57 +02:00
2026-01-06 17:23:05 +01:00
| 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 `--yes` is used.
2025-12-28 19:55:15 +01:00
---
2023-06-19 13:11:57 +02:00
2026-01-06 17:23:05 +01:00
## 🧪 Examples
2023-06-19 13:11:57 +02:00
2025-09-11 19:41:57 +02:00
```bash
2026-01-06 17:23:05 +01:00
# Validate a single backup and prompt before deleting invalid ones
2025-12-31 08:31:43 +01:00
cleanback --backups-root /Backups --id 2024-09-01T12-00-00
2025-09-11 19:41:57 +02:00
```
2026-01-06 17:23:05 +01:00
```bash
# Validate all backups and automatically delete invalid ones
cleanback --backups-root /Backups --all --workers 8 --yes
```
2025-12-28 19:55:15 +01:00
2025-09-11 19:41:57 +02:00
```bash
2026-01-06 17:23:05 +01:00
# 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
2025-09-11 19:41:57 +02:00
```
---
2025-12-28 19:55:15 +01:00
## 🔒 Safety & Design Notes
2025-09-11 19:41:57 +02:00
2026-01-06 17:23:05 +01:00
* **Validation and deletion are strictly separated**
* Only backups explicitly marked **invalid by `dirval`** are 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 `--yes` is 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):
```bash
make test
```
2025-09-11 19:41:57 +02:00
---
## 🪪 License
This project is licensed under the **GNU Affero General Public License v3.0** .
See the [LICENSE ](LICENSE ) file for details.
---
## 👤 Author
**Kevin Veen-Birkenbach**
🌐 [https://www.veen.world ](https://www.veen.world )
📧 [kevin@veen.world ](mailto:kevin@veen.world )