forked from djmaze/resticker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprune
More file actions
executable file
·39 lines (30 loc) · 766 Bytes
/
Copy pathprune
File metadata and controls
executable file
·39 lines (30 loc) · 766 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
#!/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:-}"
start=$(date +%s)
echo Starting prune at "$(date +"%Y-%m-%d %H:%M:%S")"
set +e
if ! restic prune ${RESTIC_PRUNE_ARGS:-} "${RESTIC_REPOSITORY}"; then
set -e
run_commands "${POST_COMMANDS_FAILURE:-}"
exit
else
set -e
fi
echo Prune successful
end="$(date +%s)"
echo Finished prune at "$(date +"%Y-%m-%d %H:%M:%S")" after $((end-start)) seconds
run_commands "${POST_COMMANDS_SUCCESS:-}"
}
trap run_exit_commands EXIT
main "$@"