diff --git a/states/borg/config.sls b/states/borg/config.sls index 1913c8b..3e9ce93 100644 --- a/states/borg/config.sls +++ b/states/borg/config.sls @@ -1,17 +1,17 @@ --- {%- from "borg/map.jinja" import borg with context %} -{% for key, job in borg.jobs.items() %} -borg-config-script-{{ key }}: +{% for name, params in borg.jobs.items() %} +borg-config-script-{{ name }}: file.managed: - - name: {{ borg.working_dir }}/scripts/borg_{{ key }}.sh + - name: {{ borg.working_dir }}/scripts/borg_{{ name }}.sh - source: salt://borg/templates/borg_job.sh.j2 - template: jinja - user: root - group: root - mode: 0700 - context: - key: {{ key }} - job: {{ job }} + name: {{ name }} + params: {{ params }} working_dir: {{ borg.working_dir }} log_dir: {{ borg.log_dir }} {% endfor %} diff --git a/states/borg/defaults.yaml b/states/borg/defaults.yaml index 69b2cd1..ce6c326 100644 --- a/states/borg/defaults.yaml +++ b/states/borg/defaults.yaml @@ -8,5 +8,5 @@ borg: - scripts pip_pkgs: - borgbackup - - llfuse + # - llfuse jobs: {} diff --git a/states/borg/templates/borg_job.sh.j2 b/states/borg/templates/borg_job.sh.j2 index c762daa..73ddf41 100644 --- a/states/borg/templates/borg_job.sh.j2 +++ b/states/borg/templates/borg_job.sh.j2 @@ -3,10 +3,10 @@ info() { printf "\n%s %s\n\n" "$( date )" "$*" >&2; } trap 'echo $( date ) Backup interrupted >&2; exit 2' INT TERM -backup_name="{{ key }}" +backup_name="{{ name }}" -{% if job.mountpoint is defined -%} -export MOUNTPOINT="{{ job.mountpoint|default('/mnt') }}" +{% if params.mountpoint is defined -%} +export MOUNTPOINT="{{ params.mountpoint|default('/mnt') }}" if [[ $(mountpoint -q $MOUNTPOINT) -ne 0 ]] then @@ -16,11 +16,11 @@ fi repo_path=${MOUNTPOINT}/borg {% else %} -repo_path={{ job.sshrepo|default('localhost::tmp') }} +repo_path={{ params.sshrepo|default('localhost::tmp') }} {%- endif %} export BORG_REPO=$repo_path/${backup_name} -export BORG_PASSPHRASE='{{ job.password }}' +export BORG_PASSPHRASE='{{ params.password }}' if [[ $1 == "list" ]] then @@ -31,10 +31,10 @@ fi info "Starting backup" info "Init repository backup" -borg init --encryption={{ job.encryption|default('repokey-blake2') }} +borg init --encryption={{ params.encryption|default('repokey-blake2') }} info "Starting before tasks" -{%- for task in job.before_tasks|default([]) %} +{%- for task in params.before_tasks|default([]) %} {{ task }} if [ $? -ne 0 ]; then echo error; fi {%- endfor %} @@ -46,16 +46,16 @@ borg create \ --list \ --stats \ --show-rc \ - --compression {{ job.compression|default('lz4') }} \ + --compression {{ params.compression|default('lz4') }} \ --exclude-if-present '.nobackup' \ -{%- if job.excluded_dirs is defined -%} -{%- for exclude in job.excluded_dirs %} +{%- if params.excluded_dirs is defined -%} +{%- for exclude in params.excluded_dirs %} --exclude '{{ exclude }}' \ {%- endfor %} {%- endif %} --exclude-caches \ ::$backup_name'-{hostname}-{now}' \ -{%- for include in job.included_dirs %} +{%- for include in params.included_dirs %} {{ include }} \ {%- endfor %} 2>> {{ log_dir }}/${backup_name}-$(date +%Y-%m-%d).log @@ -67,15 +67,15 @@ borg prune \ --list \ -a $backup_name'-' \ --show-rc \ - --keep-daily {{ job.keep_daily|default(7) }} \ - --keep-weekly {{ job.keep_weekly|default(4) }} \ - --keep-monthly {{ job.keep_monthly|default(6) }} \ + --keep-daily {{ params.keep_daily|default(7) }} \ + --keep-weekly {{ params.keep_weekly|default(4) }} \ + --keep-monthly {{ params.keep_monthly|default(6) }} \ info "Cleaning up logs" -find {{ log_dir }}/${backup_name}-*.log -mtime +{{ job.keep_logs_days|default(7) }} -delete +find {{ log_dir }}/${backup_name}-*.log -mtime +{{ params.keep_logs_days|default(7) }} -delete info "Starting after tasks" -{%- for task in job.after_tasks|default([]) %} +{%- for task in params.after_tasks|default([]) %} {{ task }} {%- endfor %}