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 %} {%- from "borg/map.jinja" import borg with context %}
{% for key, job in borg.jobs.items() %} {% for name, params in borg.jobs.items() %}
borg-config-script-{{ key }}: borg-config-script-{{ name }}:
file.managed: 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 - source: salt://borg/templates/borg_job.sh.j2
- template: jinja - template: jinja
- user: root - user: root
- group: root - group: root
- mode: 0700 - mode: 0700
- context: - context:
key: {{ key }} name: {{ name }}
job: {{ job }} params: {{ params }}
working_dir: {{ borg.working_dir }} working_dir: {{ borg.working_dir }}
log_dir: {{ borg.log_dir }} log_dir: {{ borg.log_dir }}
{% endfor %} {% endfor %}

View File

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

View File

@ -3,10 +3,10 @@
info() { printf "\n%s %s\n\n" "$( date )" "$*" >&2; } info() { printf "\n%s %s\n\n" "$( date )" "$*" >&2; }
trap 'echo $( date ) Backup interrupted >&2; exit 2' INT TERM trap 'echo $( date ) Backup interrupted >&2; exit 2' INT TERM
backup_name="{{ key }}" backup_name="{{ name }}"
{% if job.mountpoint is defined -%} {% if params.mountpoint is defined -%}
export MOUNTPOINT="{{ job.mountpoint|default('/mnt') }}" export MOUNTPOINT="{{ params.mountpoint|default('/mnt') }}"
if [[ $(mountpoint -q $MOUNTPOINT) -ne 0 ]] if [[ $(mountpoint -q $MOUNTPOINT) -ne 0 ]]
then then
@ -16,11 +16,11 @@ fi
repo_path=${MOUNTPOINT}/borg repo_path=${MOUNTPOINT}/borg
{% else %} {% else %}
repo_path={{ job.sshrepo|default('localhost::tmp') }} repo_path={{ params.sshrepo|default('localhost::tmp') }}
{%- endif %} {%- endif %}
export BORG_REPO=$repo_path/${backup_name} export BORG_REPO=$repo_path/${backup_name}
export BORG_PASSPHRASE='{{ job.password }}' export BORG_PASSPHRASE='{{ params.password }}'
if [[ $1 == "list" ]] if [[ $1 == "list" ]]
then then
@ -31,10 +31,10 @@ fi
info "Starting backup" info "Starting backup"
info "Init repository 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" info "Starting before tasks"
{%- for task in job.before_tasks|default([]) %} {%- for task in params.before_tasks|default([]) %}
{{ task }} {{ task }}
if [ $? -ne 0 ]; then echo error; fi if [ $? -ne 0 ]; then echo error; fi
{%- endfor %} {%- endfor %}
@ -46,16 +46,16 @@ borg create \
--list \ --list \
--stats \ --stats \
--show-rc \ --show-rc \
--compression {{ job.compression|default('lz4') }} \ --compression {{ params.compression|default('lz4') }} \
--exclude-if-present '.nobackup' \ --exclude-if-present '.nobackup' \
{%- if job.excluded_dirs is defined -%} {%- if params.excluded_dirs is defined -%}
{%- for exclude in job.excluded_dirs %} {%- for exclude in params.excluded_dirs %}
--exclude '{{ exclude }}' \ --exclude '{{ exclude }}' \
{%- endfor %} {%- endfor %}
{%- endif %} {%- endif %}
--exclude-caches \ --exclude-caches \
::$backup_name'-{hostname}-{now}' \ ::$backup_name'-{hostname}-{now}' \
{%- for include in job.included_dirs %} {%- for include in params.included_dirs %}
{{ include }} \ {{ include }} \
{%- endfor %} {%- endfor %}
2>> {{ log_dir }}/${backup_name}-$(date +%Y-%m-%d).log 2>> {{ log_dir }}/${backup_name}-$(date +%Y-%m-%d).log
@ -67,15 +67,15 @@ borg prune \
--list \ --list \
-a $backup_name'-' \ -a $backup_name'-' \
--show-rc \ --show-rc \
--keep-daily {{ job.keep_daily|default(7) }} \ --keep-daily {{ params.keep_daily|default(7) }} \
--keep-weekly {{ job.keep_weekly|default(4) }} \ --keep-weekly {{ params.keep_weekly|default(4) }} \
--keep-monthly {{ job.keep_monthly|default(6) }} \ --keep-monthly {{ params.keep_monthly|default(6) }} \
info "Cleaning up logs" 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" info "Starting after tasks"
{%- for task in job.after_tasks|default([]) %} {%- for task in params.after_tasks|default([]) %}
{{ task }} {{ task }}
{%- endfor %} {%- endfor %}