Files
Comtropy_CargoRadar/scripts/backup-runtime-data.ps1

25 lines
692 B
PowerShell

param(
[string]$DataDir = "runtime-data",
[string]$BackupDir = "backups"
)
$ErrorActionPreference = "Stop"
$root = (Resolve-Path ".").Path
$resolvedDataDir = Resolve-Path $DataDir
if (-not $resolvedDataDir.Path.StartsWith($root)) {
throw "Refusing to back up a path outside the repository: $($resolvedDataDir.Path)"
}
New-Item -ItemType Directory -Path $BackupDir -Force | Out-Null
$timestamp = Get-Date -Format "yyyyMMdd-HHmmss"
$archivePath = Join-Path $BackupDir "cargoradar-runtime-$timestamp.zip"
Compress-Archive -Path (Join-Path $resolvedDataDir.Path "*") -DestinationPath $archivePath -Force
[pscustomobject]@{
Backup = (Resolve-Path $archivePath).Path
} | Format-List