--- title: "Automating Backups & Telegram Status Notifications" date: 2026-11-17 description: "How I built a Python-powered backup verification script and a Telegram notification wrapper for my Docker homeserver." tldr: "Backups only count if you know they actually worked. I wrote a script to inspect my mounts, Duplicati jobs, and Docker backups, plus a Telegram wrapper that pings me if anything looks off." layout: post.njk lang: en translationKey: automating-backups-and-telegram-notifications tags: - Homeserver - Backups - Docker - Duplicati - Telegram - Automation - Python --- ## Why I Stopped Trusting Silent Backups If you run a homeserver, you probably know the feeling: you set up a backup job once, see it finish without errors, and then forget about it for months. Everything feels safe—until the day you actually need to restore something and realize the external drive unmounted three weeks ago or a database dump has been silently writing 0-byte files. I wanted to stop guessing. Instead of manually SSHing into my server and clicking through Duplicati's web UI every few days, I built a small, automated verification and notification setup in `/docker/`. ## The Inspection Script: `check-backups.sh` At the heart of the setup is `/docker/check-backups.sh` (which I also symlinked as `/docker/backup-status.sh` for convenience). It's a Bash wrapper that hands off the heavy lifting to an embedded Python 3 script. Here is what it checks every time it runs: 1. **Storage & Mounts:** It inspects `/`, `/data_safe`, and `/data_external_unsafe` using `os.statvfs` and `mountpoint -q`. For the external Crucial SSD (`/data_external_unsafe`), it also checks for a `checkfile` canary so I know the actual drive is mounted and not just an empty mount directory. 2. **Duplicati Backups:** Rather than scraping the web UI, the script opens `/docker/duplicati/config/Duplicati-server.sqlite` in read-only mode. It reads the configured backup jobs, schedules, and any `ErrorLog` entries from the past 14 days. For each job, it also opens the job-specific SQLite database to grab the latest `Fileset` timestamp and total `Remotevolume` size—whether the target is my Hetzner Storage Box, the Crucial SSD, or a Seagate USB HDD. 3. **Docker Services:** It checks the backup state of my Docker stacks, flagging things like empty dumps, stale backups, or script errors. I also added a few CLI flags like `--json`, `--all`, `--include-ignored`, `--full-test` (for deeper archive decompression checks), and `--no-color`. The `--json` flag is the key piece that makes automation easy. ## Getting Pinged on Telegram: `notify-backup-status.sh` Having a nice terminal report is great when I'm logged in, but I want to know when something breaks without having to ask. That's where `/docker/notify-backup-status.sh` comes in. It's another Bash-plus-Python wrapper that runs `check-backups.sh --json` and parses the output. If `check-backups.sh` itself fails to run, it immediately fires off a `🚨 DOCKER BACKUP ALERT` via `telegram-send`. Otherwise, it loops through all active Docker services and Duplicati jobs, tallying up how many are healthy, how many have warnings (like `STALE`, `NOT_IN_CRON`, or `SCRIPT_ERROR`), and how many failed (`FAILED`, `NO_BACKUP`, `EMPTY_DUMP`). Depending on the totals, it picks a header: - `✅ Docker Backup Verification: All Healthy` - `⚠️ Docker Backup Verification: Warnings` - `🚨 DOCKER BACKUP ALERT: Failures Detected!` One small detail I'm glad I thought of early: Telegram has a 4,096-character limit per message. If a bunch of things ever go wrong at once, `notify-backup-status.sh` automatically splits the problem list into chunks of up to 3,900 characters so nothing gets truncated or rejected by the API. ## Was It Worth It? Definitely. Now I get a clean HTML-formatted summary right in Telegram via `/root/.config/telegram-send.conf`. If everything is green, I can ignore it in two seconds. If something is yellow or red, I know immediately which service or target needs attention—before I ever need to restore from it.