From 59b6388b1335875c0b079165eb51437961861514 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 15 May 2020 00:48:10 -0400 Subject: [PATCH] restic --- restic/client.sls | 11 +++++++++++ restic/files/restic_backup.sh.jinja | 12 ++++++++++++ top.sls | 4 +++- 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 restic/files/restic_backup.sh.jinja diff --git a/restic/client.sls b/restic/client.sls index d030471..9bebf4b 100644 --- a/restic/client.sls +++ b/restic/client.sls @@ -5,3 +5,14 @@ - name: 'wget {{url}} -O - | bzip2 -cd > /bin/restic ; chmod +x /bin/restic' - unless: stat /bin/restic +/opt/restic_backups.sh: + file.managed: + - source: 'salt://restic/files/restic_backup.sh.jinja' + - template: jinja + - user: root + - group: root + - mode: 0700 + cron.present: + - minute: 20 + - hour: 4 + - dayweek: 0 diff --git a/restic/files/restic_backup.sh.jinja b/restic/files/restic_backup.sh.jinja new file mode 100644 index 0000000..597b2b0 --- /dev/null +++ b/restic/files/restic_backup.sh.jinja @@ -0,0 +1,12 @@ +#!/bin/sh +export HOME=/root +export RESTIC_PASSWORD={{ salt.pillar.get('restic:pass') }} +export RESTIC_REPOSITORY={{ salt.pillar.get('restic:repo') }} +restic backup --tag files {{ salt.pillar.get('restic:files') }} +{% if salt.pillar.get('restic:mysql', False) -%} +mysqldump --all-databases | restic backup --stdin --stdin-filename /all_databases.sql --tag mysql +{% endif -%} +restic forget --keep-last 4 --tag mysql --prune +{% if salt.pillar.get('restic:mysql', False) -%} +restic forget --keep-last 4 --tag files --prune +{% endif -%} diff --git a/top.sls b/top.sls index ae8abea..813004b 100644 --- a/top.sls +++ b/top.sls @@ -3,6 +3,9 @@ - common - users - salt.minion +{% if salt.pillar.get('restic', None) is not none %} + - restic.client +{% endif %} '*.keiran.us': - net 'vps47492.inmotionhosting.com': @@ -12,5 +15,4 @@ - icinga2 - nginx - restic.server - - restic.client - samba