infrastructure/coreos-config/templates/restore.sh.j2

54 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='{{ backup.password }}'
export BORG_REPO=ssh://{{ backup.remote.user }}@{{ backup.remote.url }}
export BORG_RSH='ssh -i /root/.ssh/storagebox'
{% if provision.from_backup.name is defined %}
RESTORE_FROM={{ provision.from_backup.name }}
{% else %}
RESTORE_FROM=$(borg list --short --sort-by timestamp --last 1)
{% 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 \
--exclude "re:^/var/lib/docker/volumes/[a-z0-9]{64}/.*" \
"::${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 %}