Advertisement
PlebCoder1337

Untitled

Jun 9th, 2025
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.86 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. """
  3. verify_backup.py  –  Ensure the newest tar.gz in ~/backup_demo/archives can be listed.
  4. If corrupt, exits with code 1 so cron can alert.
  5. """
  6. import subprocess, pathlib, sys, os, glob, datetime
  7.  
  8. ARCHIVE_DIR = pathlib.Path.home() / "backup_demo" / "archives"
  9. archives = sorted(ARCHIVE_DIR.glob("backup-*.tar.gz"))
  10. if not archives:
  11.     print("No archives found!", file=sys.stderr); sys.exit(1)
  12.  
  13. latest = archives[-1]
  14. print(f"[+] Verifying {latest.name}")
  15.  
  16. # `tar -tzf` lists contents — exits non‑zero if archive is bad
  17. result = subprocess.run(
  18.     ["tar", "-tzf", latest], capture_output=True, text=True)
  19.  
  20. if result.returncode == 0:
  21.     print("[+] Archive OK, sample listing:")
  22.     print(result.stdout.splitlines()[:3])   # show first 3 files
  23. else:
  24.     print("[!] Archive appears corrupt!", file=sys.stderr)
  25.     sys.exit(1)
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement