$ErrorActionPreference = "Stop"
$BackupDir = if ($args[0]) { $args[0] } else { ".\backups" }
$Timestamp = Get-Date -Format "yyyyMMdd_HHmmss"
New-Item -ItemType Directory -Force -Path $BackupDir | Out-Null

Write-Host "Backing up database..."
docker compose exec -T db pg_dump -U postgres student_archive | Out-File -Encoding utf8 "$BackupDir\db_$Timestamp.sql"

Write-Host "Backing up uploads..."
Compress-Archive -Path "uploads\*" -DestinationPath "$BackupDir\uploads_$Timestamp.zip" -Force

Write-Host "Backup complete:"
Write-Host "  $BackupDir\db_$Timestamp.sql"
Write-Host "  $BackupDir\uploads_$Timestamp.zip"
