add pre/post hooks to restic scripts

This commit is contained in:
Ryan Cavicchioni 2019-12-23 11:30:07 -06:00
parent 55ba448f13
commit d86b692e4f
Signed by: ryanc
GPG Key ID: 877EEDAF9245103D
2 changed files with 32 additions and 1 deletions

View File

@ -20,6 +20,7 @@ fi
JOB_PATH="${RESTIC_ETC_PATH}/jobs/${JOB}"
JOB_ENV="${JOB_PATH}/env.sh"
HOOKS_PATH="${JOB_PATH}/hooks.d"
if [ ! -r "$JOB_ENV" ]; then
error_exit "${JOB_ENV} does not exist"
@ -50,6 +51,11 @@ fi
printf "job '%s' started\n" "$JOB"
if [ -d "${HOOKS_PATH}" ]; then
printf "running '%s' job pre-hooks\n" "$JOB"
run-parts -v -a pre "${HOOKS_PATH}"
fi
counter=0
sleep=1
rc=1
@ -77,4 +83,8 @@ if [ $rc -ne 0 ] && [ $counter -eq "$MAX_ATTEMPTS" ]; then
else
printf "job '%s' complete\n" "$JOB"
fi
if [ -d "${HOOKS_PATH}" ]; then
printf "running '%s' job post-hooks\n" "$JOB"
run-parts -v -a post "${HOOKS_PATH}"
fi

View File

@ -7,7 +7,19 @@
mode: 0755
state: directory
- name: create repo environment helper
- name: create job hooks
copy:
src: "hooks/{{ hook_item }}"
dest: "{{ restic_etc_path }}/jobs/{{ item.name }}/hooks.d/{{ hook_item | basename | splitext | first }}"
owner: root
group: root
mode: 0755
loop: "{{ item.hooks | default([]) }}"
loop_control:
loop_var: hook_item
when: item.hooks is defined
- name: create job environment helper
template:
src: job-env.sh.j2
dest: "{{ restic_etc_path }}/jobs/{{ item.name }}/env.sh"
@ -15,6 +27,15 @@
group: root
mode: 0400
- name: install hooks
file:
path: "{{ restic_etc_path }}/jobs/{{ item.name }}/hooks.d"
owner: root
group: root
mode: 0755
state: directory
when: item.hooks is defined and item.hooks | length
- name: create job exclude file
template:
src: exclude.txt.j2