Automate File Verification with an SFV Checker Script
Date: February 5, 2026
Automating file verification ensures data integrity across backups, transfers, and archives. An SFV (Simple File Verification) checker uses CRC32 checksums stored in .sfv files to confirm files haven’t been corrupted. This guide shows a concise, practical script-based workflow to generate, verify, and automate SFV checks on Windows, macOS, or Linux.
Why use SFV automation
- Reliability: CRC32 quickly detects file corruption from transfers or disk errors.
- Speed: Lightweight checks are faster than some stronger hashes where CRC32 suffices.
- Compatibility: .sfv is widely supported by archival workflows and older tools.
- Automation: Integrate verification into backups, CI pipelines, or scheduled integrity checks.
What the script will do
- Generate an .sfv file of CRC32 checksums for all files in a folder.
- Verify files against the .sfv, reporting mismatches or missing files.
- Optionally re-run verification and log results for scheduled checks.
Tools and assumptions
- Cross-platform approach using Python 3.8+ (installed on Windows, macOS, Linux).
- Uses standard libraries only (no external packages).
- Operates on a target folder and produces/reads a file named checks.sfv by default.
Script: generate + verify SFV (Python)
Code
#!/usr/bin/env python3 ”“” sfv_tool.py — generate and verify CRC32 .sfv files Usage:python sfv_tool.py generate /path/to/folder python sfv_tool.py verify /path/to/folder “”” import sys, os, zlib, argparsedef crc32_file(path):
bufsize = 65536 crc = 0 with open(path, 'rb') as f: while True: data = f.read(bufsize) if not data: break crc = zlib.crc32(data, crc) return format(crc & 0xFFFFFFFF, '08X')def generate_sfv(folder, sfv_name=‘checks.sfv’):
entries = [] for root, _, files in os.walk(folder): for fn in sorted(files): if fn == sfv_name: continue full = os.path.join(root, fn) rel = os.path.relpath(full, folder) entries.append((rel.replace(os.sep, '/'), crc32_file(full))) with open(os.path.join(folder, sfv_name), 'w', newline='\n') as out: out.write('; Generated by sfv_tool.py\n') for name, crc in entries: out.write(f"{name} {crc}\n") print(f"Generated {sfv_name} with {len(entries)} entries.")def verify_sfv(folder, sfv_name=‘checks.sfv’):
path = os.path.join(folder, sfv_name) if not os.path.exists(path): print(f"SFV not found: {path}"); return 2 failures = [] missing = [] with open(path, 'r') as f: for line in f: line = line.strip() if not line or line.startswith(';'): continue parts = line.split() if len(parts) < 2: continue name = parts[0]; expected = parts[1].upper() full = os.path.join(folder, name) if not os.path.exists(full): missing.append(name); continue actual = crc32_file(full) if actual != expected: failures.append((name, expected, actual)) for m in missing: print(f"MISSING: {m}") for n,e,a in failures: print(f"FAILED: {n} expected {e} got {a}") ok = (not missing and not failures) print("OK" if ok else "VERIFICATION FAILED") return 0 if ok else 1def main():
p = argparse.ArgumentParser() p.add_argument('action', choices=['generate','verify']) p.add_argument('folder') p.add_argument('--sfv', default='checks.sfv') args = p.parse_args() if args.action == 'generate': generate_sfv(args.folder, args.sfv) else: sys.exit(verify_sfv(args.folder, args.sfv))if name == ‘main’:
main()How to use
- Save as sfv_tool.py and make executable (chmod +x sfv_tool.py).
- Generate checks:
python sfv_tool.py generate /path/to/target- Verify:
python sfv_tool.py verify /path/to/target- Integrate into cron/Task Scheduler for recurring checks; redirect output to a log file.
Scheduling examples
- Cron (daily at 02:00):
- 0 2 * * * /usr/bin/python3 /path/to/sfv_tool.py verify /data/backups >> /var/log/sfv_verify.log 2>&1
- Windows Task Scheduler:
- Create a task that runs: python C:\path\sfv_tool.py verify C:\backups with desired trigger.
Logging and notifications
- Redirect script output to log files.
- For alerts, wrap verify call in a small shell/batch wrapper that emails or posts to a webhook when exit code != 0.
Limitations and tips
- CRC32 is fast but weaker than SHA-family hashes; prefer SHA256 if threat model requires cryptographic guarantees.
- Keep the .sfv file stored separately from the files it verifies (e.g., different disk or remote storage) to avoid simultaneous corruption.
- For very large files or many files, run generation during off-peak hours.
Summary
This lightweight Python script provides cross-platform automation for SFV-based integrity checks. Use scheduled verification plus offsite storage of the .sfv to maintain reliable, automated file verification for backups and transfers.
Leave a Reply