Fix borgmatic PostgreSQL backup and update backup sources #21

Merged
eblume merged 5 commits from feature/improve-borgmatic-backups into main 2026-01-17 09:22:02 -08:00
2 changed files with 79 additions and 0 deletions
Showing only changes of commit f1bcfa8471 - Show all commits

Add per-source backup size breakdown to dashboard

- Update borgmatic-metrics script to collect size per source directory
- Add horizontal bar gauge panel showing backup size by source
- Sources: Pictures, Documents, devpi, Zettelkasten, Forgejo, Loki, PostgreSQL

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Erich Blume 2026-01-17 09:18:14 -08:00

View file

@ -125,6 +125,38 @@ borgmatic_last_archive_timestamp $last_timestamp
# TYPE borgmatic_last_archive_duration_seconds gauge
borgmatic_last_archive_duration_seconds ${last_duration:-0}
EOF
# Collect per-source-directory sizes
cat >> "$TEMP_FILE" << 'EOF'
# HELP borgmatic_source_size_bytes Size of each backup source directory in bytes
# TYPE borgmatic_source_size_bytes gauge
EOF
# List archive contents and group by source directory
$BORG_CMD list "${BORG_REPO}::${last_archive_name}" --format "{size} {path}{NL}" 2>/dev/null | awk '
{
size = $1
path = $2
# Map paths to friendly source names
if (path ~ /^Users\/[^\/]+\/Pictures/) { source = "Pictures" }
else if (path ~ /^Users\/[^\/]+\/Documents/) { source = "Documents" }
else if (path ~ /^Users\/[^\/]+\/devpi/) { source = "devpi" }
else if (path ~ /^Users\/[^\/]+\/code\/personal\/zk/) { source = "Zettelkasten" }
else if (path ~ /^Users\/[^\/]+\/.config\/borgmatic/) { source = "borgmatic_config" }
else if (path ~ /^opt\/homebrew\/var\/forgejo/) { source = "Forgejo" }
else if (path ~ /^opt\/homebrew\/var\/loki/) { source = "Loki" }
else if (path ~ /^borgmatic\/postgresql_databases/) { source = "PostgreSQL" }
else if (path ~ /^borgmatic\//) { source = "borgmatic_metadata" }
else { source = "other" }
totals[source] += size
}
END {
for (src in totals) {
printf "borgmatic_source_size_bytes{source=\"%s\"} %.0f\n", src, totals[src]
}
}' >> "$TEMP_FILE"
fi
# Atomic move

View file

@ -477,6 +477,53 @@
"title": "Unique Chunks",
"type": "stat"
},
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [{ "color": "green", "value": null }]
},
"unit": "decbytes"
},
"overrides": []
},
"gridPos": { "h": 8, "w": 8, "x": 16, "y": 4 },
"id": 14,
"options": {
"displayMode": "basic",
"minVizHeight": 10,
"minVizWidth": 0,
"orientation": "horizontal",
"reduceOptions": {
"calcs": ["lastNotNull"],
"fields": "",
"values": false
},
"showUnfilled": true,
"valueMode": "color"
},
"pluginVersion": "10.0.0",
"targets": [
{
"datasource": { "type": "prometheus", "uid": "prometheus" },
"expr": "topk(10, borgmatic_source_size_bytes)",
"legendFormat": "{{source}}",
"refId": "A"
}
],
"title": "Backup Size by Source",
"description": "Breakdown of backup size by source directory",
"type": "bargauge"
},
{
"datasource": {
"type": "prometheus",