Add the ability to exclude certain paths from backup

This commit is contained in:
Jake Howard 2021-08-30 21:49:58 +01:00
parent 259b0ca7a6
commit 07b2ea2ccb
Signed by: jake
GPG key ID: 57AFB45680EDD477
3 changed files with 20 additions and 3 deletions

View file

@ -1,2 +1,3 @@
restic_backup_locations: [] restic_backup_locations: []
restic_backup_excludes: []
restic_forget: false restic_forget: false

View file

@ -17,7 +17,7 @@ mkdir -p "$RESTIC_LOG_DIR"
# Run backup, and capture logs to file # Run backup, and capture logs to file
cron_backup() { cron_backup() {
curl -fsS -m 10 --retry 5 -o /dev/null {{ healthchecks_host }}/{{ restic_healthchecks_id }}/start curl -fsS -m 10 --retry 5 -o /dev/null {{ healthchecks_host }}/{{ restic_healthchecks_id }}/start
restic --verbose backup {{ restic_backup_locations|join(' ') }} | tee -a $RESTIC_LOG_FILE restic --verbose backup --files-from=$HOME/restic-include.txt --exclude-file=$HOME/restic-excludes.txt | tee -a $RESTIC_LOG_FILE
exit_code=${PIPESTATUS[0]} exit_code=${PIPESTATUS[0]}
curl -fsS -m 10 --retry 5 -o /dev/null {{ healthchecks_host }}/{{ restic_healthchecks_id }}/$exit_code --data-binary "@$RESTIC_LOG_FILE" curl -fsS -m 10 --retry 5 -o /dev/null {{ healthchecks_host }}/{{ restic_healthchecks_id }}/$exit_code --data-binary "@$RESTIC_LOG_FILE"
echo "Exit code: $exit_code" echo "Exit code: $exit_code"
@ -25,7 +25,7 @@ cron_backup() {
# Run backup, but show all the progress # Run backup, but show all the progress
backup() { backup() {
restic --verbose backup {{ restic_backup_locations|join(' ') }} restic --verbose backup --files-from=$HOME/restic-include.txt --exclude-file=$HOME/restic-excludes.txt
} }
{% if restic_forget %} {% if restic_forget %}

View file

@ -10,7 +10,7 @@
system: false system: false
become: true become: true
- name: backrest - name: Install backrest
template: template:
src: files/backrest.sh src: files/backrest.sh
dest: /home/restic/backrest.sh dest: /home/restic/backrest.sh
@ -18,6 +18,22 @@
owner: restic owner: restic
become: true become: true
- name: Install includes files
copy:
content: "{{ restic_backup_locations | join('\n') }}"
dest: /home/restic/restic-include.txt
mode: "0644"
owner: restic
become: true
- name: Install excludes files
copy:
content: "{{ restic_backup_excludes | join('\n') }}"
dest: /home/restic/restic-excludes.txt
mode: "0644"
owner: restic
become: true
- name: Set restic binary permissions - name: Set restic binary permissions
file: file:
path: /usr/bin/restic path: /usr/bin/restic