restic-scripts-win/backup.ps1

45 lines
1.5 KiB
PowerShell
Raw Normal View History

2023-01-26 15:32:09 +01:00
2024-03-13 12:40:09 +01:00
2023-01-26 15:32:09 +01:00
$dir = Split-Path $script:MyInvocation.MyCommand.Path
. "$dir/env.ps1"
2024-03-13 18:03:23 +01:00
if ( $KUMA_ID -ne "" ){
2024-03-13 18:06:37 +01:00
$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="
2024-03-13 18:04:17 +01:00
} elseif ( $HEALTHCHECK_UUID -ne "" ) {
2024-03-13 18:05:33 +01:00
$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"
2024-03-13 18:03:23 +01:00
}
2023-01-26 15:32:09 +01:00
$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..."
2024-03-13 18:03:23 +01:00
./bin/curl.exe $FAILURE_URL
2023-01-26 15:32:09 +01:00
exit
}
Write-Host "Not currently running. Continuing..."
2024-03-13 18:03:23 +01:00
./bin/curl.exe $RUNNING_URL
2023-01-26 15:32:09 +01:00
if ( $PRE_RUN_SCRIPT ) {
. $dir/$PRE_RUN_SCRIPT
}
Invoke-Expression $BACKUP_CMD
if ( $LastExitCode -eq 0 ) {
if ( $POST_RUN_SCRIPT ) {
. $dir/$POST_RUN_SCRIPT
2024-03-13 12:24:06 +01:00
}
2024-03-13 18:03:23 +01:00
./bin/curl.exe $SUCCESS_URL
2023-01-26 15:32:09 +01:00
} else {
2024-03-13 18:03:23 +01:00
./bin/curl.exe $FAILURE_URL
2023-01-26 15:32:09 +01:00
}