Run restic prune before backup
This commit is contained in:
parent
0338a60747
commit
cb5971876f
@ -135,7 +135,7 @@ sudo_rules:
|
|||||||
|
|
||||||
restic_repos:
|
restic_repos:
|
||||||
- name: b2
|
- name: b2
|
||||||
repo: "b2:kill0-infra-backup:"
|
repo: "b2:kill0-infra-backup:/{{ inventory_hostname_short }}"
|
||||||
environment:
|
environment:
|
||||||
RESTIC_PASSWORD: "{{ vault_restic_repo_b2_password }}"
|
RESTIC_PASSWORD: "{{ vault_restic_repo_b2_password }}"
|
||||||
B2_ACCOUNT_ID: "{{ vault_restic_repo_b2_account_id }}"
|
B2_ACCOUNT_ID: "{{ vault_restic_repo_b2_account_id }}"
|
||||||
|
@ -33,7 +33,7 @@ main() {
|
|||||||
gitea dump \
|
gitea dump \
|
||||||
--config "$GITEA_CONFIG" \
|
--config "$GITEA_CONFIG" \
|
||||||
--work-path "$GITEA_WORK_PATH" \
|
--work-path "$GITEA_WORK_PATH" \
|
||||||
--custom-path "$GITEA_CUSTOM_PATH" > /dev/null
|
--custom-path "$GITEA_CUSTOM_PATH" >/dev/null 2>&1
|
||||||
printf "gitea dump complete\n"
|
printf "gitea dump complete\n"
|
||||||
popd > /dev/null || printf "could not chdir to %s\n" "$OLDPWD"
|
popd > /dev/null || printf "could not chdir to %s\n" "$OLDPWD"
|
||||||
elif [ "$1" == "post" ]; then
|
elif [ "$1" == "post" ]; then
|
||||||
|
@ -19,8 +19,14 @@ NICE="ionice -c2 nice -n19"
|
|||||||
JOB=$1
|
JOB=$1
|
||||||
LOCK="/run/restic/${JOB}.lock"
|
LOCK="/run/restic/${JOB}.lock"
|
||||||
|
|
||||||
|
KEEP_HOURLY=${KEEP_HOURLY:-24}
|
||||||
|
KEEP_DAILY=${KEEP_DAILY:-7}
|
||||||
|
KEEP_WEEKLY=${KEEP_WEEKLY:-5}
|
||||||
|
KEEP_MONTHLY=${KEEP_MONTHLY:-12}
|
||||||
|
KEEP_YEARLY=${KEEP_YEARLY:-10}
|
||||||
|
|
||||||
function finish {
|
function finish {
|
||||||
if [ -z $KEEP_LOCK ]; then
|
if [ -z "$KEEP_LOCK" ]; then
|
||||||
rm -f "$LOCK"
|
rm -f "$LOCK"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@ -90,6 +96,25 @@ echo $$ > "$LOCK"
|
|||||||
|
|
||||||
LOCKED=$(($(date +%s) - START))
|
LOCKED=$(($(date +%s) - START))
|
||||||
|
|
||||||
|
printf "prune: started, keep hourly:%d daily:%d weekly:%d monthly:%d year:%d\n" \
|
||||||
|
"$KEEP_HOURLY" \
|
||||||
|
"$KEEP_DAILY" \
|
||||||
|
"$KEEP_WEEKLY" \
|
||||||
|
"$KEEP_MONTHLY" \
|
||||||
|
"$KEEP_YEARLY"
|
||||||
|
|
||||||
|
$RESTIC_PATH forget \
|
||||||
|
--quiet \
|
||||||
|
--host "$(hostname -f)" \
|
||||||
|
--keep-hourly "$KEEP_HOURLY" \
|
||||||
|
--keep-daily "$KEEP_DAILY" \
|
||||||
|
--keep-weekly "$KEEP_WEEKLY" \
|
||||||
|
--keep-monthly "$KEEP_MONTHLY" \
|
||||||
|
--keep-yearly "$KEEP_YEARLY" \
|
||||||
|
--prune
|
||||||
|
|
||||||
|
printf "prune: complete\n"
|
||||||
|
|
||||||
printf "job '%s' started\n" "$JOB"
|
printf "job '%s' started\n" "$JOB"
|
||||||
|
|
||||||
if [ -d "${HOOKS_PATH}" ]; then
|
if [ -d "${HOOKS_PATH}" ]; then
|
||||||
@ -127,7 +152,7 @@ until [ $counter -eq "$MAX_ATTEMPTS" ] || [ $rc -eq 0 ]; do
|
|||||||
done
|
done
|
||||||
printf "restic complete\n"
|
printf "restic complete\n"
|
||||||
|
|
||||||
if [ $rc -ne 0 ] && [ $counter -eq "$MAX_ATTEMPTS" ]; then
|
if [ $rc -ne 0 ] && [ "$counter" -eq "$MAX_ATTEMPTS" ]; then
|
||||||
printf "restic job timed out, exiting\n"
|
printf "restic job timed out, exiting\n"
|
||||||
else
|
else
|
||||||
printf "job '%s' complete\n" "$JOB"
|
printf "job '%s' complete\n" "$JOB"
|
||||||
|
@ -13,7 +13,7 @@ LOCK="${LOCK_PATH}/tidy.lock"
|
|||||||
KEEP_LOCK=
|
KEEP_LOCK=
|
||||||
|
|
||||||
function finish {
|
function finish {
|
||||||
if [ -z $KEEP_LOCK ]; then
|
if [ -z "$KEEP_LOCK" ]; then
|
||||||
rm -f "$LOCK"
|
rm -f "$LOCK"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@ -109,7 +109,7 @@ until [ $counter -eq "$MAX_ATTEMPTS" ] || [ $rc -eq 0 ]; do
|
|||||||
(( counter++ ))
|
(( counter++ ))
|
||||||
done
|
done
|
||||||
|
|
||||||
if [ $rc -ne 0 ] && [ $counter -eq "$MAX_ATTEMPTS" ]; then
|
if [ $rc -ne 0 ] && [ "$counter" -eq "$MAX_ATTEMPTS" ]; then
|
||||||
printf "tidy timed out, exiting\n"
|
printf "tidy timed out, exiting\n"
|
||||||
else
|
else
|
||||||
printf "complete\n"
|
printf "complete\n"
|
||||||
|
Loading…
Reference in New Issue
Block a user