From a60c7000e46d72c9b6665c454e8502e851374725 Mon Sep 17 00:00:00 2001 From: Paul Wilde Date: Thu, 26 Jan 2023 14:32:09 +0000 Subject: [PATCH] first for win --- .gitignore | 6 ++-- backup.ps1 | 74 +++++++++++++++++++++++++------------------------- env.sample.ps1 | 42 ++++++++++++++-------------- init.ps1 | 4 +-- readme.md | 4 +-- snapshots.ps1 | 4 +-- 6 files changed, 67 insertions(+), 67 deletions(-) diff --git a/.gitignore b/.gitignore index f184348..1b33ff1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -env.ps1 -exclusions.txt -pre +env.ps1 +exclusions.txt +pre post \ No newline at end of file diff --git a/backup.ps1 b/backup.ps1 index 45eb6d7..ef5170f 100644 --- a/backup.ps1 +++ b/backup.ps1 @@ -1,37 +1,37 @@ - -$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" -} -if ( $USE_VSS -eq 1 ) { - $BACKUP_CMD = "$BACKUP_CMD --use-windows-vss" -} -#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 -} + +$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" +} +if ( $USE_VSS -eq 1 ) { + $BACKUP_CMD = "$BACKUP_CMD --use-windows-vss" +} +#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 +} diff --git a/env.sample.ps1 b/env.sample.ps1 index bbf0c61..38bc8e1 100644 --- a/env.sample.ps1 +++ b/env.sample.ps1 @@ -1,22 +1,22 @@ -# Name your backup (only really for logging purposes) -$NAME="Backup Name" -# The directory to back up -$BACKUP_DIR="/dir/to/back/up" -# any additional params you want with restic -$BACKUP_PARAMS="" -# an exclude file, generally I use "exclusions.txt" that's ignored by git -$BACKUP_EXCLUDE_FILE="" -# https://healthchecks.io uuid -$HEALTHCHECK_UUID="" -# name of a script to run before (ideally in the "pre/" dir) -$PRE_RUN_SCRIPT="" -# name of a script to run after (ideally in the "post/" dir) -$POST_RUN_SCRIPT="" -# Use VSS -$USE_VSS = 1 - - -$Env:AWS_ACCESS_KEY_ID= -$Env:AWS_SECRET_ACCESS_KEY= -$Env:RESTIC_REPOSITORY="s3:https://repo.tld/bucket/sub-bucket" +# Name your backup (only really for logging purposes) +$NAME="Backup Name" +# The directory to back up +$BACKUP_DIR="/dir/to/back/up" +# any additional params you want with restic +$BACKUP_PARAMS="" +# an exclude file, generally I use "exclusions.txt" that's ignored by git +$BACKUP_EXCLUDE_FILE="" +# https://healthchecks.io uuid +$HEALTHCHECK_UUID="" +# name of a script to run before (ideally in the "pre/" dir) +$PRE_RUN_SCRIPT="" +# name of a script to run after (ideally in the "post/" dir) +$POST_RUN_SCRIPT="" +# Use VSS +$USE_VSS = 1 + + +$Env:AWS_ACCESS_KEY_ID= +$Env:AWS_SECRET_ACCESS_KEY= +$Env:RESTIC_REPOSITORY="s3:https://repo.tld/bucket/sub-bucket" $Env:RESTIC_PASSWORD=V3RYSecuRepaSsWord \ No newline at end of file diff --git a/init.ps1 b/init.ps1 index 539fe80..5217bab 100644 --- a/init.ps1 +++ b/init.ps1 @@ -1,3 +1,3 @@ -$dir = Split-Path $script:MyInvocation.MyCommand.Path -. $dir/env.ps1 +$dir = Split-Path $script:MyInvocation.MyCommand.Path +. $dir/env.ps1 Invoke-Expression "restic init" \ No newline at end of file diff --git a/readme.md b/readme.md index efd3204..96ac525 100644 --- a/readme.md +++ b/readme.md @@ -1,2 +1,2 @@ -A set of scripts to simplify running restic backup jobs via scheduler. -Also includes curl resquests to healthchecks.io service for monitoring purposes +A set of scripts to simplify running restic backup jobs via scheduler. +Also includes curl resquests to healthchecks.io service for monitoring purposes diff --git a/snapshots.ps1 b/snapshots.ps1 index de3702e..42081ad 100644 --- a/snapshots.ps1 +++ b/snapshots.ps1 @@ -1,3 +1,3 @@ -$dir = Split-Path $script:MyInvocation.MyCommand.Path -. $dir/env.ps1 +$dir = Split-Path $script:MyInvocation.MyCommand.Path +. $dir/env.ps1 Invoke-Expression "restic snapshots" \ No newline at end of file