# Synopsis: Creates timestamped orchestrator backups.
# Description: Saves a secure copy of the active orchestrator system script to the snapshots folder.

$BaseDir = Split-Path (Split-Path $PSScriptRoot -Parent) -Parent
$SourceFile = Join-Path $BaseDir "Scripts\AgentOSX.ps1"
$BackupDir = Join-Path $BaseDir "Memory\Snapshots"

if (!(Test-Path $BackupDir)) { New-Item -ItemType Directory -Path $BackupDir -Force | Out-Null }

if (Test-Path $SourceFile) {
    $Timestamp = (Get-Date).ToString("yyyyMMdd_HHmmss")
    $DestFile = Join-Path $BackupDir "AgentOSX_Backup_$Timestamp.ps1"
    Copy-Item -Path $SourceFile -Destination $DestFile -Force
    Write-Host "SUCCESS: Orchestrator snapshot saved to: $DestFile" -ForegroundColor Green
} else {
    Write-Host "ERROR: Source orchestrator file not found at $SourceFile" -ForegroundColor Red
}

