diff options
Diffstat (limited to 'templates')
| -rw-r--r-- | templates/borg_backup.service.j2 | 5 | ||||
| -rw-r--r-- | templates/borg_backup_script.j2 | 15 | ||||
| -rw-r--r-- | templates/borg_prune.service.j2 | 17 | ||||
| -rw-r--r-- | templates/borg_prune.timer.j2 | 11 | ||||
| -rw-r--r-- | templates/borg_prune_script.j2 | 71 |
5 files changed, 118 insertions, 1 deletions
diff --git a/templates/borg_backup.service.j2 b/templates/borg_backup.service.j2 index 04f2a49..c4901c3 100644 --- a/templates/borg_backup.service.j2 +++ b/templates/borg_backup.service.j2 @@ -1,10 +1,13 @@ [Unit] Description=Runs borgbackup to create application level backup (ANSIBLE MANAGED) Wants={{ borg_backup_timer_name }}{{ "@" if borg_backup_argument != "" }}{{ borg_backup_argument }}.timer +{% if borg_prune_enabled and borg_prune_trigger == 'after_backup' %} +OnSuccess={{ borg_prune_service_name }}{{ "@" if borg_backup_argument != "" }}{{ borg_backup_argument }}.service +{% endif %} [Service] Type=oneshot -ExecStart={{ borg_backup_script_location }} +ExecStart={{ borg_backup_script_location }}{{ "@" if borg_backup_argument != "" else "" }}{{ borg_backup_argument }} User={{ borg_client_user }} Group={{ borg_client_user }} {% if borg_backup_service_successful_exit_status | length > 0 %} diff --git a/templates/borg_backup_script.j2 b/templates/borg_backup_script.j2 new file mode 100644 index 0000000..0ef22ff --- /dev/null +++ b/templates/borg_backup_script.j2 @@ -0,0 +1,15 @@ +#!/bin/bash +export BORG_PASSPHRASE={{ borg_passphrase | quote }} +{% if borg_ssh_key_per_repo %} +export BORG_RSH="ssh -i {{ borg_ssh_key_path }}" +{% endif %} +borg create \ + -C {{ borg_compression }} \ +{% for excluded_dir in borg_excluded_dirs %} + --exclude {{ excluded_dir | quote }} \ +{% endfor %} +{% if borg_create_additional_arguments %} + {{ borg_create_additional_arguments }} \ +{% endif %} + {{ borg_server_user }}@{{ borg_server_host_url }}:{{ borg_server_user_home }}/{{ borg_repo_name }}::{{ borg_backup_name_format }} \ + {{ borg_included_dirs | map('quote') | join(' ') }} diff --git a/templates/borg_prune.service.j2 b/templates/borg_prune.service.j2 new file mode 100644 index 0000000..ce8e528 --- /dev/null +++ b/templates/borg_prune.service.j2 @@ -0,0 +1,17 @@ +[Unit] +Description=Runs borgbackup prune/compact retention job (ANSIBLE MANAGED) +{% if borg_prune_trigger == 'timer' %} +Wants={{ borg_prune_timer_name }}{{ "@" if borg_backup_argument != "" }}{{ borg_backup_argument }}.timer +{% endif %} + +[Service] +Type=oneshot +ExecStart={{ borg_prune_script_location }}{{ "@" if borg_backup_argument != "" else "" }}{{ borg_backup_argument }} +User={{ borg_client_user }} +Group={{ borg_client_user }} +{% if borg_prune_service_successful_exit_status | length > 0 %} +SuccessExitStatus={{ borg_prune_service_successful_exit_status | join(' ') }} +{% endif %} + +[Install] +WantedBy=multi-user.target diff --git a/templates/borg_prune.timer.j2 b/templates/borg_prune.timer.j2 new file mode 100644 index 0000000..caf3406 --- /dev/null +++ b/templates/borg_prune.timer.j2 @@ -0,0 +1,11 @@ +[Unit] +Description=Runs borgbackup prune/compact retention job (ANSIBLE MANAGED) +Requires={{ borg_prune_service_name }}{{ "@" if borg_backup_argument != "" }}{{ borg_backup_argument }}.service + +[Timer] +Unit={{ borg_prune_service_name }}{{ "@" if borg_backup_argument != "" }}{{ borg_backup_argument }}.service +OnCalendar={{ borg_prune_systemd_oncalendar }} +AccuracySec={{ borg_prune_systemd_accuracysec }} + +[Install] +WantedBy=timers.target diff --git a/templates/borg_prune_script.j2 b/templates/borg_prune_script.j2 new file mode 100644 index 0000000..bc1f5b9 --- /dev/null +++ b/templates/borg_prune_script.j2 @@ -0,0 +1,71 @@ +#!/bin/bash +export BORG_PASSPHRASE={{ borg_passphrase | quote }} +{% if borg_ssh_key_per_repo %} +export BORG_RSH="ssh -i {{ borg_ssh_key_path }}" +{% endif %} + +borg prune \ + {% if borg_prune_force %} +--force \ + {% endif %} +{% if borg_prune_stats %} +--stats \ + {% endif %} +{% if borg_prune_list %} +--list \ + {% endif %} +{% if borg_prune_save_space %} +--save-space \ + {% endif %} +--checkpoint-interval {{ borg_prune_checkpoint_interval }} \ + --glob-archives {{ borg_prune_glob_archives | quote }} \ + {% if borg_prune_keep_within %} +--keep-within {{ borg_prune_keep_within | quote }} \ + {% endif %} +{% if borg_prune_keep_last %} +--keep-last {{ borg_prune_keep_last | quote }} \ + {% endif %} +{% if borg_prune_keep_minutely %} +--keep-minutely {{ borg_prune_keep_minutely | quote }} \ + {% endif %} +{% if borg_prune_keep_hourly %} +--keep-hourly {{ borg_prune_keep_hourly | quote }} \ + {% endif %} +{% if borg_prune_keep_daily %} +--keep-daily {{ borg_prune_keep_daily | quote }} \ + {% endif %} +{% if borg_prune_keep_weekly %} +--keep-weekly {{ borg_prune_keep_weekly | quote }} \ + {% endif %} +{% if borg_prune_keep_monthly %} +--keep-monthly {{ borg_prune_keep_monthly | quote }} \ + {% endif %} +{% if borg_prune_keep_13weekly %} +--keep-13weekly {{ borg_prune_keep_13weekly | quote }} \ + {% endif %} +{% if borg_prune_keep_3monthly %} +--keep-3monthly {{ borg_prune_keep_3monthly | quote }} \ + {% endif %} +{% if borg_prune_keep_yearly %} +--keep-yearly {{ borg_prune_keep_yearly | quote }} \ + {% endif %} +{% if borg_prune_additional_arguments %} +{{ borg_prune_additional_arguments }} \ + {% endif %} +{{ borg_server_user }}@{{ borg_server_host_url }}:{{ borg_server_user_home }}/{{ borg_repo_name }} +borg_prune_exit=$? +if [ "${borg_prune_exit}" -ne 0 ]; then + exit "${borg_prune_exit}" +fi +{% if borg_prune_compact_enabled %} + +borg compact \ + {% if borg_compact_cleanup_commits %} +--cleanup-commits \ + {% endif %} +--threshold {{ borg_compact_threshold }} \ + {% if borg_compact_additional_arguments %} +{{ borg_compact_additional_arguments }} \ + {% endif %} +{{ borg_server_user }}@{{ borg_server_host_url }}:{{ borg_server_user_home }}/{{ borg_repo_name }} +{% endif %} |