diff --git a/roles/restic/files/restic-job.sh b/roles/restic/files/restic-job.sh index f8058ac..0df8f6f 100755 --- a/roles/restic/files/restic-job.sh +++ b/roles/restic/files/restic-job.sh @@ -53,7 +53,11 @@ 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}" + if ! run-parts --exit-on-error -v -a pre "${HOOKS_PATH}"; then + printf "'%s' pre-hooks failed, running post-hooks and exiting\n" "$JOB" + run-parts --exit-on-error -v -a post "${HOOKS_PATH}" + exit 1 + fi fi counter=0 @@ -86,5 +90,5 @@ fi if [ -d "${HOOKS_PATH}" ]; then printf "running '%s' job post-hooks\n" "$JOB" - run-parts -v -a post "${HOOKS_PATH}" + run-parts --exit-on-error -v -a post "${HOOKS_PATH}" fi diff --git a/roles/restic/tasks/job.yaml b/roles/restic/tasks/job.yaml index cbb26c4..f60f464 100644 --- a/roles/restic/tasks/job.yaml +++ b/roles/restic/tasks/job.yaml @@ -7,18 +7,6 @@ mode: 0755 state: directory -- 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 @@ -27,7 +15,7 @@ group: root mode: 0400 -- name: install hooks +- name: create hooks directory file: path: "{{ restic_etc_path }}/jobs/{{ item.name }}/hooks.d" owner: root @@ -36,6 +24,19 @@ state: directory when: item.hooks is defined and item.hooks | length +- name: create job hooks + copy: + src: "hooks/{{ hook_item }}" + dest: "{{ restic_etc_path }}/jobs/{{ item.name }}/hooks.d/{{ '%02d' | format(idx) }}-{{ hook_item | basename | splitext | first }}" + owner: root + group: root + mode: 0755 + loop: "{{ item.hooks | default([]) }}" + loop_control: + loop_var: hook_item + index_var: idx + when: item.hooks is defined + - name: create job exclude file template: src: exclude.txt.j2