Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- """
- verify_backup.py – Ensure the newest tar.gz in ~/backup_demo/archives can be listed.
- If corrupt, exits with code 1 so cron can alert.
- """
- import subprocess, pathlib, sys, os, glob, datetime
- ARCHIVE_DIR = pathlib.Path.home() / "backup_demo" / "archives"
- archives = sorted(ARCHIVE_DIR.glob("backup-*.tar.gz"))
- if not archives:
- print("No archives found!", file=sys.stderr); sys.exit(1)
- latest = archives[-1]
- print(f"[+] Verifying {latest.name}")
- # `tar -tzf` lists contents — exits non‑zero if archive is bad
- result = subprocess.run(
- ["tar", "-tzf", latest], capture_output=True, text=True)
- if result.returncode == 0:
- print("[+] Archive OK, sample listing:")
- print(result.stdout.splitlines()[:3]) # show first 3 files
- else:
- print("[!] Archive appears corrupt!", file=sys.stderr)
- sys.exit(1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement