Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ PRE_COMMANDS: |-
```

The commands specified in `PRE_COMMANDS` are executed one by one.
In case of a failure, `PRE_COMMANDS_FAILURE` will be executed, if set.
The backup will be aborted if `ABORT_ON_PRE_COMMANDS_FAILURE` is set to `"true"`.

## Execute commands after backup

Expand Down
23 changes: 21 additions & 2 deletions backup
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@
set -eo pipefail

function run_commands {
COMMANDS=$1
while IFS= read -r cmd; do echo "$cmd" && eval "$cmd" ; done < <(printf '%s\n' "$COMMANDS")
COMMANDS=$1
RESULT=0
while IFS= read -r cmd; do
echo "$cmd" && eval "$cmd"
if [ $? -ne 0 ]; then
RESULT=1
fi
done < <(printf '%s\n' "$COMMANDS")
return $RESULT
}

function run_exit_commands {
Expand Down Expand Up @@ -42,7 +49,19 @@ touch /run/lock/backup.lock

trap run_exit_commands EXIT

set +e
run_commands "${PRE_COMMANDS:-}"
pre_result=$?
set -e
if [ $pre_result -ne 0 ]; then
echo "Warning: At least one command of PRE_COMMANDS exited with a non-zero exit code."
run_commands "${PRE_COMMANDS_FAILURE:-}"

if [ "${ABORT_ON_PRE_COMMANDS_FAILURE:-}" == "true" ]; then
rm -f /run/lock/backup.lock
exit 1
fi
fi

IFS=" " read -r -a RESTIC_BACKUP_SOURCES <<< "$(replace_spaces "${RESTIC_BACKUP_SOURCES:-/data}")"
RESTIC_BACKUP_TAGS="${RESTIC_BACKUP_TAGS:-}"
Expand Down
22 changes: 20 additions & 2 deletions check
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@
set -euo pipefail

function run_commands {
COMMANDS=$1
while IFS= read -r cmd; do echo $cmd && eval $cmd ; done < <(printf '%s\n' "$COMMANDS")
COMMANDS=$1
RESULT=0
while IFS= read -r cmd; do
echo "$cmd" && eval "$cmd"
if [ $? -ne 0 ]; then
RESULT=1
fi
done < <(printf '%s\n' "$COMMANDS")
return $RESULT
}

function run_exit_commands {
Expand All @@ -13,7 +20,18 @@ function run_exit_commands {
}

main() {
set +e
run_commands "${PRE_COMMANDS:-}"
pre_result=$?
set -e
if [ $pre_result -ne 0 ]; then
echo "Warning: At least one command of PRE_COMMANDS exited with a non-zero exit code."
run_commands "${PRE_COMMANDS_FAILURE:-}"

if [ "${ABORT_ON_PRE_COMMANDS_FAILURE:-}" == "true" ]; then
exit 1
fi
fi

start=$(date +%s)
echo Starting check at "$(date +"%Y-%m-%d %H:%M:%S")"
Expand Down
22 changes: 20 additions & 2 deletions prune
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@
set -euo pipefail

function run_commands {
COMMANDS=$1
while IFS= read -r cmd; do echo $cmd && eval $cmd ; done < <(printf '%s\n' "$COMMANDS")
COMMANDS=$1
RESULT=0
while IFS= read -r cmd; do
echo "$cmd" && eval "$cmd"
if [ $? -ne 0 ]; then
RESULT=1
fi
done < <(printf '%s\n' "$COMMANDS")
return $RESULT
}

function run_exit_commands {
Expand All @@ -13,7 +20,18 @@ function run_exit_commands {
}

main() {
set +e
run_commands "${PRE_COMMANDS:-}"
pre_result=$?
set -e
if [ $pre_result -ne 0 ]; then
echo "Warning: At least one command of PRE_COMMANDS exited with a non-zero exit code."
run_commands "${PRE_COMMANDS_FAILURE:-}"

if [ "${ABORT_ON_PRE_COMMANDS_FAILURE:-}" == "true" ]; then
exit 1
fi
fi

start=$(date +%s)

Expand Down