40 lines
2.2 KiB
Python
40 lines
2.2 KiB
Python
"""Read-only verification of the retained damaged QA cluster, never the active cluster."""
|
|
import hashlib
|
|
import json
|
|
import sys
|
|
from datetime import datetime, timezone
|
|
from pathlib import Path
|
|
|
|
source = Path('C:/Users/macbook/AppData/Local/Temp/investmoz-pg-test-55441').resolve()
|
|
copy = Path('C:/Users/macbook/.config/investmoz/qa-postgres-recovery/original-damaged-20261010_154445').resolve()
|
|
assert source.name == 'investmoz-pg-test-55441' and copy.parent.name == 'qa-postgres-recovery'
|
|
files = sorted(p.relative_to(source).as_posix() for p in source.rglob('*') if p.is_file())
|
|
other = sorted(p.relative_to(copy).as_posix() for p in copy.rglob('*') if p.is_file())
|
|
assert files == other, 'Retained file inventory differs'
|
|
digest = hashlib.sha256()
|
|
size = 0
|
|
for index, relative in enumerate(files):
|
|
original = source / relative
|
|
retained = copy / relative
|
|
length = original.stat().st_size
|
|
assert length == retained.stat().st_size
|
|
def sha(path):
|
|
h = hashlib.sha256()
|
|
with path.open('rb') as stream:
|
|
for block in iter(lambda: stream.read(1024 * 1024), b''):
|
|
h.update(block)
|
|
return h.hexdigest()
|
|
fingerprint = sha(original)
|
|
assert fingerprint == sha(retained), 'Retained QA file differs'
|
|
digest.update((relative + '\t' + str(length) + '\t' + fingerprint + '\n').encode('utf-8'))
|
|
size += length
|
|
if index and index % 15000 == 0:
|
|
print(json.dumps({'files_checked': index}), flush=True)
|
|
proof = {'verified_at': datetime.now(timezone.utc).isoformat(), 'original_cluster': str(source), 'retained_copy': str(copy),
|
|
'files': len(files), 'bytes': size, 'manifest_sha256': digest.hexdigest(), 'all_names_sizes_hashes_equal': True,
|
|
'database_writes': 0, 'active_access': False, 'original_damaged_cluster_preserved': True,
|
|
'limitation': 'Physical preservation of all historical QA databases, not logical restoration of every historical database.'}
|
|
out = Path(__file__).resolve().parent.parent / 'storage/app/private/investmoz-v2/portal-qa-recovery/20261010_154445/damaged-copy-proof.json'
|
|
out.write_text(json.dumps(proof, indent=2), encoding='utf-8')
|
|
print(json.dumps({k: v for k, v in proof.items() if k not in ['original_cluster', 'retained_copy']}))
|