From d8922619929e0c8ea67b20c53408b706838a74b1 Mon Sep 17 00:00:00 2001 From: Paul Lecuq Date: Sat, 15 May 2021 13:05:18 +0200 Subject: [PATCH] updated borg state --- states/borg/defaults.yaml | 4 ++++ states/borg/init.sls | 1 + states/borg/install.sls | 2 +- states/borg/templates/borg_job.sh.j2 | 11 +++++++++-- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/states/borg/defaults.yaml b/states/borg/defaults.yaml index 4c6c689..e121343 100644 --- a/states/borg/defaults.yaml +++ b/states/borg/defaults.yaml @@ -3,6 +3,10 @@ borg: enabled: true run_user: dkron working_dir: /opt/borg + default_dirs: + - bin + - logs + - scripts pip_pkgs: - borgbackup - llfuse diff --git a/states/borg/init.sls b/states/borg/init.sls index dfdbe60..030b82d 100644 --- a/states/borg/init.sls +++ b/states/borg/init.sls @@ -1,5 +1,6 @@ --- include: + - dkron - .pkgs - .install - .config diff --git a/states/borg/install.sls b/states/borg/install.sls index ba61090..e54be34 100644 --- a/states/borg/install.sls +++ b/states/borg/install.sls @@ -5,7 +5,7 @@ borg-working-dir: - name: {{ borg.working_dir }} - mode: 0700 -{% for dir in ['bin', 'logs', 'scripts'] %} +{% for dir in borg.default_dirs %} borg-working-dir-{{ dir }}: file.directory: - name: {{ borg.working_dir }}/{{ dir }} diff --git a/states/borg/templates/borg_job.sh.j2 b/states/borg/templates/borg_job.sh.j2 index ea3e0a9..9ef5fa3 100755 --- a/states/borg/templates/borg_job.sh.j2 +++ b/states/borg/templates/borg_job.sh.j2 @@ -1,7 +1,11 @@ #!/bin/bash + info() { printf "\n%s %s\n\n" "$( date )" "$*" >&2; } trap 'echo $( date ) Backup interrupted >&2; exit 2' INT TERM +backup_name="{{ key }}" + +{% if job.mountpoint is defined -%} export MOUNTPOINT="{{ job.mountpoint|default('/mnt') }}" if [[ $(mountpoint -q $MOUNTPOINT) -ne 0 ]] @@ -10,9 +14,12 @@ then exit 2 fi -backup_name="{{ key }}" +repo_path=${MOUNTPOINT}/borg +{% else %} +repo_path={{ job.sshrepo|default('localhost::tmp') }} +{%- endif %} -export BORG_REPO=${MOUNTPOINT}/borg/${backup_name} +export BORG_REPO=$repo_path/${backup_name} export BORG_PASSPHRASE='{{ job.password }}' info "Starting backup"