mirror of
https://github.com/roles-ansible/ansible_role_restic_archiver.git
synced 2024-08-16 10:09:49 +02:00
improve template
This commit is contained in:
parent
8755a2cba2
commit
933e8c0bbb
4 changed files with 44 additions and 29 deletions
|
@ -7,6 +7,10 @@ restic_archiver__repos: {}
|
||||||
# - name: other_server
|
# - name: other_server
|
||||||
# location: /srv/restic/other_server_repo
|
# location: /srv/restic/other_server_repo
|
||||||
# password: xtrasecuredifferentpassword4other
|
# password: xtrasecuredifferentpassword4other
|
||||||
|
# archive: true
|
||||||
|
# archive_location: /mnt/archive/other_server_repo
|
||||||
|
# archive_password: archive4other_server_password
|
||||||
|
# archive_cleanup: true
|
||||||
# keep_last: 5
|
# keep_last: 5
|
||||||
# keep_hourly: 4
|
# keep_hourly: 4
|
||||||
# keep_daily: 1
|
# keep_daily: 1
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
group: "{{ restic_archiver__dir_owner }}"
|
group: "{{ restic_archiver__dir_owner }}"
|
||||||
owner: "{{ restic_archiver__dir_group }}"
|
owner: "{{ restic_archiver__dir_group }}"
|
||||||
mode: 0700
|
mode: 0700
|
||||||
no_log: true
|
# no_log: true
|
||||||
|
|
||||||
|
|
||||||
#- include_tasks: template.yml
|
#- include_tasks: template.yml
|
||||||
|
|
|
@ -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 %}
|
|
|
@ -44,16 +44,53 @@ set -euxo pipefail
|
||||||
{%- endif -%}
|
{%- endif -%}
|
||||||
{% if repo.keep_within is defined and repo.keep_within != None %} \
|
{% if repo.keep_within is defined and repo.keep_within != None %} \
|
||||||
--keep-within {{ repo.keep_within }} {% endif -%}
|
--keep-within {{ repo.keep_within }} {% endif -%}
|
||||||
|
{%- if repo.prune|default(false) %} \
|
||||||
|
--prune {% endif %}
|
||||||
{%- endmacro %}
|
{%- endmacro %}
|
||||||
|
|
||||||
|
|
||||||
# Settings for Server {{ repo['name'] | string }}
|
# Settings for Server {{ repo['name'] | string }}
|
||||||
export RESTIC_REPOSITORY="{{ repo['location'] }}"
|
export RESTIC_REPOSITORY="{{ repo['location'] }}"
|
||||||
export RESTIC_PASSWORD='''{{ repo['password'] | regex_replace('\'', '\'\\\'\'') }}'''
|
export RESTIC_PASSWORD='{{ repo['password'] | regex_replace('\'', '\'\\\'\'') }}'
|
||||||
BACKUP_NAME="{{ repo.name }}"
|
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 %}
|
{% endfor %}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue