add restic wrapper scripts

This commit is contained in:
2019-12-15 20:51:51 -06:00
parent 95b7f4115c
commit 4a7cd07ac9
10 changed files with 191 additions and 10 deletions

View File

@ -7,6 +7,14 @@
mode: 0755
state: directory
- name: create repo environment helper
template:
src: job-env.sh.j2
dest: "{{ restic_etc_path }}/jobs/{{ item.name }}/env.sh"
owner: root
group: root
mode: 0400
- name: create job exclude file
template:
src: exclude.txt.j2
@ -19,10 +27,10 @@
cron:
name: "restic {{ item.name }} job"
hour: "{{ item.cron.hour | default(omit) }}"
minute: "{{ item.cron.minute | default(omit) }}"
minute: "{{ item.cron.minute | default(60 | random(seed=inventory_hostname)) }}"
day: "{{ item.cron.day | default(omit) }}"
month: "{{ item.cron.month | default(omit) }}"
weekday: "{{ item.cron.weekday | default(omit) }}"
user: "{{ item.cron.user | default('root') }}"
state: "{{ item.cron.state | default('present') }}"
job: ". {{ restic_etc_path }}/repos/{{ item.repo }}/env.sh && restic backup -q --exclude-file {{ restic_etc_path }}/jobs/{{ item.name }}/exclude.txt {{ item.paths | join(' ') }}"
job: "{{ restic_bin_path }}/restic-job {{ item.name }}"

View File

@ -65,6 +65,22 @@
- "{{ restic_etc_path }}/repos"
- "{{ restic_etc_path }}/jobs"
- name: create restic job wrapper script
template:
src: restic-job.sh.j2
dest: "{{ restic_bin_path }}/restic-job"
owner: root
group: root
mode: 0755
- name: create restic tidy wrapper
template:
src: restic-tidy.sh.j2
dest: "{{ restic_bin_path }}/restic-tidy"
owner: root
group: root
mode: 0755
- name: manage repos
include: repo.yaml
loop: "{{ restic_repos | default([]) }}"

View File

@ -1,7 +1,7 @@
---
- name: get repo status
shell:
cmd: restic -q -r {{ item.repo }} snapshots 2> /dev/null
cmd: restic -q -r {{ item.repo }} --no-lock snapshots 2> /dev/null
ignore_errors: yes
environment: "{{ item.environment | default({}) }}"
register: restic_init
@ -30,8 +30,17 @@
- name: create repo environment helper
template:
src: env.sh.j2
src: repo-env.sh.j2
dest: "{{ restic_etc_path }}/repos/{{ item.name }}/env.sh"
owner: root
group: root
mode: 0400
- name: create cron
cron:
name: "restic {{ item.name }} tidy"
hour: "0"
minute: "{{ 60 | random(seed=inventory_hostname) }}"
user: root
state: present
job: "{{ restic_bin_path }}/restic-tidy {{ item.name }}"