Compare commits

...

1 Commits

Author SHA1 Message Date
768aecc9a4
add restic wrapper scripts 2019-12-15 20:51:51 -06:00
6 changed files with 143 additions and 6 deletions

View File

@ -1,6 +0,0 @@
#!/bin/bash
export RESTIC_REPOSITORY="{{ item.repo }}"
{% for k, v in item.environment.items() %}
export {{ k | upper }}="{{ v }}"
{% endfor %}

View File

@ -1,3 +1,15 @@
# {{ ansible_managed }}
{% if restic_global_exclude is defined %}
# global exclusions
{% for exclude in restic_global_exclude | default([]) %}
{{ exclude }}
{% endfor %}
{% endif %}
{% if item.exclude is defined %}
# job exclusions
{% for exclude in item.exclude %}
{{ exclude }}
{% endfor %}
{%- endif -%}

View File

@ -0,0 +1,6 @@
#!/bin/bash
# {{ ansible_managed }}
REPO="{{ item.repo }}"
PATHS="{{ item.paths | join(' ') }}"

View File

@ -0,0 +1,16 @@
#!/bin/bash
# {{ ansible_managed }}
export RESTIC_REPOSITORY="{{ item.repo }}"
{% if "environment" in item %}
{% for k, v in item.environment.items() %}
export {{ k | upper }}="{{ v }}"
{% endfor %}
{% endif %}
{% if "forget" in item %}
{% for k, v in item.forget.items() %}
{{ k | upper }}="{{ v }}"
{% endfor %}
{% endif %}

View File

@ -0,0 +1,50 @@
#!/bin/bash
# {{ ansible_managed }}
error_exit() {
printf "%s\n" "$1"
exit 1
}
NICE="ionice -c2 nice -n19"
JOB=$1
if [ -z "$JOB" ]; then
error_exit "job is missing"
fi
RESTIC_ETC_PATH="{{ restic_etc_path }}"
JOB_PATH="${RESTIC_ETC_PATH}/jobs/${JOB}"
JOB_ENV="${JOB_PATH}/env.sh"
if [ ! -r "$JOB_ENV" ]; then
error_exit "${JOB_ENV} does not exist"
fi
. "$JOB_ENV"
if [ -z "${REPO+x}" ]; then
error_exit "\$REPO is not set"
fi
REPO_PATH="${RESTIC_ETC_PATH}/repos/${REPO}"
REPO_ENV="${REPO_PATH}/env.sh"
if [ ! -r "$REPO_ENV" ]; then
error_exit "${REPO_ENV} does not exist"
fi
. "$REPO_ENV"
EXCLUDE_PATH="${JOB_PATH}/exclude.txt"
if [ -z "${PATHS+x}" ]; then
error_exit "\$PATHS is not set"
fi
if [ -r "$EXCLUDE_PATH" ]; then
$NICE {{ restic_path }} backup -q --exclude-file="${EXCLUDE_PATH}" "${PATHS}"
else
$NICE {{ restic_path }} backup -q "${PATHS}"
fi

View File

@ -0,0 +1,59 @@
#!/bin/bash
# {{ ansible_managed }}
error_exit() {
printf "%s\n" "$1"
exit 1
}
MAX_ATTEMPTS=60
REPO=$1
if [ -z "$REPO" ]; then
error_exit "repo is missing"
fi
RESTIC_ETC_PATH="{{ restic_etc_path }}"
REPO_PATH="${RESTIC_ETC_PATH}/repos/${REPO}"
REPO_ENV="${REPO_PATH}/env.sh"
if [ ! -r "$REPO_ENV" ]; then
error_exit "${REPO_ENV} does not exist"
fi
. "$REPO_ENV"
KEEP_DAILY=${KEEP_DAILY:-7}
KEEP_WEEKLY=${KEEP_WEEKLY:-5}
KEEP_MONTHLY=${KEEP_MONTHLY:-12}
KEEP_YEARLY=${KEEP_YEARLY:-10}
counter=0
sleep=1
rc=1
until [ $counter -eq $MAX_ATTEMPTS ] || [ $rc -eq 0 ]; do
{{ restic_path }} forget \
--quiet \
--host $(hostname -f) \
--keep-daily "$KEEP_DAILY" \
--keep-weekly "$KEEP_WEEKLY" \
--keep-monthly "$KEEP_MONTHLY" \
--keep-yearly "$KEEP_YEARLY" \
--prune
rc=$?
if [ $rc -ne 0 ]; then
sleep=$((counter * 5))
printf "sleeping for %d seconds (%d)\n" $sleep $counter
sleep $sleep
fi
let counter+=1
done
if [ $rc -ne 0 ] && [ $counter -eq $MAX_ATTEMPTS ]; then
printf "tidy timed out, exiting\n"
fi