updated borg state
This commit is contained in:
parent
015d25297f
commit
28e0ea4ab7
16
states/borg/config.sls
Normal file
16
states/borg/config.sls
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
---
|
||||||
|
{%- from "borg/map.jinja" import borg with context %}
|
||||||
|
{% for key, job in borg.jobs.items() %}
|
||||||
|
borg-config-script-{{ key }}:
|
||||||
|
file.managed:
|
||||||
|
- name: {{ borg.working_dir }}/scripts/borg_{{ key }}.sh
|
||||||
|
- source: salt://borg/templates/borg_job.sh.j2
|
||||||
|
- template: jinja
|
||||||
|
- user: root
|
||||||
|
- group: root
|
||||||
|
- mode: 0755
|
||||||
|
- context:
|
||||||
|
key: {{ key }}
|
||||||
|
job: {{ job }}
|
||||||
|
working_dir: {{ borg.working_dir }}
|
||||||
|
{% endfor %}
|
@ -2,5 +2,5 @@
|
|||||||
include:
|
include:
|
||||||
- .pkgs
|
- .pkgs
|
||||||
- .install
|
- .install
|
||||||
#- .config
|
- .config
|
||||||
#- .schedule
|
#- .schedule
|
||||||
|
@ -1,19 +1,20 @@
|
|||||||
#!/bin/sh
|
#!/bin/bash
|
||||||
export MOUNTPOINT="{{ job.mountpoint }}"
|
info() { printf "\n%s %s\n\n" "$( date )" "$*" >&2; }
|
||||||
|
trap 'echo $( date ) Backup interrupted >&2; exit 2' INT TERM
|
||||||
|
|
||||||
if [[ $(mountpoint -q $MOUNTPOINT) -eq 0 ]]
|
export MOUNTPOINT="{{ job.mountpoint|default('/mnt') }}"
|
||||||
|
|
||||||
|
if [[ $(mountpoint -q $MOUNTPOINT) -ne 0 ]]
|
||||||
then
|
then
|
||||||
|
info "Mountpoint not exists, exiting backup"
|
||||||
exit 2
|
exit 2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
backup_name="{{ job.name }}"
|
backup_name="{{ key }}"
|
||||||
|
|
||||||
export BORG_REPO=${MOUNTPOINT}/borg/${backup_name}
|
export BORG_REPO=${MOUNTPOINT}/borg/${backup_name}
|
||||||
export BORG_PASSPHRASE='{{ job.password }}'
|
export BORG_PASSPHRASE='{{ job.password }}'
|
||||||
|
|
||||||
info() { printf "\n%s %s\n\n" "$( date )" "$*" >&2; }
|
|
||||||
trap 'echo $( date ) Backup interrupted >&2; exit 2' INT TERM
|
|
||||||
|
|
||||||
info "Starting backup"
|
info "Starting backup"
|
||||||
|
|
||||||
info "Init repository backup"
|
info "Init repository backup"
|
||||||
@ -32,7 +33,7 @@ borg create \
|
|||||||
{% for include in job.included_dirs -%}
|
{% for include in job.included_dirs -%}
|
||||||
{{ include }} \
|
{{ include }} \
|
||||||
{% endfor -%}
|
{% endfor -%}
|
||||||
2>> /opt/borgbackup/logs/${backup_name}-$(date +%Y-%m-%d).log
|
2>> {{ working_dir }}/logs/${backup_name}-$(date +%Y-%m-%d).log
|
||||||
|
|
||||||
backup_exit=$?
|
backup_exit=$?
|
||||||
|
|
||||||
@ -51,13 +52,10 @@ global_exit=$(( backup_exit > prune_exit ? backup_exit : prune_exit ))
|
|||||||
|
|
||||||
if [ ${global_exit} -eq 0 ]; then
|
if [ ${global_exit} -eq 0 ]; then
|
||||||
info "Backup and Prune finished successfully"
|
info "Backup and Prune finished successfully"
|
||||||
#echo "Borg backup success for $backup_name job, proof file restore succeeded" | mutt -F {{ borgbackup_install_dir }}/.muttrc -s "BACKUP $backup_name SUCCESS" {{ job.value.notify_addr|default(borgbackup_mail_notify_addr) }}
|
|
||||||
elif [ ${global_exit} -eq 1 ]; then
|
elif [ ${global_exit} -eq 1 ]; then
|
||||||
info "Backup and/or Prune finished with warnings"
|
info "Backup and/or Prune finished with warnings"
|
||||||
#echo "Borg backup warning for $backup_name job, need for manual check of job for errors" | mutt -F {{ borgbackup_install_dir }}/.muttrc -s "BACKUP $backup_name WARNING" {{ job.value.notify_addr|default(borgbackup_mail_notify_addr) }}
|
|
||||||
else
|
else
|
||||||
info "Backup and/or Prune finished with errors"
|
info "Backup and/or Prune finished with errors"
|
||||||
#echo "Borg backup failed for $backup_name job, need for manual check of job for errors" | mutt -F {{ borgbackup_install_dir }}/.muttrc -s "BACKUP $backup_name FAILED" {{ job.value.notify_addr|default(borgbackup_mail_notify_addr) }}
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
exit ${global_exit}
|
exit ${global_exit}
|
||||||
|
Loading…
Reference in New Issue
Block a user