mirror of
https://github.com/roles-ansible/ansible_role_restic.git
synced 2024-12-11 23:41:32 +01:00
Merge pull request #37 from rndmh3ro/add_journald_logging
add option to log to journald
This commit is contained in:
commit
1dceeed476
2 changed files with 14 additions and 8 deletions
|
@ -143,6 +143,7 @@ Available variables:
|
|||
| `schedule_month` | no (`*`) | Month when the job is run. ( 1-12, *, */2, etc ) |
|
||||
| `exclude` | no (`{}`) | Allows you to specify files to exclude. See [Exclude](#exclude) for reference. |
|
||||
| `disable_logging` | no | Optionally disable logging |
|
||||
| `log_to_journald` | no | Optionally switch logging to journald with the name of the backup job as the tag |
|
||||
| `mail_on_error` | no | Optionally send a mail if the backupjob will fail *(mailx is required)* |
|
||||
| `mail_address` | if `mail_on_error` is true | The mail addressto recive mails if you enabled ``mail_on_error``. |
|
||||
|
||||
|
|
|
@ -7,8 +7,13 @@
|
|||
{% set backup_result_log, backup_output_log = "/dev/null", "/dev/null" %}
|
||||
{% set forget_result_log, forget_output_log = "/dev/null", "/dev/null" %}
|
||||
{% else %}
|
||||
{% set backup_result_log, backup_output_log = restic_log_dir + "/" + item.name + "-backup-result.log", restic_log_dir + "/" + item.name + "-backup-output.log" %}
|
||||
{% set forget_result_log, forget_output_log = restic_log_dir + "/" + item.name + "-forget-result.log", restic_log_dir + "/" + item.name + "-forget-output.log" %}
|
||||
{% if (item.log_to_journald is defined and item.log_to_journald) %}
|
||||
{% set backup_result_log, backup_output_log = "| systemd-cat -t " + item.name, "| systemd-cat -t " + item.name %}
|
||||
{% set forget_result_log, forget_output_log = "| systemd-cat -t " + item.name, "| systemd-cat -t " + item.name %}
|
||||
{% else %}
|
||||
{% set backup_result_log, backup_output_log = ">> " + restic_log_dir + "/" + item.name + "-backup-result.log", "| tee " + restic_log_dir + "/" + item.name + "-backup-output.log" %}
|
||||
{% set forget_result_log, forget_output_log = ">> " + restic_log_dir + "/" + item.name + "-forget-result.log", "| tee " + restic_log_dir + "/" + item.name + "-forget-output.log" %}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
export RESTIC_REPOSITORY={{ restic_repos[item.repo].location }}
|
||||
|
@ -125,12 +130,12 @@ fi
|
|||
{{ tags(item.tags) }} \
|
||||
{% if item.exclude is defined %}{{ exclude(item.exclude) }}{% endif %} \
|
||||
$@ \
|
||||
{% endif %} | tee {{ backup_output_log }}
|
||||
{% endif %} {{ backup_output_log }}
|
||||
if [[ $? -eq 0 ]]
|
||||
then
|
||||
echo "$(date -u '+%Y-%m-%d %H:%M:%S') OK" >> {{ backup_result_log }}
|
||||
echo "$(date -u '+%Y-%m-%d %H:%M:%S') OK" {{ backup_result_log }}
|
||||
else
|
||||
echo "$(date -u '+%Y-%m-%d %H:%M:%S') ERROR" >> {{ backup_result_log }}
|
||||
echo "$(date -u '+%Y-%m-%d %H:%M:%S') ERROR" {{ backup_result_log }}
|
||||
fi
|
||||
|
||||
|
||||
|
@ -138,12 +143,12 @@ fi
|
|||
{#
|
||||
Define stdin forget commands
|
||||
#}
|
||||
{{ restic_install_path }}/restic forget --path {{ path(item) }} {{ retention_pattern(item) }} {% if item.prune is defined and item.prune == true %}--prune{% endif %} | tee {{ forget_output_log }}
|
||||
{{ restic_install_path }}/restic forget --path {{ path(item) }} {{ retention_pattern(item) }} {% if item.prune is defined and item.prune == true %}--prune{% endif %} {{ forget_output_log }}
|
||||
if [[ $? -eq 0 ]]
|
||||
then
|
||||
echo "$(date -u '+%Y-%m-%d %H:%M:%S') OK" >> {{ forget_result_log }}
|
||||
echo "$(date -u '+%Y-%m-%d %H:%M:%S') OK" {{ forget_result_log }}
|
||||
else
|
||||
echo "$(date -u '+%Y-%m-%d %H:%M:%S') ERROR" >> {{ forget_result_log }}
|
||||
echo "$(date -u '+%Y-%m-%d %H:%M:%S') ERROR" {{ forget_result_log }}
|
||||
{% if item.mail_on_error is defined and item.mail_on_error == true %}
|
||||
mail -s "restic backup failed on {{ ansible_hostname }}" {{ item.mail_address }} <<< "Something went wrong while running restic backup script running at {{ ansible_hostname }} at $(date -u '+%Y-%m-%d %H:%M:%S').
|
||||
{%- if item.src is defined -%}
|
||||
|
|
Loading…
Reference in a new issue