29 lines
1.6 KiB
PowerShell
29 lines
1.6 KiB
PowerShell
# Script to create a scheduled task for Gitea database backups
|
|
$scriptPath = Join-Path (Get-Location) "backup-gitea-db.ps1"
|
|
$taskName = "GiteaDatabaseBackup"
|
|
$taskDescription = "Regular backup of Gitea PostgreSQL database"
|
|
|
|
# Check if the backup script exists
|
|
if (-not (Test-Path $scriptPath)) {
|
|
Write-Host "Backup script not found at: $scriptPath" -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
|
|
# Create a scheduled task to run daily at 3 AM
|
|
$action = New-ScheduledTaskAction -Execute "PowerShell.exe" -Argument "-NoProfile -ExecutionPolicy Bypass -File `"$scriptPath`""
|
|
$trigger = New-ScheduledTaskTrigger -Daily -At 3AM
|
|
$settings = New-ScheduledTaskSettingsSet -StartWhenAvailable -DontStopOnIdleEnd -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries
|
|
|
|
# Register the scheduled task
|
|
$taskExists = Get-ScheduledTask -TaskName $taskName -ErrorAction SilentlyContinue
|
|
|
|
if ($taskExists) {
|
|
Write-Host "Task '$taskName' already exists. Updating..." -ForegroundColor Yellow
|
|
Set-ScheduledTask -TaskName $taskName -Action $action -Trigger $trigger -Settings $settings -Description $taskDescription
|
|
} else {
|
|
Write-Host "Creating new scheduled task '$taskName'..." -ForegroundColor Green
|
|
Register-ScheduledTask -TaskName $taskName -Action $action -Trigger $trigger -Settings $settings -Description $taskDescription -User "$env:USERDOMAIN\$env:USERNAME"
|
|
}
|
|
|
|
Write-Host "Scheduled task setup complete. The database will be backed up daily at 3 AM." -ForegroundColor Green
|
|
Write-Host "Backup files will be stored in the 'backups' folder in your Gitea Docker directory." -ForegroundColor Green |