backup permission fix
This commit is contained in:
BIN
backups/gitea-db-backup-2025-03-28_18-23-22.sql.zip
Normal file
BIN
backups/gitea-db-backup-2025-03-28_18-23-22.sql.zip
Normal file
Binary file not shown.
@@ -14,15 +14,27 @@ $action = New-ScheduledTaskAction -Execute "PowerShell.exe" -Argument "-NoProfil
|
|||||||
$trigger = New-ScheduledTaskTrigger -Daily -At 3AM
|
$trigger = New-ScheduledTaskTrigger -Daily -At 3AM
|
||||||
$settings = New-ScheduledTaskSettingsSet -StartWhenAvailable -DontStopOnIdleEnd -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries
|
$settings = New-ScheduledTaskSettingsSet -StartWhenAvailable -DontStopOnIdleEnd -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries
|
||||||
|
|
||||||
|
# Create a principal that runs with highest privileges
|
||||||
|
$principal = New-ScheduledTaskPrincipal -UserId "NT AUTHORITY\SYSTEM" -LogonType ServiceAccount -RunLevel Highest
|
||||||
|
|
||||||
# Register the scheduled task
|
# Register the scheduled task
|
||||||
$taskExists = Get-ScheduledTask -TaskName $taskName -ErrorAction SilentlyContinue
|
$taskExists = Get-ScheduledTask -TaskName $taskName -ErrorAction SilentlyContinue
|
||||||
|
|
||||||
if ($taskExists) {
|
if ($taskExists) {
|
||||||
Write-Host "Task '$taskName' already exists. Updating..." -ForegroundColor Yellow
|
Write-Host "Task '$taskName' already exists. Updating..." -ForegroundColor Yellow
|
||||||
Set-ScheduledTask -TaskName $taskName -Action $action -Trigger $trigger -Settings $settings -Description $taskDescription
|
# Get the existing task
|
||||||
|
$task = Get-ScheduledTask -TaskName $taskName
|
||||||
|
# Update the task properties
|
||||||
|
$task.Actions = $action
|
||||||
|
$task.Triggers = $trigger
|
||||||
|
$task.Settings = $settings
|
||||||
|
$task.Principal = $principal
|
||||||
|
$task.Description = $taskDescription
|
||||||
|
# Save the updated task
|
||||||
|
Set-ScheduledTask -InputObject $task
|
||||||
} else {
|
} else {
|
||||||
Write-Host "Creating new scheduled task '$taskName'..." -ForegroundColor Green
|
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"
|
Register-ScheduledTask -TaskName $taskName -Action $action -Trigger $trigger -Settings $settings -Description $taskDescription -Principal $principal
|
||||||
}
|
}
|
||||||
|
|
||||||
Write-Host "Scheduled task setup complete. The database will be backed up daily at 3 AM." -ForegroundColor Green
|
Write-Host "Scheduled task setup complete. The database will be backed up daily at 3 AM." -ForegroundColor Green
|
||||||
|
|||||||
Reference in New Issue
Block a user