From bf7df0a181e92d7c9ef3017ee3a96c88f0a4d8db Mon Sep 17 00:00:00 2001 From: Hunter Date: Fri, 19 Jul 2019 21:52:28 +0000 Subject: [PATCH] Update: added retention policy settings to config --- README.md | 6 ++++++ defaults/main.yml | 7 ++++++- templates/config.yaml.j2 | 31 +++++++++++++++++++++++++++---- 3 files changed, 39 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index cb2578a..08af3d7 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ An Ansible Role that sets up automated remote backups on the target machine. Use - `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. +- `borg_retention_policy`: Retention policy for how many backups to keep in each category (daily, weekly, monthly, etc). ## Example Playbook @@ -32,6 +33,11 @@ An Ansible Role that sets up automated remote backups on the target machine. Use - /var/lib/automysqlbackup borg_exclude_patterns: - /srv/www/old-sites + borg_retention_policy: + keep_hourly: 3 + keep_daily: 7 + keep_weekly: 4 + keep_monthly: 6 ``` ## Planned features diff --git a/defaults/main.yml b/defaults/main.yml index 1e1fbd0..7d01d05 100755 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -7,4 +7,9 @@ borgmatic_failure_command: echo "`date` - Error while creating a backup." borg_one_file_system: true borg_exclude_from: [] borg_encryption_passcommand: false -borg_ssh_command: false \ No newline at end of file +borg_ssh_command: false +borg_retention_policy: + keep_hourly: 3 + keep_daily: 7 + keep_weekly: 4 + keep_monthly: 6 diff --git a/templates/config.yaml.j2 b/templates/config.yaml.j2 index b753f38..8f8b6d4 100644 --- a/templates/config.yaml.j2 +++ b/templates/config.yaml.j2 @@ -79,17 +79,40 @@ storage: # https://borgbackup.readthedocs.org/en/stable/usage.html#borg-prune for details. # At least one of the "keep" options is required for pruning to work. retention: +{% if borg_retention_policy.keep_secondly is defined %} + # Number of secondly archives to keep. + keep_secondly: {{ borg_retention_policy.keep_secondly }} +{% endif %} + +{% if borg_retention_policy.keep_minutely is defined %} + # Number of minutely archives to keep. + keep_minutely: {{ borg_retention_policy.keep_minutely }} +{% endif %} + +{% if borg_retention_policy.keep_hourly is defined %} # Number of hourly archives to keep. - keep_hourly: 3 + keep_hourly: {{ borg_retention_policy.keep_hourly }} +{% endif %} +{% if borg_retention_policy.keep_daily is defined %} # Number of daily archives to keep. - keep_daily: 7 + keep_daily: {{ borg_retention_policy.keep_daily }} +{% endif %} +{% if borg_retention_policy.keep_weekly is defined %} # Number of weekly archives to keep. - keep_weekly: 4 + keep_weekly: {{ borg_retention_policy.keep_weekly }} +{% endif %} +{% if borg_retention_policy.keep_monthly is defined %} # Number of monthly archives to keep. - keep_monthly: 6 + keep_monthly: {{ borg_retention_policy.keep_monthly }} +{% endif %} + +{% if borg_retention_policy.keep_yearly is defined %} + # Number of yearly archives to keep. + keep_yearly: {{ borg_retention_policy.keep_yearly }} +{% endif %} # When pruning, only consider archive names starting with this prefix. # Borg placeholders can be used. See the output of "borg help placeholders" for