Fixing restore-test

This commit is contained in:
Dieter Verhelst 2018-09-03 20:48:47 +02:00
parent 01bc64e95c
commit e1d9aae46e
8 changed files with 59 additions and 7 deletions

View File

@ -1 +1 @@
../restore/side_effect.yml
../generic_files/side_effect.yml

View File

@ -1 +1 @@
../restore/side_effect.yml
../generic_files/side_effect.yml

View File

@ -1 +1 @@
../restore/side_effect.yml
../generic_files/side_effect.yml

View File

@ -1 +0,0 @@
../restore/restore.sh.j2

View File

@ -0,0 +1,36 @@
#!/bin/sh
export BORG_PASSPHRASE="{{ borgbackup_passphrase }}"
last_backup=`/usr/local/bin/borg-backup list | grep '^[0-9]' | awk ' { print $1 } ' | tail -1`
if [ "$1" = "verify" ]
then
{% for b in borgbackup_servers %}
{% if b.type == 'hetzner' %}
REPOSITORY=ssh://{{ b.user }}@{{ b.fqdn }}:23/./{{ b.home }}{{ b.pool }}/{{ inventory_hostname }}
{% else %}
REPOSITORY={{ b.user }}@{{ b.fqdn }}:{{ b.home }}{{ b.pool }}/{{ inventory_hostname }}
{% endif %}
printf "verifying on {{ b.fqdn }} :\n"
/usr/local/bin/borg extract --list --dry-run $REPOSITORY::$last_backup root/sample.txt
{% endfor %}
exit 0
fi
if [ "$1" = "restore" ]
then
file="$2"
{% for b in borgbackup_servers %}
{% if b.type == 'hetzner' %}
REPOSITORY=ssh://{{ b.user }}@{{ b.fqdn }}:23/./{{ b.home }}{{ b.pool }}/{{ inventory_hostname }}
{% else %}
REPOSITORY={{ b.user }}@{{ b.fqdn }}:{{ b.home }}{{ b.pool }}/{{ inventory_hostname }}
{% endif %}
rm -rf /root/restore/{{ b.fqdn }}
mkdir -p /root/restore/{{ b.fqdn }}
cd /root/restore/{{ b.fqdn }}
/usr/local/bin/borg extract $REPOSITORY::$last_backup root/sample.txt
{% endfor %}
exit 0
fi

View File

@ -0,0 +1,17 @@
---
- hosts: all:!borgbackup_servers
gather_facts: false
tasks:
- name: generate random file
command: dd if=/dev/urandom of=/root/sample.txt bs=1M count=4
args:
creates: /root/sample.txt
- name: template restore test
template:
src: restore.sh.j2
dest: /root/restore.sh
mode: "0755"
- name: back up
command: /usr/local/bin/borg-backup backup
- name: restore test file
command: /root/restore.sh restore root/sample.txt

View File

@ -1 +1 @@
../restore/side_effect.yml
../generic_files/side_effect.yml

View File

@ -1 +1 @@
../restore/side_effect.yml
../generic_files/side_effect.yml

View File

@ -1 +1 @@
../restore/side_effect.yml
../generic_files/side_effect.yml