-
Notifications
You must be signed in to change notification settings - Fork 80
Expand file tree
/
Copy pathcheck
More file actions
executable file
·46 lines (36 loc) · 1004 Bytes
/
check
File metadata and controls
executable file
·46 lines (36 loc) · 1004 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/bin/bash
set -euo pipefail
function run_commands {
COMMANDS=$1
while IFS= read -r cmd; do echo $cmd && eval $cmd ; done < <(printf '%s\n' "$COMMANDS")
}
function run_exit_commands {
set +e
set +o pipefail
run_commands "${POST_COMMANDS_EXIT:-}"
}
main() {
run_commands "${PRE_COMMANDS:-}"
repo_arg="--repo=${RESTIC_REPOSITORY}"
if [ -n "${RESTIC_REPOSITORY_FILE:-}" ]; then
echo Using restic repository file at $RESTIC_REPOSITORY_FILE
repo_arg="--repository-file=${RESTIC_REPOSITORY_FILE}"
unset RESTIC_REPOSITORY
fi
start=$(date +%s)
echo Starting check at "$(date +"%Y-%m-%d %H:%M:%S")"
set +e
if ! restic "${repo_arg}" check ${RESTIC_CHECK_ARGS:-}; then
set -e
run_commands "${POST_COMMANDS_FAILURE:-}"
exit
else
set -e
fi
echo Check successful
end="$(date +%s)"
echo Finished check at "$(date +"%Y-%m-%d %H:%M:%S")" after $((end-start)) seconds
run_commands "${POST_COMMANDS_SUCCESS:-}"
}
trap run_exit_commands EXIT
main "$@"