Improve Borgmatic cron-job names.

This commit is contained in:
Manu 2019-05-15 12:44:10 +08:00
parent 6787e98f08
commit e30ce279c4
4 changed files with 44 additions and 37 deletions

View File

@ -4,16 +4,20 @@ An Ansible Role that sets up automated remote backups on the target machine. Use
## Role Variables ## Role Variables
- `borg_repository` (required): Full path to repository. Your own server or [BorgBase.com](https://www.borgbase.com) repo. ### Required Arguments
- `borg_source_directories` (required): List of local folders to back up. - `borg_repository`: Full path to repository. Your own server or [BorgBase.com](https://www.borgbase.com) repo.
- `borg_encryption_passphrase` (optional): Password to use for repokey or keyfile. Empty if repo is unencrypted. - `borg_source_directories`: List of local folders to back up.
- `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. ### Optional Arguments
- `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_encryption_passphrase`: Password to use for repokey or keyfile. Empty if repo is unencrypted.
- `borg_one_file_system` (optional): Don't cross file-system boundaries. Defaults to `true` - `borgmatic_config_name`: Name to use for the borgmatic config file. Defaults to `config.yml`
- `borg_exclude_from` (optional): Read exclude patterns from one or more separate named files, one pattern per line. - `borgmatic_large_repo`: Does repo-checking on a weekly basis instead of daily. Good for repos with 100GB+ size.
- `borg_ssh_command` (optional): Command to use instead of just "ssh". This can be used to specify ssh options. - `borgmatic_failure_command`: Run this command when an error occurs. E.g. `curl -s -F "token=xxx" -F "user=xxx" -F "message=Error during backup" https://api.pushover.net/1/messages.json`
- `borg_encryption_passcommand` (optional): The standard output of this command is used to unlock the encryption key. - `borg_exclude_patterns`: 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`: Don't cross file-system boundaries. Defaults to `true`
- `borg_exclude_from`: Read exclude patterns from one or more separate named files, one pattern per line.
- `borg_ssh_command`: Command to use instead of just "ssh". This can be used to specify ssh options.
- `borg_encryption_passcommand`: The standard output of this command is used to unlock the encryption key.
## Example Playbook ## Example Playbook

View File

@ -3,6 +3,7 @@ borg_encryption_passphrase: ''
borg_exclude_patterns: [] borg_exclude_patterns: []
borgmatic_config_name: config.yaml borgmatic_config_name: config.yaml
borgmatic_large_repo: false borgmatic_large_repo: false
borgmatic_failure_command: echo "`date` - Error while creating a backup."
borg_one_file_system: true borg_one_file_system: true
borg_exclude_from: [] borg_exclude_from: []
borg_encryption_passcommand: false borg_encryption_passcommand: false

View File

@ -46,20 +46,18 @@
dest: "/etc/borgmatic/{{ borgmatic_config_name }}" dest: "/etc/borgmatic/{{ borgmatic_config_name }}"
mode: 0600 mode: 0600
- name: Add cron-job for borgmatic (large repo, create and prune) - name: Add cron-job for borgmatic (large repo, create and check separate)
cron: block:
name: "borgmatic-create" - cron:
name: "borgmatic"
hour: "{{ 6 |random }}" hour: "{{ 6 |random }}"
minute: "{{ 59 |random }}" minute: "{{ 59 |random }}"
user: "root" user: "root"
cron_file: borgmatic cron_file: borgmatic
job: "/usr/local/bin/borgmatic -c /etc/borgmatic/{{ borgmatic_config_name }} --create --prune" job: "/usr/local/bin/borgmatic -c /etc/borgmatic/{{ borgmatic_config_name }} --create --prune"
when: borgmatic_large_repo - cron:
- name: Add cron-job for borgmatic (large repo, check)
cron:
name: "borgmatic-check" name: "borgmatic-check"
weekday: 0 day: "{{ 28 | random }}"
hour: "{{ range(7, 24) | random }}" hour: "{{ range(7, 24) | random }}"
minute: "{{ 59 | random }}" minute: "{{ 59 | random }}"
user: "root" user: "root"
@ -68,13 +66,17 @@
when: borgmatic_large_repo when: borgmatic_large_repo
- name: Add cron-job for borgmatic (normal-sized repo) - name: Add cron-job for borgmatic (normal-sized repo)
cron: block:
name: "borgmatic-create" - cron:
name: "borgmatic"
hour: "{{ 6 | random }}" hour: "{{ 6 | random }}"
minute: "{{ 59 | random }}" minute: "{{ 59 | random }}"
user: "root" user: "root"
cron_file: borgmatic cron_file: borgmatic
job: "/usr/local/bin/borgmatic -c /etc/borgmatic/{{ borgmatic_config_name }}" job: "/usr/local/bin/borgmatic -c /etc/borgmatic/{{ borgmatic_config_name }}"
- cron:
name: "borgmatic-check"
state: absent
when: not borgmatic_large_repo when: not borgmatic_large_repo
- name: Set PATH for borgmatic cron job. - name: Set PATH for borgmatic cron job.

View File

@ -132,4 +132,4 @@ hooks:
# List of one or more shell commands or scripts to execute in case an exception has occurred. # List of one or more shell commands or scripts to execute in case an exception has occurred.
on_error: on_error:
- echo "`date` - Error while creating a backup." - {{ borgmatic_failure_command }}