diff --git a/playbooks/roles/backup/files/recovery/immich_database b/playbooks/roles/backup/files/recovery/immich_database new file mode 100755 index 0000000..f3fd004 --- /dev/null +++ b/playbooks/roles/backup/files/recovery/immich_database @@ -0,0 +1,32 @@ +#!/usr/bin/env bash + +set -e + +tmp_dir=$(mktemp -d) + +cd /opt/services/backup/ + +echo "Restoring backup..." +autorestic -c .autorestic.all.yml restore -l immich_database --from borgbase --to "$tmp_dir" +echo "Backup restored." + +cd /opt/services/immich + +echo "Starting database..." +docker compose up -d database + +echo "Waiting for database to start..." +sleep 10 + +echo "Restoring database..." +cat "$tmp_dir/opt/services/_backup/immich_database/immich.sql.gz" \ + | gunzip \ + | sed "s/SELECT pg_catalog.set_config('search_path', '', false);/SELECT pg_catalog.set_config('search_path', 'public, pg_catalog', true);/g" \ + | docker exec -i immich-database-1 psql --username=immich +echo "Database restored." + +echo "Removing temporary files..." +rm -rf "$tmp_dir" + +echo "Starting services..." +docker compose up -d diff --git a/playbooks/roles/backup/tasks/main.yml b/playbooks/roles/backup/tasks/main.yml index f07ed74..5f67f92 100644 --- a/playbooks/roles/backup/tasks/main.yml +++ b/playbooks/roles/backup/tasks/main.yml @@ -31,6 +31,8 @@ - name: Import tasks specific to the hooks scripts ansible.builtin.import_tasks: hooks.yml + - name: Import tasks specific to the recovery scripts + ansible.builtin.import_tasks: recovery.yml - name: Import tasks specific to systemd ansible.builtin.import_tasks: systemd.yml diff --git a/playbooks/roles/backup/tasks/recovery.yml b/playbooks/roles/backup/tasks/recovery.yml new file mode 100644 index 0000000..2398660 --- /dev/null +++ b/playbooks/roles/backup/tasks/recovery.yml @@ -0,0 +1,13 @@ +- name: Set recovery path + ansible.builtin.set_fact: + recovery_path: "{{ (service_path, 'recovery') | path_join }}" +- name: Create recovery directory + ansible.builtin.file: + path: "{{ recovery_path }}" + state: directory + mode: "0755" +- name: Copy the recovery + ansible.builtin.copy: + src: recovery/ + dest: "{{ recovery_path }}" + mode: "0755" diff --git a/services.auto.tfvars b/services.auto.tfvars index 6f57077..35bcfc6 100644 --- a/services.auto.tfvars +++ b/services.auto.tfvars @@ -177,7 +177,7 @@ services = { }, "immich" = { - host = "node002" + host = "node001" dns = [{ domain = "gallery.serguzim.me" }]