Improve backup service

This commit is contained in:
Tobias Reisinger 2024-10-07 21:24:48 +02:00
parent 9b7b5d3642
commit 33d5e30ba6
Signed by: serguzim
GPG key ID: 13AD60C237A28DFE
5 changed files with 26 additions and 18 deletions

View file

@ -10,26 +10,26 @@ all:
node002:
ansible_host: "{{ opentofu.hosts.node002.fqdn_vpn }}"
ansible_port: "{{ vault_node002.ansible_port }}"
ansible_user: "{{ vault_node002.ansible_user }}"
interactive_user: "{{ vault_node002.interactive_user }}"
ansible_port: "{{ vault_hosts.node002.ansible_port }}"
ansible_user: "{{ vault_hosts.node002.ansible_user }}"
interactive_user: "{{ vault_hosts.node002.interactive_user }}"
host_vpn:
domain: "{{ opentofu.hosts.node002.fqdn_vpn }}"
ip: "{{ opentofu.hosts.node002.ipv4_address_vpn }}"
host_backup:
hc_uid: "{{ opentofu.healthchecksio.backup.node002.id }}"
hc_url: "{{ opentofu.healthchecksio.backup.node002.ping_url }}"
uptime_kuma_token: "{{ vault_node002.backup.uptime_kuma_token }}"
gatus_token: "{{ vault_hosts.node002.backup.gatus_token }}"
node003:
ansible_host: "{{ opentofu.hosts.node003.fqdn_vpn }}"
ansible_port: "{{ vault_node003.ansible_port }}"
ansible_user: "{{ vault_node003.ansible_user }}"
interactive_user: "{{ vault_node003.interactive_user }}"
ansible_port: "{{ vault_hosts.node003.ansible_port }}"
ansible_user: "{{ vault_hosts.node003.ansible_user }}"
interactive_user: "{{ vault_hosts.node003.interactive_user }}"
host_vpn:
domain: "{{ opentofu.hosts.node003.fqdn_vpn }}"
ip: "{{ opentofu.hosts.node003.ipv4_address_vpn }}"
host_backup:
hc_uid: "{{ opentofu.healthchecksio.backup.node003.id }}"
hc_url: "{{ opentofu.healthchecksio.backup.node003.ping_url }}"
uptime_kuma_token: "{{ vault_node003.backup.uptime_kuma_token }}"
gatus_token: "{{ vault_hosts.node003.backup.gatus_token }}"

View file

@ -15,7 +15,7 @@ class FilterModule(object):
new_location = {
"to": backends_list,
"forget": "yes",
"forget": "no",
"hooks": copy.deepcopy(hooks)
}

View file

@ -32,3 +32,7 @@
chdir: "{{ service_path }}"
changed_when: false
become: true
register: cmd_result_verify
until: "cmd_result_verify is not failed"
retries: 10
delay: 10

View file

@ -5,8 +5,8 @@
if autorestic backup -av --ci
then
{{ backup_hc_command_success }}
{{ backup_uk_command_success }}
{{ backup_gatus_command_success }}
else
{{ backup_hc_command_fail }}
{{ backup_uk_command_fail }}
{{ backup_gatus_command_fail }}
fi

View file

@ -12,29 +12,33 @@ backup_msg_success: "Backup successful"
backup_curl_base: 'curl -L -m 10 --retry 5'
backup_hc_curl_base: '{{ backup_curl_base }} -X POST -H "Content-Type: text/plain"'
backup_uk_curl_base: '{{ backup_curl_base }}'
backup_gatus_curl_base: '{{ backup_curl_base }} -X POST -H "Authorization: Bearer {{ host_backup.gatus_token }}"'
backup_hc_url: '{{ host_backup.hc_url }}'
backup_uk_url: 'https://status.serguzim.me/api/push/{{ host_backup.uptime_kuma_token }}'
backup_gatus_url: 'https://status.serguzim.me/api/v1/endpoints/8-backups_backup@{{ ansible_facts.hostname }}/external'
backup_hc_command_start: '{{ backup_hc_curl_base }} --data "{{ backup_msg_start }}" {{ backup_hc_url }}/start'
backup_hc_command_success: '{{ backup_hc_curl_base }} --data "{{ backup_msg_success }}" {{ backup_hc_url }}'
backup_uk_command_success: '{{ backup_uk_curl_base }} "{{ backup_uk_url }}?status=up&msg={{ backup_msg_success | urlencode }}&ping="'
backup_hc_command_fail: '{{ backup_hc_curl_base }} --data "{{ backup_msg_fail }}" {{ backup_hc_url }}/fail'
backup_uk_command_fail: '{{ backup_uk_curl_base }} "{{ backup_uk_url }}?status=down&msg={{ backup_msg_fail | urlencode }}&ping="'
backup_gatus_command_success: '{{ backup_gatus_curl_base }} "{{ backup_gatus_url }}?success=true"'
backup_gatus_command_fail: '{{ backup_gatus_curl_base }} "{{ backup_gatus_url }}?success=false&error={{ backup_msg_fail | urlencode }}"'
backup_default_hooks:
failure:
- '{{ backup_hc_curl_base }} --data "{{ backup_msg_fail_location }}${AUTORESTIC_LOCATION}" {{ backup_hc_url }}/fail'
- '{{ backup_uk_curl_base }} "{{ backup_uk_url }}?status=down&msg={{ backup_msg_fail_location | urlencode }}${AUTORESTIC_LOCATION}&ping="'
- '{{ backup_gatus_curl_base }} "{{ backup_gatus_url }}?success=false&error={{ backup_msg_fail_location | urlencode }}${AUTORESTIC_LOCATION}'
backup_yml:
version: 2
backends: "{{ vault_backup.locations }}"
backends: "{{ vault_backup.backends }}"
locations: "{{ backup_list | map_backup_locations(vault_backup.locations, backup_default_hooks ) }}"
locations: "{{ backup_list | map_backup_locations(vault_backup.backends, backup_default_hooks ) }}"
global:
all:
cache-dir: "{{ (service_path, 'cache') | path_join }}"
retry-lock: 5m
forget:
keep-last: 7
keep-daily: 14