Removed old local binary restic setup, made setup-lxc use other vault files.

This commit is contained in:
tolerryan
2026-07-28 01:02:00 +00:00
parent b460cf8d6b
commit 358aee0239
4 changed files with 60 additions and 268 deletions

View File

@@ -6,31 +6,24 @@
# Same source/location mapping as run-backups.yaml, kept in sync intentionally.
vars:
# Set to false (default) to require an explicit opt-in before anything destructive happens.
# Run with: ansible-playbook restore-backups.yaml -e "confirm_restore=true"
confirm_restore: false
# Defaults to "latest" per host+tag. Override with -e "restore_snapshot_id=abcd1234"
# to restore a specific snapshot instead.
# to restore a specific snapshot instead. Applied to every target in the loop.
restore_snapshot_id: "latest"
backup_source_label: >-
{%- if 'app_data' in group_names -%}
apps_data
{%- elif 'app_docker' in group_names -%}
apps_docker
{%- elif 'home_grail' in group_names -%}
home_grail
{%- endif -%}
group_paths:
app_data:
label: apps_data
path: /apps/data/
app_docker:
label: apps_docker
path: /apps/docker/
home_grail:
label: home_grail
path: /home/grail/
backup_location: >-
{%- if 'app_data' in group_names -%}
/apps/data/
{%- elif 'app_docker' in group_names -%}
/apps/docker/
{%- elif 'home_grail' in group_names -%}
/home/grail/
{%- endif -%}
restore_targets: "{{ group_paths | dict2items | selectattr('key', 'in', group_names) | map(attribute='value') | list }}"
restic_env: &restic_env
RESTIC_REPOSITORY: "s3:http://misamisa.duckdns.org:9000/resticbackup"
@@ -44,23 +37,22 @@
that:
- confirm_restore | bool
fail_msg: >-
This playbook will overwrite {{ backup_location }} on {{ inventory_hostname }}
with data from a restic snapshot. Re-run with -e "confirm_restore=true" to proceed,
This playbook will overwrite backup_targets paths on {{ inventory_hostname }}
with data from restic snapshots. Re-run with -e "confirm_restore=true" to proceed,
optionally with -e "restore_snapshot_id=<id>" to pick a snapshot other than latest.
success_msg: "Confirmed. Proceeding with restore on {{ inventory_hostname }}."
- name: Fail fast if backup_location/backup_source_label could not be resolved
- name: Fail fast if this host matches no known group
ansible.builtin.assert:
that:
- backup_location | trim | length > 0
- backup_source_label | trim | length > 0
- restore_targets | length > 0
fail_msg: >-
Host {{ inventory_hostname }} did not match any known inventory group
Host {{ inventory_hostname }} is not in any group listed in group_paths
(app_data, app_docker, home_grail). Check group membership.
- name: List available snapshots for this host/tag (for the log)
- name: List available snapshots (per target, for the log)
community.docker.docker_container:
name: restic_snapshots_list
name: "restic_snapshots_list_{{ item.label }}"
image: restic/restic:latest
state: started
detach: false
@@ -69,13 +61,16 @@
command: >-
snapshots
--host "{{ inventory_hostname }}"
--tag "{{ backup_source_label }}"
--tag "{{ item.label }}"
env: *restic_env
register: restic_snapshots_result
loop: "{{ restore_targets }}"
loop_control:
label: "{{ item.label }}"
- name: Show available snapshots
ansible.builtin.debug:
var: restic_snapshots_result.container.Output
var: restic_snapshots_result.results
- name: Restore Sequence with Safety Catch
block:
@@ -86,15 +81,18 @@
- name: Ensure restore target exists with correct ownership before mounting
ansible.builtin.file:
path: "{{ backup_location }}"
path: "{{ item.path }}"
state: directory
owner: docker
group: docker
mode: "0755"
loop: "{{ restore_targets }}"
loop_control:
label: "{{ item.label }}"
- name: Check for and remove stale locks
- name: Check for and remove stale locks (per target)
community.docker.docker_container:
name: restic_unlock
name: "restic_unlock_{{ item.label }}"
image: restic/restic:latest
state: started
detach: false
@@ -103,10 +101,13 @@
env: *restic_env
register: restic_unlock_result
failed_when: restic_unlock_result.status != 0
loop: "{{ restore_targets }}"
loop_control:
label: "{{ item.label }}"
- name: Restore latest snapshot into place
- name: Restore latest snapshot into place (per target)
community.docker.docker_container:
name: restic_restore
name: "restic_restore_{{ item.label }}"
image: restic/restic:latest
state: started
detach: false
@@ -116,18 +117,21 @@
command: >-
restore {{ restore_snapshot_id }}
--host "{{ inventory_hostname }}"
--tag "{{ backup_source_label }}"
--tag "{{ item.label }}"
--target /
volumes:
# NOTE: rw (no :ro) here — this is the whole point of a restore.
- "{{ backup_location }}:/backup_target/{{ backup_source_label }}"
- "{{ item.path }}:/backup_target/{{ item.label }}"
env: *restic_env
register: restic_restore_result
failed_when: restic_restore_result.status != 0
loop: "{{ restore_targets }}"
loop_control:
label: "{{ item.label }}"
- name: Show restore output
ansible.builtin.debug:
var: restic_restore_result.container.Output
var: restic_restore_result.results
always:
- name: Ensure the application is started back up
ansible.builtin.systemd: