Files
craft2prints/backup-database.ps1
AndymickandClaude Haiku 4.5 3fe38a7c2f Feature: Add bulk upload for gallery photos and database backup script
- New bulk upload page at /admin/gallery/bulk for uploading multiple photos at once
- File preview list with ability to remove files before uploading
- Category assignment for all uploaded photos in bulk
- Accessible from both gallery page and single photo upload page
- Added PostgreSQL backup script for daily database snapshots
- Backups kept as local SQL dumps with automatic cleanup of old files

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-07-19 15:06:28 +01:00

38 lines
1.2 KiB
PowerShell

# PostgreSQL Database Backup Script
# Backs up the craft2prints database daily
$backupDir = "D:\Craft2Prints\database-backups"
$pgBin = "C:\Program Files\PostgreSQL\18\bin"
$dbName = "craft2prints"
$dbUser = "postgres"
$dbHost = "localhost"
$dbPort = "5432"
# Create backup directory if it doesn't exist
if (!(Test-Path $backupDir)) {
New-Item -ItemType Directory -Path $backupDir | Out-Null
}
# Create timestamped backup filename
$timestamp = Get-Date -Format "yyyy-MM-dd_HH-mm-ss"
$backupFile = "$backupDir\craft2prints_$timestamp.sql"
# Run pg_dump
Write-Host "Backing up database to $backupFile..."
$env:PGPASSWORD = "postgres"
& "$pgBin\pg_dump.exe" -h $dbHost -p $dbPort -U $dbUser -d $dbName -F p -f $backupFile
$exitCode = $LASTEXITCODE
if ($exitCode -eq 0) {
Write-Host "Backup completed successfully"
# Keep only the last 7 backups
$backups = Get-ChildItem $backupDir -Filter "craft2prints_*.sql" | Sort-Object CreationTime -Descending
if ($backups.Count -gt 7) {
$backups | Select-Object -Skip 7 | Remove-Item
Write-Host "Cleaned up old backups (kept 7 most recent)"
}
} else {
Write-Host "Backup failed with exit code $exitCode"
}