restic-scripts-win/backup.ps1

57 lines
1.8 KiB
PowerShell
Raw Normal View History

2023-01-26 15:32:09 +01:00
2024-03-13 12:42:36 +01:00
Set-Alias -Name .bin/curl.exe -Value ./bin/.bin/curl.exe.exe
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"
$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 12:24:06 +01:00
if ( $KUMA_ID -ne "" ){
2024-03-13 12:42:36 +01:00
.bin/curl.exe https://$KUMA_URL/api/push/$KUMA_ID?status=down"&"msg=Failed"&"ping=
2024-03-13 12:24:06 +01:00
}
if ( $HEALTHCHECK_UUID -ne "" ) {
2024-03-13 12:42:36 +01:00
.bin/curl.exe https://hc-ping.com/$HEALTHCHECK_UUID/fail
2024-03-13 12:24:06 +01:00
}
2023-01-26 15:32:09 +01:00
exit
}
Write-Host "Not currently running. Continuing..."
2024-03-13 12:24:06 +01:00
if ( $KUMA_ID -ne "" ){
2024-03-13 12:42:36 +01:00
.bin/curl.exe https://$KUMA_URL/api/push/$KUMA_ID?status=up"&"msg=Running"&"ping=
2024-03-13 12:24:06 +01:00
}
if ( $HEALTHCHECK_UUID -ne "" ) {
2024-03-13 12:42:36 +01:00
.bin/curl.exe https://hc-ping.com/$HEALTHCHECK_UUID/start
2024-03-13 12:24:06 +01:00
}
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
}
if ( $KUMA_ID -ne "" ){
2024-03-13 12:42:36 +01:00
.bin/curl.exe https://$KUMA_URL/api/push/$KUMA_ID?status=up"&"msg=Completed"&"ping=
2024-03-13 12:24:06 +01:00
}
if ( $HEALTHCHECK_UUID -ne "" ) {
2024-03-13 12:42:36 +01:00
.bin/curl.exe https://hc-ping.com/$HEALTHCHECK_UUID
2024-03-13 12:24:06 +01:00
}
2023-01-26 15:32:09 +01:00
} else {
2024-03-13 12:24:06 +01:00
if ( $KUMA_ID -ne "" ){
2024-03-13 12:42:36 +01:00
.bin/curl.exe https://$KUMA_URL/api/push/$KUMA_ID?status=down"&"msg=Failed"&"ping=
2024-03-13 12:24:06 +01:00
}
if ( $HEALTHCHECK_UUID -ne "" ) {
2024-03-13 12:42:36 +01:00
.bin/curl.exe https://hc-ping.com/$HEALTHCHECK_UUID/fail
2024-03-13 12:24:06 +01:00
}
2023-01-26 15:32:09 +01:00
}