Enhance Gitea database backup script with relative paths, logging, and Docker checks; update scheduling script to include Docker check

This commit is contained in:
2025-04-19 19:36:36 -06:00
parent 5f329bc7e3
commit cba5e8167b
8 changed files with 157 additions and 9 deletions

View File

@@ -1,5 +1,7 @@
# Script to create a scheduled task for Gitea database backups
$scriptPath = Join-Path (Get-Location) "backup-gitea-db.ps1"
$workingDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$scriptPath = Join-Path $workingDir "backup-gitea-db.ps1"
$dockerCheckScript = Join-Path $workingDir "ensure-docker-running.ps1"
$taskName = "GiteaDatabaseBackup"
$taskDescription = "Regular backup of Gitea PostgreSQL database"
@@ -9,8 +11,32 @@ if (-not (Test-Path $scriptPath)) {
exit 1
}
# Check if the Docker check script exists
if (-not (Test-Path $dockerCheckScript)) {
Write-Host "Docker check script not found at: $dockerCheckScript" -ForegroundColor Red
exit 1
}
# Create a batch script that runs both scripts
$batchScriptPath = Join-Path $workingDir "run-backup.ps1"
@"
# This script is automatically generated - do not edit manually
# It runs the Docker check script followed by the backup script
# Get the script directory
`$scriptDir = Split-Path -Parent `$MyInvocation.MyCommand.Path
# Run the Docker check script first
`$dockerCheckScript = Join-Path `$scriptDir "ensure-docker-running.ps1"
& `$dockerCheckScript
# Then run the backup script
`$backupScript = Join-Path `$scriptDir "backup-gitea-db.ps1"
& `$backupScript
"@ | Out-File -FilePath $batchScriptPath -Encoding utf8
# Create a scheduled task to run daily at 3 AM
$action = New-ScheduledTaskAction -Execute "PowerShell.exe" -Argument "-NoProfile -ExecutionPolicy Bypass -File `"$scriptPath`""
$action = New-ScheduledTaskAction -Execute "PowerShell.exe" -Argument "-NoProfile -ExecutionPolicy Bypass -File `"$batchScriptPath`"" -WorkingDirectory "$workingDir"
$trigger = New-ScheduledTaskTrigger -Daily -At 3AM
$settings = New-ScheduledTaskSettingsSet -StartWhenAvailable -DontStopOnIdleEnd -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries