diff --git a/README.md b/README.md index 14f785e..eb81acf 100644 --- a/README.md +++ b/README.md @@ -13,11 +13,16 @@ -## Description + Description +---------------- [Restic](https://github.com/restic/restic) is a versatile Go based backup solution which supports multiple backends, deduplication and incremental backups. +This role is **only intended to clean up a restick backup**. So for example to keep only backups of the last 7 days and monthly backups. And if necessary to copy the backups again to an external storage. + +---------------------- + This role installs restic on a client, configures the backup repositories and optionally sets up cronjobs to run said backups. Aditionally, it will setup executable scripts to run a Backup manually. diff --git a/tasks/distribution/Linux.yml b/tasks/distribution/Linux.yml index 167e5aa..fe49ca7 100644 --- a/tasks/distribution/Linux.yml +++ b/tasks/distribution/Linux.yml @@ -39,12 +39,13 @@ - name: Setup CRON jobs cron: - name: 'arillso.restic backup {{ item.name }}' + name: 'do1jlr.restic_archiver {{ item.name }}' job: 'CRON=true {{ restic_script_dir }}/backup-{{ item.name }}.sh' minute: '{{ item.schedule_minute | default("*") }}' hour: '{{ item.schedule_hour | default("*") }}' weekday: '{{ item.schedule_weekday | default("*") }}' month: '{{ item.schedule_month | default("*") }}' + cron_file: '/etc/crontab' state: present become: true no_log: true diff --git a/templates/restic_script_Linux.j2 b/templates/restic_script_Linux.j2 index c9da047..20dda88 100644 --- a/templates/restic_script_Linux.j2 +++ b/templates/restic_script_Linux.j2 @@ -1,30 +1,20 @@ #!/usr/bin/env bash # {{ ansible_managed }} # Backup script for {{ item.src|default('stdin') }} -# Use this file to create a Backup and prune existing data with one execution. +# This file is to cleanup your backup archive and move some snapshots to a external storage. + export RESTIC_REPOSITORY={{ restic_repos[item.repo].location }} export RESTIC_PASSWORD='{{ restic_repos[item.repo].password | regex_replace('\'', '\'\\\'\'') }}' BACKUP_NAME={{ item.name }} -{% 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 %} -{% if item.src is defined %} -BACKUP_SOURCE={{ item.src }} -{% endif %} + +{% if item.src is defined -%} + # BACKUP_SOURCE={{ item.src }} +{%- endif %} + set -euxo pipefail + + {# Define Tags #} @@ -37,6 +27,8 @@ set -euxo pipefail {% macro keep_tags(tags) -%} {% if tags is defined and (tags|length>0) %}{% for tag in tags %} --keep-tag {{ tag }}{% endfor %}{% endif %} {%- endmacro %} + + {# Define Hostname #} @@ -103,19 +95,19 @@ else MODE_TAG="--tag cron" fi {% if item.stdin is defined and item.stdin == true %} - #{{ item.stdin_cmd }} | {{ restic_install_path }}/restic backup \ - --stdin $MODE_TAG \ - {{ tags(item.tags) }} \ - {{ stdin_filename(item.stdin_filename) }} \ - {% if item.exclude is defined %}{{ exclude(item.exclude) }}{% endif %} \ - $@ +# {{ item.stdin_cmd }} | {{ restic_install_path }}/restic backup \ +# --stdin $MODE_TAG \ +# {{ tags(item.tags) }} \ +# {{ stdin_filename(item.stdin_filename) }} \ +# {% if item.exclude is defined %}{{ exclude(item.exclude) }}{% endif %} \ +# $@ {% else %} - #{{ restic_install_path }}/restic backup $BACKUP_SOURCE $MODE_TAG \ - {{ tags(item.tags) }} \ - {% if item.exclude is defined %}{{ exclude(item.exclude) }}{% endif %} \ - $@ +# {{ restic_install_path }}/restic backup $BACKUP_SOURCE $MODE_TAG \ +# {{ tags(item.tags) }} \ +# {% if item.exclude is defined %}{{ exclude(item.exclude) }}{% endif %} \ +# $@ {% endif %} {# Define stdin forget commands #} -{{ restic_install_path }}/restic forget --path {{ path(item) }} {{ retention_pattern(item) }} {% if item.prune is defined and item.prune == true %}--prune{% endif %} +{{ restic_install_path }}/restic forget {{ retention_pattern(item) }} {% if item.prune is defined and item.prune == true %}--prune{% endif %}