From 933e8c0bbb58f0e5c2d5585dbf8fb4c6785db039 Mon Sep 17 00:00:00 2001 From: L3D Date: Thu, 10 Dec 2020 19:44:40 +0100 Subject: [PATCH] improve template --- defaults/main.yml | 4 +++ tasks/main.yml | 2 +- templates/restic_access_Linux.j2 | 26 ------------------ templates/restic_forget_snapshots.j2 | 41 ++++++++++++++++++++++++++-- 4 files changed, 44 insertions(+), 29 deletions(-) delete mode 100644 templates/restic_access_Linux.j2 diff --git a/defaults/main.yml b/defaults/main.yml index 7f4dc31..20db4e5 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -7,6 +7,10 @@ restic_archiver__repos: {} # - name: other_server # location: /srv/restic/other_server_repo # password: xtrasecuredifferentpassword4other +# archive: true +# archive_location: /mnt/archive/other_server_repo +# archive_password: archive4other_server_password +# archive_cleanup: true # keep_last: 5 # keep_hourly: 4 # keep_daily: 1 diff --git a/tasks/main.yml b/tasks/main.yml index c389350..941f4e0 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -9,7 +9,7 @@ group: "{{ restic_archiver__dir_owner }}" owner: "{{ restic_archiver__dir_group }}" mode: 0700 - no_log: true +# no_log: true #- include_tasks: template.yml diff --git a/templates/restic_access_Linux.j2 b/templates/restic_access_Linux.j2 deleted file mode 100644 index edcaf8e..0000000 --- a/templates/restic_access_Linux.j2 +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env bash -# {{ ansible_managed }} -# Backup credentials for {{ item.src|default('stdin') }} -# Source this file to work with restic on this host - -export RESTIC_REPOSITORY={{ restic_repos[item.repo].location }} -export RESTIC_PASSWORD='{{ restic_repos[item.repo].password | regex_replace('\'', '\'\\\'\'') }}' -{% if restic_repos[item.repo].aws_access_key is defined %} -export AWS_ACCESS_KEY_ID={{ restic_repos[item.repo].aws_access_key }} -{% endif %} -{% if restic_repos[item.repo].aws_secret_access_key is defined %} -export AWS_SECRET_ACCESS_KEY='{{ restic_repos[item.repo].aws_secret_access_key | regex_replace('\'', '\'\\\'\'') }}' -{% endif %} -{% if restic_repos[item.repo].aws_default_region is defined %} -export AWS_DEFAULT_REGION={{ restic_repos[item.repo].aws_default_region }} -{% endif %} -{% if restic_repos[item.repo].b2_account_id is defined %} -export B2_ACCOUNT_ID={{ restic_repos[item.repo].b2_account_id }} -{% endif %} -{% if restic_repos[item.repo].b2_account_key is defined %} -export B2_ACCOUNT_KEY={{ restic_repos[item.repo].b2_account_key }} -{% endif %} -BACKUP_NAME={{ item.name }} -{% if item.src is defined %} -BACKUP_SOURCE={{ item.src }} -{% endif %} diff --git a/templates/restic_forget_snapshots.j2 b/templates/restic_forget_snapshots.j2 index 1978390..a28e7d6 100644 --- a/templates/restic_forget_snapshots.j2 +++ b/templates/restic_forget_snapshots.j2 @@ -44,16 +44,53 @@ set -euxo pipefail {%- endif -%} {% if repo.keep_within is defined and repo.keep_within != None %} \ --keep-within {{ repo.keep_within }} {% endif -%} + {%- if repo.prune|default(false) %} \ + --prune {% endif %} {%- endmacro %} # Settings for Server {{ repo['name'] | string }} export RESTIC_REPOSITORY="{{ repo['location'] }}" -export RESTIC_PASSWORD='''{{ repo['password'] | regex_replace('\'', '\'\\\'\'') }}''' +export RESTIC_PASSWORD='{{ repo['password'] | regex_replace('\'', '\'\\\'\'') }}' BACKUP_NAME="{{ repo.name }}" +{{ restic_install_path }}/restic forget {{ retention_pattern(repo) }} -{{ restic_install_path }}/restic forget {{ retention_pattern(repo) }} {% if repo.prune is defined and repo.prune == true %}--prune{% endif %} + +{% if repo.archive|default(false) %} +# ARCHIVE Settings for Server "{{ repo['name'] | string }}" +export RESTIC_REPOSITORY="{{ repo['archive_location'] }}" +export RESTIC_PASSWORD='{{ repo['archive_password'] | regex_replace('\'', '\'\\\'\'') }}' +export RESTIC_REPOSITORY2="{{ repo['location'] }}" +export RESTIC_PASSWORD2='{{ repo['password'] | regex_replace('\'', '\'\\\'\'') }}' +BACKUP_NAME="{{ repo.name }}_archive" + +# init repo if it does not exist +if ([ -z "$(restic cat config)" ]) 2>/dev/null; then + restic init --copy-chunker-params +fi + +# ARCHIVE Settings for Server "{{ repo['name'] | string }}" +export RESTIC_REPOSITORY2="{{ repo['archive_location'] }}" +export RESTIC_PASSWORD2='{{ repo['archive_password'] | regex_replace('\'', '\'\\\'\'') }}' +export RESTIC_REPOSITORY="{{ repo['location'] }}" +export RESTIC_PASSWORD='{{ repo['password'] | regex_replace('\'', '\'\\\'\'') }}' + +# transfer snapshots to archive +restic copy + +{% if repo.archive_cleanup | default(false) %} + + + +{{ restic_install_path }}/restic copy --copy-chunker-params + +{% endif %} + + +{% endif %} {% endfor %} + +