feat(kopia): add restore procedure
This commit is contained in:
@@ -138,14 +138,6 @@
|
|||||||
tags: ["init", "nftables"]
|
tags: ["init", "nftables"]
|
||||||
tags: ["init", "nftables"]
|
tags: ["init", "nftables"]
|
||||||
|
|
||||||
- name: Set crowdsec
|
|
||||||
ansible.builtin.include_role:
|
|
||||||
name: "common"
|
|
||||||
tasks_from: "services/set_crowdsec"
|
|
||||||
apply:
|
|
||||||
tags: ["site", "crowdsec"]
|
|
||||||
tags: ["site", "crowdsec"]
|
|
||||||
|
|
||||||
- name: Set alloy
|
- name: Set alloy
|
||||||
ansible.builtin.include_role:
|
ansible.builtin.include_role:
|
||||||
name: "common"
|
name: "common"
|
||||||
@@ -154,6 +146,14 @@
|
|||||||
tags: ["init", "alloy"]
|
tags: ["init", "alloy"]
|
||||||
tags: ["init", "alloy"]
|
tags: ["init", "alloy"]
|
||||||
|
|
||||||
|
- name: Set crowdsec
|
||||||
|
ansible.builtin.include_role:
|
||||||
|
name: "common"
|
||||||
|
tasks_from: "services/set_crowdsec"
|
||||||
|
apply:
|
||||||
|
tags: ["site", "crowdsec"]
|
||||||
|
tags: ["site", "crowdsec"]
|
||||||
|
|
||||||
- name: Set kopia
|
- name: Set kopia
|
||||||
ansible.builtin.include_role:
|
ansible.builtin.include_role:
|
||||||
name: "common"
|
name: "common"
|
||||||
@@ -258,6 +258,14 @@
|
|||||||
tags: ["site", "homebox"]
|
tags: ["site", "homebox"]
|
||||||
tags: ["site", "homebox"]
|
tags: ["site", "homebox"]
|
||||||
|
|
||||||
|
- name: Set homepage
|
||||||
|
ansible.builtin.include_role:
|
||||||
|
name: "app"
|
||||||
|
tasks_from: "services/set_homepage"
|
||||||
|
apply:
|
||||||
|
tags: ["site", "homepage"]
|
||||||
|
tags: ["site", "homepage"]
|
||||||
|
|
||||||
- name: Flush handlers right now
|
- name: Flush handlers right now
|
||||||
ansible.builtin.meta: "flush_handlers"
|
ansible.builtin.meta: "flush_handlers"
|
||||||
|
|
||||||
|
|||||||
@@ -138,6 +138,14 @@
|
|||||||
tags: ["site", "crowdsec"]
|
tags: ["site", "crowdsec"]
|
||||||
tags: ["site", "crowdsec"]
|
tags: ["site", "crowdsec"]
|
||||||
|
|
||||||
|
- name: Set kopia
|
||||||
|
ansible.builtin.include_role:
|
||||||
|
name: "common"
|
||||||
|
tasks_from: "services/set_kopia"
|
||||||
|
apply:
|
||||||
|
tags: ["site", "kopia"]
|
||||||
|
tags: ["site", "kopia"]
|
||||||
|
|
||||||
- name: Set ca
|
- name: Set ca
|
||||||
ansible.builtin.include_role:
|
ansible.builtin.include_role:
|
||||||
name: "infra"
|
name: "infra"
|
||||||
@@ -209,11 +217,3 @@
|
|||||||
apply:
|
apply:
|
||||||
tags: ["site", "grafana"]
|
tags: ["site", "grafana"]
|
||||||
tags: ["site", "grafana"]
|
tags: ["site", "grafana"]
|
||||||
|
|
||||||
- name: Set kopia
|
|
||||||
ansible.builtin.include_role:
|
|
||||||
name: "common"
|
|
||||||
tasks_from: "services/set_kopia"
|
|
||||||
apply:
|
|
||||||
tags: ["site", "kopia"]
|
|
||||||
tags: ["site", "kopia"]
|
|
||||||
|
|||||||
@@ -365,6 +365,78 @@
|
|||||||
become: true
|
become: true
|
||||||
no_log: true
|
no_log: true
|
||||||
|
|
||||||
|
- name: Check data directory empty
|
||||||
|
ansible.builtin.find:
|
||||||
|
path: "{{ node['home_path'] }}/data/"
|
||||||
|
file_type: "any"
|
||||||
|
hidden: true
|
||||||
|
recurse: false
|
||||||
|
register: "is_data_dir_empty"
|
||||||
|
|
||||||
|
- name: Connect kopia server
|
||||||
|
environment:
|
||||||
|
KOPIA_PASSWORD: "{{ hostvars['console']['kopia']['users'][node['name']] }}"
|
||||||
|
ansible.builtin.shell: |
|
||||||
|
/usr/bin/kopia repository connect server \
|
||||||
|
--url=https://{{ services['kopia']['domain']['internal'] }}.{{ domain['internal'] }}:443 \
|
||||||
|
--override-username={{ node['name'] }} \
|
||||||
|
--override-hostname={{ node['name'] }}.{{ domain['internal'] }}
|
||||||
|
become: true
|
||||||
|
when: is_data_dir_empty.matched == 0
|
||||||
|
changed_when: false
|
||||||
|
failed_when: is_kopia_connected.rc != 0
|
||||||
|
register: "is_kopia_connected"
|
||||||
|
no_log: true
|
||||||
|
|
||||||
|
- name: Check whether Kopia snapshot exists
|
||||||
|
environment:
|
||||||
|
KOPIA_PASSWORD: "{{ hostvars['console']['kopia']['users'][node['name']] }}"
|
||||||
|
ansible.builtin.shell: |
|
||||||
|
/usr/bin/kopia snapshot list \
|
||||||
|
{{ node['name'] }}@{{ node['name'] }}.{{ domain['internal'] }}:{{ node['home_path'] }}/data \
|
||||||
|
--json \
|
||||||
|
--max-results=1
|
||||||
|
become: true
|
||||||
|
when: (is_kopia_connected.rc | default(1)) == 0
|
||||||
|
changed_when: false
|
||||||
|
failed_when: false
|
||||||
|
register: "is_snapshot_exist"
|
||||||
|
no_log: true
|
||||||
|
|
||||||
|
- name: Restore data directory
|
||||||
|
environment:
|
||||||
|
KOPIA_PASSWORD: "{{ hostvars['console']['kopia']['users'][node['name']] }}"
|
||||||
|
ansible.builtin.shell: |
|
||||||
|
/usr/bin/kopia snapshot restore \
|
||||||
|
--snapshot-time=latest \
|
||||||
|
{{ node['name'] }}@{{ node['name'] }}.{{ domain['internal'] }}:{{ node['home_path'] }}/data \
|
||||||
|
{{ node['home_path'] }}/data
|
||||||
|
become: true
|
||||||
|
when:
|
||||||
|
- is_data_dir_empty.matched == 0
|
||||||
|
- (is_kopia_connected.rc | default(1)) == 0
|
||||||
|
- (is_snapshot_exist.stdout |
|
||||||
|
default('[]', true) |
|
||||||
|
from_json |
|
||||||
|
list |
|
||||||
|
length
|
||||||
|
) > 0
|
||||||
|
changed_when: is_kopia_restored.rc == 0
|
||||||
|
failed_when: is_kopia_restored.rc != 0
|
||||||
|
register: "is_kopia_restored"
|
||||||
|
no_log: true
|
||||||
|
|
||||||
|
- name: Disconnect kopia server
|
||||||
|
ansible.builtin.shell: |
|
||||||
|
/usr/bin/kopia repository disconnect
|
||||||
|
become: true
|
||||||
|
when:
|
||||||
|
- is_data_dir_empty.matched == 0
|
||||||
|
- (is_kopia_connected.rc | default(1)) == 0
|
||||||
|
changed_when: false
|
||||||
|
failed_when: false
|
||||||
|
no_log: true
|
||||||
|
|
||||||
- name: Deploy kopia backup service files
|
- name: Deploy kopia backup service files
|
||||||
ansible.builtin.template:
|
ansible.builtin.template:
|
||||||
src: "{{ hostvars['console']['node']['config_path'] }}/services/systemd/common/kopia/{{ item }}.j2"
|
src: "{{ hostvars['console']['node']['config_path'] }}/services/systemd/common/kopia/{{ item }}.j2"
|
||||||
@@ -421,8 +493,8 @@
|
|||||||
ansible.builtin.shell: |
|
ansible.builtin.shell: |
|
||||||
/usr/bin/kopia repository connect server \
|
/usr/bin/kopia repository connect server \
|
||||||
--url=https://{{ services['kopia']['domain']['internal'] }}.{{ domain['internal'] }}:443 \
|
--url=https://{{ services['kopia']['domain']['internal'] }}.{{ domain['internal'] }}:443 \
|
||||||
--override-username=console \
|
--override-username={{ node['name'] }} \
|
||||||
--override-hostname=console.{{ domain['internal'] }}
|
--override-hostname={{ node['name'] }}.{{ domain['internal'] }}
|
||||||
changed_when: false
|
changed_when: false
|
||||||
failed_when: is_kopia_connected.rc != 0
|
failed_when: is_kopia_connected.rc != 0
|
||||||
register: "is_kopia_connected"
|
register: "is_kopia_connected"
|
||||||
|
|||||||
Reference in New Issue
Block a user