Backup & Recovery (Rsync/Tar/Dd)
Don’t let your backups die mid-stream because you forgot to check available space
🧩 The Challenge
Everyone has had that moment where they kick off a massive database dump or a full system tarball only to walk back twenty minutes later to a filesystem full error. It is infuriating to lose half an hour of progress just because the disk hit 100 percent capacity while you were grabbing a coffee.
💡 The Fix
You can tell your command to check the destination path’s free space before it even starts writing a single byte. It saves you the headache of cleaning up a massive, incomplete file that wasn’t going to finish anyway.
df -h /path/to/backup/dest | awk 'NR==2 {if ($4 < 50) exit 1}' && tar -cvzf /path/to/backup/dest/data.tar.gz /important/data
⚙️ Why It Works
Using awk here effectively gates the tar command based on the available space reported by df, so the backup process never initiates unless your threshold is met. Checking against specific gigabytes before running a pipe keeps your drives from hitting that dreaded read-only state.
🚀 Pro-Tip: Replace that 50 with a variable like $REQUIRED_GB so you can tweak your headroom requirements across different backup scripts without digging through the logic every time.
Linux Tips & Tricks | © ngelinux.com | 11/1/2026
