- A rollback record now says which restarts succeeded. A snapshot stays open while an instance is unrestored or its restart failed (or was declined), so -Rollback -RestartInstances retries exactly those instead of reporting done or stepping back to an older deployment. - Running dependents (SQL Server Agent) are written to dependents-<service>.json before the stop and removed once they run again, so a failed restart does not leave Agent stopped for good. - GetRegValue returns $null only for a value confirmed absent; a missing key or read error throws, so it is never snapshotted or verified as absent. - Instances come from the value names of Instance Names\SQL; the 'PS*' filter dropped names such as PSREPORTING. Tests for each, including the real registry operations on an HKCU test key. Pester green on PowerShell 7.6 (63) and Windows PowerShell 5.1 (62, 1 skipped). Co-Authored-By: Claude Opus 5.5 <[email protected]>
3.4 KiB
scripts
Backup and restore scripts arrive in phase 9: a per-stack pg_dump backup with a
systemd timer on docker-1, and a restore script with a rehearsal recorded in docs/DEPLOY.md.
Export-PescoCaBundle.ps1
Run on a domain-joined PC. Exports every unexpired PESCO CA certificate from the Windows stores to one PEM bundle and copies it to docker-1 with scp (default target ~/packetstation/test/ca/pesco-ca.pem). Use -Remote for another path and -NoCopy to only write the file. It warns on SHA-1 signed certificates; see docs/DEPLOY.md.
Request-VsqlServerCertificate.ps1
Run elevated on the SQL Server host behind vsql, in Windows PowerShell 5.1 or PowerShell 7. Requests a TLS certificate from PESCO-PSYLOCKE-CA with certreq the way SQL Server requires it (legacy Microsoft RSA SChannel Cryptographic Provider, KeySpec AT_KEYEXCHANGE, RSA 2048, SHA-256, Server Authentication, key usage 0xA0, SANs vsql.pesco.com, vsql and the host FQDN and short name). It installs it and validates it before anything is bound. The validation checks the key provider and KeySpec from the certificate's own key property, the key size, the signature, the dates, the EKU, and the SAN DNS names as whole names. It grants only the selected instances' service accounts read on the private key, then binds the thumbprint and reads it back.
-WhatIfpreviews every step and changes nothing.-Confirmasks before each change. Declining enrollment or a key grant cancels the run with nothing bound (exit code 2).-CerFilecontinues a request that was pending.-Thumbprintbinds a certificate already installed.-Instanceslimits the run (DEV,MSSQLSERVER).-RestartInstancesrestarts them and starts SQL Server Agent again if it ran. The running dependents are written todependents-<service>.jsonbefore the stop and the file is removed once they run again, so after a failed restart the next restart of that service starts them too.- Each deployment writes a new
deploy-<time>.jsoninC:\ProgramData\PacketStation\vsql-certwith the values it replaced. Instances already bound to the thumbprint are left alone and get no snapshot, so a rerun never hides the useful one. A pending request writesrequest-<time>.jsonwith its request id. A registry value that cannot be read stops the run; only a value confirmed absent is saved as absent. -Rollbackrestores the newest snapshot not yet rolled back, each instance on its own, verified by reading back, and records it inrollback-<time>.jsonwith which restarts succeeded. A snapshot stays open while an instance is unrestored or its restart failed, so-Rollback -RestartInstancesagain retries exactly those.-Snapshotpicks another. Failures are listed and the run exits with an error.- Instances are read from the value names of
Instance Names\SQL, so a name starting withPS(for examplePSREPORTING) is found.
Tests: scripts/tests/Request-VsqlServerCertificate.Tests.ps1 (Pester 5) fakes the host (instances, services, registry, machine store, certreq, icacls) and uses real throwaway certificates in Cert:\CurrentUser\My. Run it on both PowerShell versions:
Install-Module Pester -RequiredVersion 5.7.1 -Scope CurrentUser -SkipPublisherCheck
Invoke-Pester -Path scripts ests -Output Detailed
The run procedure is in docs/DEPLOY.md, under the vsql known issue. Gitea issue 5 tracks the switch to VISUAL_ENCRYPT=yes.