mirror of
https://github.com/roles-ansible/ansible_role_restic_archiver.git
synced 2024-08-16 10:09:49 +02:00
commit
5ed22205fb
7 changed files with 36 additions and 47 deletions
|
@ -8,8 +8,7 @@ galaxy_info:
|
||||||
min_ansible_version: 2.11
|
min_ansible_version: 2.11
|
||||||
platforms:
|
platforms:
|
||||||
- name: Debian
|
- name: Debian
|
||||||
versions:
|
versions: all
|
||||||
- buster
|
|
||||||
galaxy_tags:
|
galaxy_tags:
|
||||||
- backup
|
- backup
|
||||||
- archive
|
- archive
|
||||||
|
|
14
templates/includes/mail_report_header.sh.j2
Normal file
14
templates/includes/mail_report_header.sh.j2
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
# This file is also designed to create a overview
|
||||||
|
# over the restic backup and
|
||||||
|
# send it by mail - if wanted
|
||||||
|
found_error=false
|
||||||
|
cat <<EOT > /tmp/mailcontent
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Restic summary</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>SUMMARY for Restic BACKUP</h1>
|
||||||
|
{{ restic_archiver__additional_mail_msg | default ('') }}
|
||||||
|
EOT
|
6
templates/includes/mounting.sh.j2
Normal file
6
templates/includes/mounting.sh.j2
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
if mountpoint -q {{ restic_archiver__mount_disk }}
|
||||||
|
then
|
||||||
|
echo "{{ restic_archiver__mount_disk }} is mounted"
|
||||||
|
else
|
||||||
|
mount -a
|
||||||
|
fi
|
2
templates/includes/restic_cache.sh.j2
Normal file
2
templates/includes/restic_cache.sh.j2
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
# define cache directory
|
||||||
|
export XDG_CACHE_HOME={{ restic_archiver__cache_dir }}
|
2
templates/includes/set_send_mail_on_error_variable.sh.j2
Normal file
2
templates/includes/set_send_mail_on_error_variable.sh.j2
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
# Send a mail on error!
|
||||||
|
restic_archiver__send_mail_on_error=false
|
|
@ -1,38 +1,20 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
# {{ ansible_managed }}
|
# {{ ansible_managed }}
|
||||||
# This file is to cleanup your backup archive and move some snapshots to a external storage.
|
# This file is to cleanup your backup archive and move some snapshots to a external storage.
|
||||||
{% if restic_archiver__cache_config | bool %}
|
|
||||||
|
|
||||||
# define cache directory
|
{% if restic_archiver__cache_config | bool %}
|
||||||
export XDG_CACHE_HOME={{ restic_archiver__cache_dir }}
|
{% incluede 'includes/restic_cache.sh.j2' %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if restic_archiver__mail_on_error | bool %}
|
{% if restic_archiver__mail_on_error | bool %}
|
||||||
# Send a mail on error!
|
{% incluede 'includes/set_send_mail_on_error_variable.sh.j2' %}
|
||||||
restic_archiver__send_mail_on_error=false
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
|
||||||
{% if restic_archiver__mail_report | default(false) %}
|
{% if restic_archiver__mail_report | default(false) %}
|
||||||
# This file is also designed to create a overview
|
{% incluede 'includes/mail_report_header.sh.j2' %}
|
||||||
# over the restic backup and
|
|
||||||
# send it by mail - if wanted
|
|
||||||
found_error=false
|
|
||||||
cat <<EOT > /tmp/mailcontent
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>Restic summary</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<h1>SUMMARY for Restic BACKUP</h1>
|
|
||||||
{{ restic_archiver__additional_mail_msg | default ('') }}
|
|
||||||
EOT
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
|
||||||
{% for repo in restic_archiver__repos %}
|
{% for repo in restic_archiver__repos %}
|
||||||
|
|
||||||
{#
|
{#
|
||||||
define macro:
|
define macro:
|
||||||
how fast should we delete snapshots?
|
how fast should we delete snapshots?
|
||||||
|
@ -77,21 +59,14 @@ EOT
|
||||||
{%- endmacro %}
|
{%- endmacro %}
|
||||||
|
|
||||||
{#
|
{#
|
||||||
|
START DOING STUFF INSIDE THE RESTIC REPO FOR LOOP
|
||||||
START DUING STUFF INSIDE THE RESTIC REPO FOR LOOP
|
|
||||||
|
|
||||||
#}
|
#}
|
||||||
|
|
||||||
{ # try
|
{ # try
|
||||||
|
|
||||||
|
|
||||||
{% if restic_archiver__mount_required %}
|
{% if restic_archiver__mount_required %}
|
||||||
if mountpoint -q {{ restic_archiver__mount_disk }}
|
{% incluede 'includes/mounting.sh.j2' %}
|
||||||
then
|
|
||||||
echo "{{ restic_archiver__mount_disk }} is mounted"
|
|
||||||
else
|
|
||||||
mount -a
|
|
||||||
fi
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
# Settings for Server {{ repo['name'] | string }}
|
# Settings for Server {{ repo['name'] | string }}
|
||||||
|
@ -128,7 +103,7 @@ $(restic {{ restic_archiver__default_opt }} check --quiet 2>/dev/null)
|
||||||
<th>latest backup</th>
|
<th>latest backup</th>
|
||||||
<th>Path</th>
|
<th>Path</th>
|
||||||
</tr>
|
</tr>
|
||||||
$(restic --quiet snapshots --last --json | jq -c '.[]' | while read i; do echo -e "$i" | python3 -c "import sys, json; jsondata=json.load(sys.stdin); print('<tr>\n<td>', jsondata['hostname'], '</td>\n<td>', jsondata['time'], '</td>\n<td>', str(jsondata['paths'][0]), '</td>\n</tr>\n')" ; done)
|
$(restic --quiet snapshots --latest 1 --json | jq -c '.[]' | while read i; do echo -e "$i" | python3 -c "import sys, json; jsondata=json.load(sys.stdin); print('<tr>\n<td>', jsondata['hostname'], '</td>\n<td>', jsondata['time'], '</td>\n<td>', str(jsondata['paths'][0]), '</td>\n</tr>\n')" ; done)
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<table style="width:100%">
|
<table style="width:100%">
|
||||||
|
@ -154,11 +129,7 @@ BACKUP_NAME="{{ repo.name }}_archive"
|
||||||
|
|
||||||
echo "init $BACKUP_NAME"
|
echo "init $BACKUP_NAME"
|
||||||
{% if restic_archiver__mount_required %}
|
{% if restic_archiver__mount_required %}
|
||||||
if mountpoint -q {{ restic_archiver__mount_disk }}
|
{% incluede 'includes/mounting.sh.j2' %}
|
||||||
then
|
|
||||||
echo "{{ restic_archiver__mount_disk }} is mounted"
|
|
||||||
else
|
|
||||||
mount -a
|
|
||||||
fi
|
fi
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
@ -172,12 +143,7 @@ export RESTIC_PASSWORD2='{{ repo['archive_password'] | regex_replace('\'', '\'\\
|
||||||
export RESTIC_REPOSITORY="{{ repo['location'] }}"
|
export RESTIC_REPOSITORY="{{ repo['location'] }}"
|
||||||
export RESTIC_PASSWORD='{{ repo['password'] | regex_replace('\'', '\'\\\'\'') }}' 2>/dev/null
|
export RESTIC_PASSWORD='{{ repo['password'] | regex_replace('\'', '\'\\\'\'') }}' 2>/dev/null
|
||||||
{% if restic_archiver__mount_required %}
|
{% if restic_archiver__mount_required %}
|
||||||
if mountpoint -q {{ restic_archiver__mount_disk }}
|
{% incluede 'includes/mounting.sh.j2' %}
|
||||||
then
|
|
||||||
echo "{{ restic_archiver__mount_disk }} is mounted"
|
|
||||||
else
|
|
||||||
mount -a
|
|
||||||
fi
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
# transfer snapshots to archive
|
# transfer snapshots to archive
|
||||||
|
@ -241,7 +207,7 @@ mail -a "Content-type: text/html" -s "restic backup report" {{ restic_archiver__
|
||||||
|
|
||||||
{% if restic_archiver__mail_on_error | bool %}
|
{% if restic_archiver__mail_on_error | bool %}
|
||||||
if [ "$restic_archiver__send_mail_on_error" == true ]; then
|
if [ "$restic_archiver__send_mail_on_error" == true ]; then
|
||||||
mail -s "restic backup report" {{ restic_archiver__mailaddress }} <<< 'Something went wrong while running restic backup archiver at {{ ansible_hostname }}'
|
mail -s "[ERROR] restic backup report" {{ restic_archiver__mailaddress }} <<< 'Something went wrong while running restic backup archiver at {{ ansible_hostname }}'
|
||||||
fi
|
fi
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
---
|
---
|
||||||
playbook_version_number: 46 # should be int
|
playbook_version_number: 47 # should be int
|
||||||
playbook_version_path: 'role-restic_archiver_roles-ansible_github.com.version'
|
playbook_version_path: 'role-restic_archiver_roles-ansible_github.com.version'
|
||||||
|
|
Loading…
Reference in a new issue