add pre/post hooks to restic scripts
This commit is contained in:
parent
55ba448f13
commit
d86b692e4f
@ -20,6 +20,7 @@ fi
|
|||||||
|
|
||||||
JOB_PATH="${RESTIC_ETC_PATH}/jobs/${JOB}"
|
JOB_PATH="${RESTIC_ETC_PATH}/jobs/${JOB}"
|
||||||
JOB_ENV="${JOB_PATH}/env.sh"
|
JOB_ENV="${JOB_PATH}/env.sh"
|
||||||
|
HOOKS_PATH="${JOB_PATH}/hooks.d"
|
||||||
|
|
||||||
if [ ! -r "$JOB_ENV" ]; then
|
if [ ! -r "$JOB_ENV" ]; then
|
||||||
error_exit "${JOB_ENV} does not exist"
|
error_exit "${JOB_ENV} does not exist"
|
||||||
@ -50,6 +51,11 @@ fi
|
|||||||
|
|
||||||
printf "job '%s' started\n" "$JOB"
|
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
|
counter=0
|
||||||
sleep=1
|
sleep=1
|
||||||
rc=1
|
rc=1
|
||||||
@ -77,4 +83,8 @@ if [ $rc -ne 0 ] && [ $counter -eq "$MAX_ATTEMPTS" ]; then
|
|||||||
else
|
else
|
||||||
printf "job '%s' complete\n" "$JOB"
|
printf "job '%s' complete\n" "$JOB"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ -d "${HOOKS_PATH}" ]; then
|
||||||
|
printf "running '%s' job post-hooks\n" "$JOB"
|
||||||
|
run-parts -v -a post "${HOOKS_PATH}"
|
||||||
fi
|
fi
|
||||||
|
@ -7,7 +7,19 @@
|
|||||||
mode: 0755
|
mode: 0755
|
||||||
state: directory
|
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:
|
template:
|
||||||
src: job-env.sh.j2
|
src: job-env.sh.j2
|
||||||
dest: "{{ restic_etc_path }}/jobs/{{ item.name }}/env.sh"
|
dest: "{{ restic_etc_path }}/jobs/{{ item.name }}/env.sh"
|
||||||
@ -15,6 +27,15 @@
|
|||||||
group: root
|
group: root
|
||||||
mode: 0400
|
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
|
- name: create job exclude file
|
||||||
template:
|
template:
|
||||||
src: exclude.txt.j2
|
src: exclude.txt.j2
|
||||||
|
Loading…
Reference in New Issue
Block a user