initial commit
This commit is contained in:
commit
e4097afe2b
10 changed files with 408 additions and 0 deletions
78
templates/borg-backup.sh.j2
Normal file
78
templates/borg-backup.sh.j2
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
#!/bin/bash
|
||||
|
||||
if [ -z "$1" ] || [ ! -z "$2" ]
|
||||
then
|
||||
printf "Possible: info | init | list | backup | 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 b in backupservers %}
|
||||
REPOSITORY={{ b.user }}@{{ b.fqdn }}:{{ b.home }}{{ b.pool }}/{{ inventory_hostname }}
|
||||
/usr/local/bin/borg info $REPOSITORY::$2 {{ b.options }}
|
||||
{% 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 b in backupservers %}
|
||||
REPOSITORY={{ b.user }}@{{ b.fqdn }}:{{ b.home }}{{ b.pool }}/{{ inventory_hostname }}
|
||||
/usr/local/bin/borg mount $REPOSITORY::$3 $4 {{ b.options }}
|
||||
if [ "$?" = "0" ]; then printf "Backup mounted on $4, do not forget to unmount!\n"; fi
|
||||
exit 0
|
||||
{% endfor %}
|
||||
fi
|
||||
|
||||
if [ "$1" = "list" ]
|
||||
then
|
||||
{% for b in backupservers %}
|
||||
REPOSITORY={{ b.user }}@{{ b.fqdn }}:{{ b.home }}{{ b.pool }}/{{ inventory_hostname }}
|
||||
printf "Archives on {{ b.fqdn }} :\n"
|
||||
/usr/local/bin/borg list -v $REPOSITORY {{ b.options }}
|
||||
{% endfor %}
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ "$1" = "init" ]
|
||||
then
|
||||
{% for b in backupservers %}
|
||||
REPOSITORY={{ b.user }}@{{ b.fqdn }}:{{ b.home }}{{ b.pool }}/{{ inventory_hostname }}
|
||||
borg init $REPOSITORY {{ b.options }}
|
||||
{% endfor %}
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ "$1" = "backup" ]
|
||||
then
|
||||
date=`date +%Y%m%d-%H%M`
|
||||
|
||||
# Running some commands pre-backup
|
||||
{% for precommand in backup_pre_commands %}
|
||||
{{ precommand }}
|
||||
{% endfor %}
|
||||
|
||||
{% for b in backupservers %}
|
||||
printf "Backing up to {{ b.fqdn }} :\n"
|
||||
REPOSITORY={{ b.user }}@{{ b.fqdn }}:{{ b.home }}{{ b.pool }}/{{ inventory_hostname }}
|
||||
|
||||
/usr/local/bin/borg create --compression zlib,6 --stats $REPOSITORY::$date {{ b.options }} {% for dir in backup_include %}{{ dir }} {% endfor %}{% if automysql.stat.isdir is defined and automysql.stat.isdir == True %}/var/lib/automysqlbackup{% endif %}
|
||||
|
||||
if [ "$?" -eq "0" ]; then printf "Backup succeeded on $date\n" >> /var/log/borg-backup.log; fi
|
||||
|
||||
# Use the `prune` subcommand to maintain 7 daily, 4 weekly
|
||||
# and 6 monthly archives.
|
||||
/usr/local/bin/borg prune -v $REPOSITORY {{ b.options }} -H {{ retention.hourly }} -d {{ retention.daily }} -w {{ retention.weekly }} -m {{ retention.monthly }} -y {{ retention.yearly }}
|
||||
{% endfor %}
|
||||
fi
|
||||
|
||||
45
templates/borg-restore-from.sh.j2
Normal file
45
templates/borg-restore-from.sh.j2
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
#!/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
|
||||
8
templates/ssh.config.j2
Normal file
8
templates/ssh.config.j2
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
# backup hosts
|
||||
{% for b in backupservers %}
|
||||
Host {{ b.fqdn }}
|
||||
StrictHostKeyChecking no
|
||||
{% if b.port is defined %}
|
||||
Port {{ b.port }}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
Loading…
Add table
Add a link
Reference in a new issue