qvw-preserve-interface/templates/Backup_QVW.ps1

29 lines
1.2 KiB
PowerShell
Raw Normal View History

# Backup_QVW.ps1 — rolling ring of pre-reload QVW snapshots.
# Usage: powershell -File Backup_QVW.ps1 -QvwPath "..\4.Apps.QVW\MyApp.qvw" [-Keep 20]
# Default retention 20 slots (a day of reloads won't evict good edits).
# NOTE: this is a FALLBACK. Primary safety net is git commits in Reload_*.bat.
param(
[Parameter(Mandatory=$true)][string]$QvwPath,
[int]$Keep = 20
)
$ErrorActionPreference = "Stop"
if (-not (Test-Path $QvwPath)) { Write-Host "No QVW to back up: $QvwPath"; exit 0 }
$dir = Split-Path $QvwPath -Parent
$name = [System.IO.Path]::GetFileNameWithoutExtension($QvwPath)
$ext = [System.IO.Path]::GetExtension($QvwPath)
$backupDir = Join-Path $dir "backups"
if (-not (Test-Path $backupDir)) { New-Item -ItemType Directory -Path $backupDir -Force | Out-Null }
$stamp = Get-Date -Format "yyyyMMdd_HHmmss"
$dest = Join-Path $backupDir ($name + "_" + $stamp + $ext)
Copy-Item $QvwPath $dest -Force
Write-Host "Backed up: $dest"
# Prune: keep only $Keep most-recent backups matching "$name_*.qvw"
Get-ChildItem $backupDir -Filter ($name + "_*" + $ext) -File |
Sort-Object LastWriteTime -Descending |
Select-Object -Skip $Keep |
ForEach-Object { Remove-Item $_.FullName -Force; Write-Host "Pruned: $($_.Name)" }