ansible-borgbackup/templates/borg-restore-from.sh.j2

46 lines
1.5 KiB
Django/Jinja

#!/bin/bash
if [ -z "$1" ] || [ ! -z "$2" ]
then
printf "Possible: info | list | mount \n\n"
fi
# Sourcing the backup-passphrase
. /root/.borg.passphrase
# Small helper commands, like listing backups, will help us in the future :)
if [ "$1" = "info" ]
then
if [ -z "$2" ]; then printf "run $0 with list and use the backup-tag to request information\n"; exit 1; fi
{% for host in groups.backupservers %}
REPOSITORY={{ borg_user }}@{{ restore_backup_server }}:{{ borg_pool }}/{{ restore_from_vm }}
/usr/local/bin/borg info $REPOSITORY::$2
{% endfor %}
exit 0
fi
if [ "$1" = "mount" ]
then
if [ -z "$2" ]; then printf "Select the backup-server\n"; exit 1; fi
if [ -z "$3" ]; then printf "Select the backup to mount\n"; exit 1; fi
if [ -z "$4" ]; then printf "Select the path to mount the backup on\n"; exit 1; fi
{% for host in groups.backupservers %}
REPOSITORY={{ borg_user }}@{{ restore_backup_server }}:{{ borg_pool }}/{{ restore_from_vm }}
/usr/local/bin/borg mount $REPOSITORY::$3 $4
if [ "$?" = "0" ]; then printf "Backup mounted on $4, do not forget to unmount!\n"; fi
exit 0
{% endfor %}
fi
if [ "$1" = "list" ]
then
{% for host in groups.backupservers %}
REPOSITORY={{ borg_user }}@{{ restore_backup_server }}:{{ borg_pool }}/{{ restore_from_vm }}
printf "{{ restore_from_vm }} archives to restore on {{ host }} ( {{ restore_backup_server }} ):\n"
/usr/local/bin/borg list -v $REPOSITORY
{% endfor %}
exit 0
fi