From 15c9517d0c0d7681511e895dad614d5e2f4192c5 Mon Sep 17 00:00:00 2001 From: Mikhail Date: Sat, 22 Aug 2026 11:14:21 +0300 Subject: [PATCH] Repair production backup recovery selection --- deploy/verify-latest-postgres-backup.sh | 7 +++++- deploy/windows/Sync-PostgresBackupToNas.ps1 | 2 +- dev/ACTIVE_TASK.json | 4 ++-- ...DEV-000100-production-recovery-repair.json | 22 +++++++++++++++++++ .../verify_latest_backup_test.ps1 | 10 +++++++++ 5 files changed, 41 insertions(+), 4 deletions(-) create mode 100644 dev/tasks/DEV-000100-production-recovery-repair.json create mode 100644 tests/production_recovery/verify_latest_backup_test.ps1 diff --git a/deploy/verify-latest-postgres-backup.sh b/deploy/verify-latest-postgres-backup.sh index 244e196..82f844d 100755 --- a/deploy/verify-latest-postgres-backup.sh +++ b/deploy/verify-latest-postgres-backup.sh @@ -4,10 +4,15 @@ set -eu backup_root="${ASSISTANT_BACKUP_DIR:-/home/m/assistant-backups/postgres}" verify_script="${ASSISTANT_RESTORE_VERIFY_SCRIPT:-/home/m/assistant-ops/verify-postgres-restore.sh}" -latest="$(find "$backup_root" -mindepth 1 -maxdepth 1 -type d ! -name '.*' -printf '%f\n' | sort | tail -n 1)" +latest="$(find "$backup_root" -mindepth 1 -maxdepth 1 -type d -regextype posix-extended -regex '.*/[0-9]{8}T[0-9]{6}Z$' -printf '%f\n' | sort | tail -n 1)" if [ -z "$latest" ]; then echo "No completed PostgreSQL backup found in $backup_root" >&2 exit 1 fi +case "$latest" in + [0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]T[0-9][0-9][0-9][0-9][0-9][0-9]Z) ;; + *) echo "Selected backup directory has invalid timestamp: $latest" >&2; exit 1 ;; +esac + exec "$verify_script" "$backup_root/$latest" diff --git a/deploy/windows/Sync-PostgresBackupToNas.ps1 b/deploy/windows/Sync-PostgresBackupToNas.ps1 index 12b1801..0158d02 100644 --- a/deploy/windows/Sync-PostgresBackupToNas.ps1 +++ b/deploy/windows/Sync-PostgresBackupToNas.ps1 @@ -45,7 +45,7 @@ $cipherPartial = $null $manifestPartial = $null try { - $latest = ((& ssh.exe $SshHost "find '$RemoteBackupRoot' -mindepth 1 -maxdepth 1 -type d ! -name '.*' -printf '%f\n' | sort | tail -n1") -join '').Trim() + $latest = ((& ssh.exe $SshHost "find '$RemoteBackupRoot' -mindepth 1 -maxdepth 1 -type d -printf '%f\n' | grep -E '^[0-9]{8}T[0-9]{6}Z$' | sort | tail -n1") -join '').Trim() if ($LASTEXITCODE -ne 0 -or $latest -notmatch '^\d{8}T\d{6}Z$') { throw 'No valid completed production backup found' } New-Item -ItemType Directory -Force -Path $NasBackupRoot | Out-Null diff --git a/dev/ACTIVE_TASK.json b/dev/ACTIVE_TASK.json index dd5b431..79c5958 100644 --- a/dev/ACTIVE_TASK.json +++ b/dev/ACTIVE_TASK.json @@ -1,5 +1,5 @@ { - "task_file": "dev/tasks/DEV-000099-governance-consolidation.json", - "task_id": "DEV-000099", + "task_file": "dev/tasks/DEV-000100-production-recovery-repair.json", + "task_id": "DEV-000100", "task_revision": 1 } diff --git a/dev/tasks/DEV-000100-production-recovery-repair.json b/dev/tasks/DEV-000100-production-recovery-repair.json new file mode 100644 index 0000000..53310ed --- /dev/null +++ b/dev/tasks/DEV-000100-production-recovery-repair.json @@ -0,0 +1,22 @@ +{ + "task_id": "DEV-000100", + "task_revision": 1, + "architecture_revision": "ADR-0018", + "base_repo_revision": "8687c9b", + "risk_tier": "E", + "intent": "Repair production backup and restore selection so only complete timestamped backups are eligible, and make provenance drift degrade readiness.", + "requirement_ids": ["WP-002", "INV-CONT-001", "Production recovery must be reversible"], + "allowed_change_scope": {"modules": [], "paths": ["deploy/verify-latest-postgres-backup.sh", "deploy/windows/Sync-PostgresBackupToNas.ps1", "deploy/windows/Test-DomovoyProductionHealth.ps1", "tests/production_recovery/**", "docs/DEPLOYMENT.md", "dev/ACTIVE_TASK.json", "dev/tasks/DEV-000100-production-recovery-repair.json"]}, + "forbidden_change_scope": {"paths": ["architecture/**", "security/**", "database/**", "contracts/**", "modules/**", "cmd/**", "adapters/**", "platform/**", ".gitea/**"]}, + "allowed_architecture_delta": {"new_cross_module_dependencies": 0, "new_canonical_owners": 0, "new_privileges": 1, "new_third_party_dependencies": 0, "new_database_owner_roles": 0}, + "contracts": {"consume": ["Production backup directory contract", "Deployment manifest evidence", "Production health projection"], "may_change": []}, + "semantic_owner": "none-operational-recovery", "canonical_state": [], + "state_transitions": ["ineligible backup -> ignored", "verified backup -> restore candidate", "provenance/backup drift -> degraded health"], + "side_effects_and_privileges": ["Local script changes are read-only until explicit production verification; no secret bytes are logged"], + "persistence_and_migrations": ["No database schema or migration changes"], + "failure_retry_restart": ["Partial/temp/pre-* directories remain untouched and are ignored; restore checks use isolated temporary PostgreSQL only"], + "assumptions": ["Production host is docker.cin.su via docker-prod/docker SSH configuration", "docker-test remains prohibited"], + "acceptance_scenarios": ["pre-*, partial and temp directories are ignored", "latest timestamp directory is selected deterministically", "missing/hash-invalid backup is rejected", "production health is degraded on backup or deployment provenance drift", "restore verification remains isolated and cleanup-safe"], + "required_tests": ["shell fixture tests", "PowerShell parser", "go run ./cmd/devctl/independent", "go run ./cmd/devctl preflight -active dev/ACTIVE_TASK.json", "go run ./cmd/devctl check-diff -active dev/ACTIVE_TASK.json", "go test ./...", "go vet ./...", "git diff --check", "production read-only health evidence"], + "terminal_gap_states": ["BLOCKED_BY_ARCHITECTURE_GAP", "BLOCKED_BY_SPEC_GAP", "BLOCKED_BY_MISSING_CAPABILITY", "BLOCKED_BY_CONFLICT"] +} diff --git a/tests/production_recovery/verify_latest_backup_test.ps1 b/tests/production_recovery/verify_latest_backup_test.ps1 new file mode 100644 index 0000000..28977a1 --- /dev/null +++ b/tests/production_recovery/verify_latest_backup_test.ps1 @@ -0,0 +1,10 @@ +$ErrorActionPreference = 'Stop' +Set-StrictMode -Version Latest + +$script = Get-Content -LiteralPath (Join-Path $PSScriptRoot '../../deploy/verify-latest-postgres-backup.sh') -Raw +if ($script -notmatch "-regex '\.\*/\[0-9\]\{8\}T\[0-9\]\{6\}Z\$'") { + throw 'restore selector does not restrict candidates to timestamp directories' +} +if ($script -notmatch 'invalid timestamp') { throw 'restore selector lacks timestamp fail-closed guard' } +if ($script -match "! -name '\.\*'") { throw 'restore selector still accepts arbitrary non-hidden directories' } +Write-Output 'verify-latest backup selector tests: PASS'