44 lines
1.5 KiB
PowerShell
44 lines
1.5 KiB
PowerShell
|
|
|
|
$dir = Split-Path $script:MyInvocation.MyCommand.Path
|
|
. "$dir/env.ps1"
|
|
if ( $KUMA_ID -ne "" ){
|
|
$RUNNING_URL = "https://$KUMA_URL/api/push/$($KUMA_ID)?status=up&msg=Running&ping="
|
|
$FAILURE_URL = "https://$KUMA_URL/api/push/$($KUMA_ID)?status=down&msg=Failed&ping="
|
|
$SUCCESS_URL = "https://$KUMA_URL/api/push/$($KUMA_ID)?status=up&msg=Completed&ping="
|
|
} elseif ( $HEALTHCHECK_UUID -ne "" ) {
|
|
$RUNNING_URL = "https://hc-ping.com/$HEALTHCHECK_UUID/start"
|
|
$FAILURE_URL = "https://hc-ping.com/$HEALTHCHECK_UUID/fail"
|
|
$SUCCESS_URL = "https://hc-ping.com/$HEALTHCHECK_UUID"
|
|
}
|
|
$DATE = (Get-Date).ToString("yyyy-MM-dd HH:mm:ss")
|
|
Write-Host "Backup $NAME at $DATE"
|
|
$BACKUP_CMD="restic backup $BACKUP_DIR"
|
|
if ( $BACKUP_PARAMS ){
|
|
$BACKUP_CMD="$BACKUP_CMD $BACKUP_PARAMS"
|
|
}
|
|
if ( $BACKUP_EXCLUDE_FILE ) {
|
|
$BACKUP_CMD="$BACKUP_CMD --exclude-file $dir/$BACKUP_EXCLUDE_FILE"
|
|
}
|
|
#Write-Host $BACKUP_CMD
|
|
$running = get-process | ?{$_.path -eq "C:\Windows\system32\restic.exe"}
|
|
Write-Host $running
|
|
if ( $running ) {
|
|
Write-Host "Backup already running; $running. Exiting..."
|
|
./bin/curl.exe $FAILURE_URL
|
|
exit
|
|
}
|
|
Write-Host "Not currently running. Continuing..."
|
|
./bin/curl.exe $RUNNING_URL
|
|
if ( $PRE_RUN_SCRIPT ) {
|
|
. $dir/$PRE_RUN_SCRIPT
|
|
}
|
|
Invoke-Expression $BACKUP_CMD
|
|
if ( $LastExitCode -eq 0 ) {
|
|
if ( $POST_RUN_SCRIPT ) {
|
|
. $dir/$POST_RUN_SCRIPT
|
|
}
|
|
./bin/curl.exe $SUCCESS_URL
|
|
} else {
|
|
./bin/curl.exe $FAILURE_URL
|
|
}
|