Automated Borg repository compaction with quota management and healthcheck integration
Automates compaction of Borg backup repositories running in Docker containers. Handles quota adjustments when repository size exceeds limits, integrates with UptimeKuma for monitoring, and includes dry-run capability for safe testing.
A typical use case is compact "append-only" repos managed with Borg Warehouse. Repose need to be compacted server-side and doing so by hand over a large number of a repos can be very cumbersome. The method used in this script will autonomously list:
- list provisioned repos
- work around quota discrepencies if any
- compact repos
- notify the admin of any success/failure through Uptime Kuma
- does not require (manually or not) disabling "append-only mode" in Borg Warehouse
Quota Management Note: Borg Warehouse sets quotas via SSH command restrictions (borg serve --storage-quota), but borg compact enforces the repository's own storage_quota config. When actual usage exceeds this quota, the script temporarily expands it above current usage, runs compact, then restores the original quota.
- Place
borg_compact.shin your target directory - Make it executable:
chmod +x borg_compact.sh - For cron usage, you can consider using a
cron-wrapperas needed: see guiand888/cron-wrapper
Required:
export UPTIMEKUMA_DOMAIN=your-domain.com
export HEALTHCHECK_ID=your-healthcheck-idOptional:
export CONTAINER_NAME=borgwarehouse-borgwarehouse-1
export REPO_DIR=/home/borgwarehouse/repos
export EXTRA_QUOTA_G=10
export VERBOSE=false# Normal execution
./borg_compact.sh
# Dry-run mode (lists repos and actions without making changes)
./borg_compact.sh --dry-run
# Force verbose output
VERBOSE=true ./borg_compact.sh
# Via cron
0 3 * * * /path/to/borg_compact.shPull requests accepted. For major changes, please open an issue first to discuss what you would like to change.
AGPLv3