From 6787e98f08cf7c97fcddb4700d094b66690d9e13 Mon Sep 17 00:00:00 2001 From: Manu Date: Wed, 1 May 2019 10:39:07 +0800 Subject: [PATCH] Add option to check large repos only on Sunday. --- README.md | 1 + defaults/main.yml | 1 + tasks/main.yml | 28 +++++++++++++++++++++++++--- templates/config.yaml.j2 | 5 ++--- 4 files changed, 29 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 419ef23..0de3e2b 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ An Ansible Role that sets up automated remote backups on the target machine. Use - `borg_source_directories` (required): List of local folders to back up. - `borg_encryption_passphrase` (optional): Password to use for repokey or keyfile. Empty if repo is unencrypted. - `borgmatic_config_name` (optional): Name to use for the borgmatic config file. Defaults to `config.yml` +- `borgmatic_large_repo` (optional): Does repo-checking on a weekly basis instead of daily. Good for repos with 100GB+ size. - `borg_exclude_patterns` (optional): Paths or patterns to exclude from backup. See [official documentation](https://borgbackup.readthedocs.io/en/stable/usage/help.html#borg-help-patterns) for more. - `borg_one_file_system` (optional): Don't cross file-system boundaries. Defaults to `true` - `borg_exclude_from` (optional): Read exclude patterns from one or more separate named files, one pattern per line. diff --git a/defaults/main.yml b/defaults/main.yml index 2b73eb5..7457268 100755 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -2,6 +2,7 @@ borg_encryption_passphrase: '' borg_exclude_patterns: [] borgmatic_config_name: config.yaml +borgmatic_large_repo: false borg_one_file_system: true borg_exclude_from: [] borg_encryption_passcommand: false diff --git a/tasks/main.yml b/tasks/main.yml index a0ef783..001db36 100755 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -46,14 +46,36 @@ dest: "/etc/borgmatic/{{ borgmatic_config_name }}" mode: 0600 -- name: Add cron-job for borgmatic +- name: Add cron-job for borgmatic (large repo, create and prune) cron: - name: "borgmatic" - hour: "{{ 4 |random }}" + name: "borgmatic-create" + hour: "{{ 6 |random }}" + minute: "{{ 59 |random }}" + user: "root" + cron_file: borgmatic + job: "/usr/local/bin/borgmatic -c /etc/borgmatic/{{ borgmatic_config_name }} --create --prune" + when: borgmatic_large_repo + +- name: Add cron-job for borgmatic (large repo, check) + cron: + name: "borgmatic-check" + weekday: 0 + hour: "{{ range(7, 24) |random }}" + minute: "{{ 59 |random }}" + user: "root" + cron_file: borgmatic + job: "/usr/local/bin/borgmatic -c /etc/borgmatic/{{ borgmatic_config_name }} --check" + when: borgmatic_large_repo + +- name: Add cron-job for borgmatic (normal-sized repo) + cron: + name: "borgmatic-create" + hour: "{{ 6 |random }}" minute: "{{ 59 |random }}" user: "root" cron_file: borgmatic job: "/usr/local/bin/borgmatic -c /etc/borgmatic/{{ borgmatic_config_name }}" + when: not borgmatic_large_repo - name: Set PATH for borgmatic cron job. cron: diff --git a/templates/config.yaml.j2 b/templates/config.yaml.j2 index 623c2bf..1d5cb69 100644 --- a/templates/config.yaml.j2 +++ b/templates/config.yaml.j2 @@ -106,9 +106,8 @@ consistency: # "archive" checks all of the archives, and "extract" does an extraction dry-run # of just the most recent archive. checks: - - disabled - # - repository - # - archives + - repository + - archives # Restrict the number of checked archives to the last n. Applies only to the "archives" check. check_last: 3