infrastructure/ansible/plays/templates/restore.sh.j2
Tobias Manske 75c04207b6
Some checks failed
continuous-integration/drone/push Build is failing
Backups: Move to backup host
2023-12-25 17:45:59 +01:00

53 lines
1.2 KiB
Django/Jinja
Executable File

#!/bin/sh
# Setting this, so the repo does not need to be given on the commandline:
# See the section "Passphrase notes" for more infos.
export BORG_PASSPHRASE='{{ password }}'
export BORG_REPO='{{ repo }}'
export BORG_RSH='ssh -i /root/.ssh/borgbackup'
{% if provision.from_backup.name is defined %}
RESTORE_FROM={{ provision.from_backup.name }}
{% else %}
RESTORE_FROM=$(borg list --short --sort-by timestamp --last 1 --glob-archives "{hostname}*")
{% endif %}
{% raw %}
# some helpers and error handling:
info() { printf "\n%s %s\n\n" "$( date )" "$*" >&2; }
trap 'echo $( date ) Backup interrupted >&2; exit 2' INT TERM
# Backup the most important directories into an archive named after
# the machine this script is currently running on:
# Starting restore
info "Starting Restore from backup"
cd /
borg extract \
--list \
"::${RESTORE_FROM}"
restore_exit=$?
# use highest exit code as global exit code
global_exit=$restore_exit
if [ ${global_exit} -eq 0 ]; then
info "Restore finished successfully"
elif [ ${global_exit} -eq 1 ]; then
info "Restore finished with warnings"
else
info "Restore finished with errors"
fi
exit ${global_exit}
{% endraw %}