1
0
Fork 0
mirror of https://github.com/roles-ansible/ansible_role_restic.git synced 2024-12-11 23:41:32 +01:00

change: backups can be defined as dicts (#28)

* convert

* use loop

* clean

* combine

* change: reformat dict

* fix

* fix2

* update readme
This commit is contained in:
Matthias Leutenegger 2020-11-13 10:01:05 +01:00 committed by GitHub
parent 649f6aae0c
commit 790dae3ef4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 41 additions and 4 deletions

View file

@ -65,12 +65,12 @@ ansible-galaxy install arillso.restic
| Name | Default | Description | | Name | Default | Description |
| ---------------------- | -------------------- | --------------------------------------------------------------------------- | | ---------------------- | -------------------- | --------------------------------------------------------------------------- |
| `restic_url` | `undefined` | The URL to download restic from. Use this variable to overwrite the default | | `restic_url` | `undefined` | The URL to download restic from. Use this variable to overwrite the default |
| `restic_version` | `'0.11.0'` | The version of Restic to install | | `restic_version` | `'0.11.0'` | The version of Restic to install |
| `restic_download_path` | `'/opt/restic'` | Download location for the restic binary | | `restic_download_path` | `'/opt/restic'` | Download location for the restic binary |
| `restic_install_path` | `'/usr/local/bin'` | Install location for the restic binary | | `restic_install_path` | `'/usr/local/bin'` | Install location for the restic binary |
| `restic_script_dir` | `'~/restic'` | Location of the generated backup scripts | | `restic_script_dir` | `'~/restic'` | Location of the generated backup scripts |
| `restic_repos` | `{}` | A dictionary of repositories where snapshots are stored | | `restic_repos` | `{}` | A dictionary of repositories where snapshots are stored |
| `restic_backups` | `[]` | A list of dictionaries specifying the files and directories to be backed up | | `restic_backups` | `{}` (or `[]`) | A list of dictionaries specifying the files and directories to be backed up |
| `restic_create_cron` | `false` | Should a cronjob be created for each backup | | `restic_create_cron` | `false` | Should a cronjob be created for each backup |
| `restic_dir_owner` | `'{{ansible_user}}'` | The owner of all created dirs | | `restic_dir_owner` | `'{{ansible_user}}'` | The owner of all created dirs |
| `restic_dir_group` | `'{{ansible_user}}'` | The group of all created dirs | | `restic_dir_group` | `'{{ansible_user}}'` | The group of all created dirs |
@ -146,13 +146,18 @@ Available variables:
Example: Example:
```yaml ```yaml
restic_backups: restic_backups:
- name: data data:
name: data
repo: remove repo: remove
src: /path/to/data src: /path/to/data
scheduled: true scheduled: true
schedule_hour: 3 schedule_hour: 3
``` ```
> You can also specify restic_backups as an array, which is a legacy feature and
> might be deprecated in the future. currently, the name key is used for
> namint the access and backup files
#### Exclude #### Exclude
the `exclude` key on a backup allows you to specify multiple files to exclude or the `exclude` key on a backup allows you to specify multiple files to exclude or
files to look for filenames to be excluded. You can specify the following keys: files to look for filenames to be excluded. You can specify the following keys:

View file

@ -32,3 +32,28 @@
keep_daily: 7 keep_daily: 7
keep_monthly: 12 keep_monthly: 12
keep_yearly: 5 keep_yearly: 5
- name: Converge with dict
hosts: all
roles:
- role: ansible.restic
pre_tasks:
- name: install bzip2
package:
name: bzip2
state: present
vars:
restic_download_path: ~/restic
restic_install_path: ~/restic
restic_repos:
local:
location: /backup
password: securepassword1
init: true
restic_backups:
dicttest:
name: dicttest
src: /home
repo: local
keep_last: 4
keep_tag: deployment

View file

@ -22,5 +22,6 @@
args: args:
chdir: ~/restic/ chdir: ~/restic/
with_items: with_items:
- backup-dicttest.sh
- backup-test.sh - backup-test.sh
- backup-test_stdin.sh - backup-test_stdin.sh

View file

@ -1,6 +1,12 @@
--- ---
# tasks file for skeleton # tasks file for skeleton
- name: reformat dict if necessary
set_fact:
restic_backups: "{{ restic_backups|dict2items|json_query('[*].value') }}"
when:
- restic_backups | type_debug == "dict"
- name: Create backup credentials - name: Create backup credentials
template: template:
src: restic_access_Linux.j2 src: restic_access_Linux.j2
@ -42,8 +48,8 @@
state: present state: present
become: true become: true
no_log: true no_log: true
with_items: '{{ restic_backups }}'
when: when:
- restic_create_cron - restic_create_cron
- item.name is defined - item.name is defined
- item.scheduled | default(false) - item.scheduled | default(false)
with_items: '{{ restic_backups }}'