restic-scripts-win/backup.ps1

35 lines
1 KiB
PowerShell
Raw Normal View History

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..."
curl https://hc-ping.com/$HEALTHCHECK_UUID/fail
exit
}
Write-Host "Not currently running. Continuing..."
curl https://hc-ping.com/$HEALTHCHECK_UUID/start
if ( $PRE_RUN_SCRIPT ) {
. $dir/$PRE_RUN_SCRIPT
}
Invoke-Expression $BACKUP_CMD
if ( $LastExitCode -eq 0 ) {
if ( $POST_RUN_SCRIPT ) {
. $dir/$POST_RUN_SCRIPT
}
curl https://hc-ping.com/$HEALTHCHECK_UUID
} else {
curl https://hc-ping.com/$HEALTHCHECK_UUID/fail
}