.dots/scripts/restic/prune.sh
2024-10-28 13:42:07 +01:00

26 lines
889 B
Bash
Executable file

#!/usr/bin/env zsh
# author: Daniel Sommer <daniel.sommer@velvettear.de>
# license: MIT
# check if we're running in a subshell, forbid direct execution
[[ "$ZSH_EVAL_CONTEXT" == "toplevel" ]] && printf "error: direct execution of this script is forbidden!\n" >&2 && exit 1
# define title and icon for the notification
export RESTIC_NTFY_TITLE="prune"
export RESTIC_NTFY_ICON="red_circle"
# clear cache directory
rm -rf "/var/cache/restic"
printf ">> pruning repository '"$RESTIC_REPOSITORY"'...\n\n"
# execute "pre" action if defined
[[ -n "$RESTIC_PRUNE_PRE" ]] && eval "$RESTIC_PRUNE_PRE"
sudo --preserve-env -u "$RESTIC_USER" restic forget --keep-daily 7 --keep-weekly 1 --keep-monthly 1 --prune --retry-lock 3h --no-cache
# execute "post" action if defined
[[ -n "$RESTIC_PRUNE_POST" ]] && eval "$RESTIC_PRUNE_POST"
printf "\n>> repository pruned after "$SECONDS" seconds!\n"