updated borg state

This commit is contained in:
Paul 2023-12-04 22:34:29 +01:00
parent 74584c5a2b
commit 43909659d5
3 changed files with 22 additions and 22 deletions

View File

@ -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 %}

View File

@ -8,5 +8,5 @@ borg:
- scripts
pip_pkgs:
- borgbackup
- llfuse
# - llfuse
jobs: {}

View File

@ -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 %}