forked from djmaze/resticker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prune
executable file
·45 lines (34 loc) · 953 Bytes
/
prune
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
#!/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)
if [ -n "${RESTIC_FORGET_ARGS:-}" ]; then
echo Forget about old snapshots based on RESTIC_FORGET_ARGS = ${RESTIC_FORGET_ARGS}
restic forget ${RESTIC_FORGET_ARGS}
fi
echo Starting prune at "$(date +"%Y-%m-%d %H:%M:%S")"
set +e
if ! restic --repo="${RESTIC_REPOSITORY}" prune ${RESTIC_PRUNE_ARGS:-} ; 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 "$@"