Add restore-volumes task

This commit is contained in:
Tobias Reisinger 2024-10-19 15:18:54 +02:00
parent bd6409bcc0
commit fd2eec6683
Signed by: serguzim
GPG key ID: 13AD60C237A28DFE
6 changed files with 35 additions and 3 deletions

View file

@ -51,6 +51,7 @@ all:
$(MAKE) tofu
$(MAKE) dns
@printf "\n=====\n\n"
ansible-playbook ./playbooks/stop-and-backup-unused.yml -t $(TAGS)
ansible-playbook ./playbooks/serguzim.net.yml -t $(TAGS)
visualize:

View file

@ -4,6 +4,7 @@ class FilterModule(object):
'my_service_attributes': self.my_service_attributes,
'services_to_dnscontrol': self.services_to_dnscontrol,
'services_get_backups': self.services_get_backups,
'service_get_backups': self.service_get_backups,
'service_get_domain': self.service_get_domain,
}
@ -39,6 +40,11 @@ class FilterModule(object):
result.append(backup["name"])
return result
def service_get_backups(self, all_services, wanted_service):
if service := self.find_service(all_services, wanted_service):
return service.get("backup") or []
return []
def service_get_domain(self, all_services, wanted_service):
if service := self.find_service(all_services, wanted_service):
if dns := service.get("dns"):

View file

@ -6,6 +6,9 @@
ansible.builtin.import_tasks: tasks/steps/template-docker-compose.yml
when: compose is defined
- name: Import tasks create a service.env file
- name: Import tasks to create a service.env file
ansible.builtin.import_tasks: tasks/steps/template-service-env.yml
when: env is defined
- name: Import tasks to restore volume
ansible.builtin.import_tasks: tasks/restore-volumes.yml

View file

@ -0,0 +1,6 @@
- name: Restore volumes
ansible.builtin.include_tasks:
file: tasks/steps/restore-volume.yml
loop: "{{ all_services | service_get_backups(role_name) | map(attribute='name') }}"
loop_control:
loop_var: volume_name

View file

@ -0,0 +1,16 @@
- name: Get infos on volume "{{ volume_name }}"
community.docker.docker_volume_info:
name: "{{ volume_name }}"
register: volume_info_result
- name: Restore volume "{{ volume_name }}"
ansible.builtin.command:
cmd: sudo autorestic -c .autorestic.all.yml restore -l {{ volume_name }}
chdir: "{{ (services_path, 'backup') | path_join }}"
when: not volume_info_result.exists
changed_when: true
become: true
register: cmd_result_backup
until: "cmd_result_backup is not failed"
retries: 10
delay: 10

View file

@ -254,7 +254,7 @@ services = {
domain = "s3.serguzim.me"
},
{
domain = "s3.serguzim.me"
domain = "console.s3.serguzim.me"
name = "minio-console"
alias = "minio"
}
@ -479,7 +479,7 @@ services = {
"vikunja" = {
name = "vikunja"
host = "node003"
host = "node001"
dns = [{
domain = "todo.serguzim.me"
}]