Add (manual) recovery scripts
This commit is contained in:
		
							parent
							
								
									a2c680f3e8
								
							
						
					
					
						commit
						4f97b66c3d
					
				
					 4 changed files with 48 additions and 1 deletions
				
			
		
							
								
								
									
										32
									
								
								playbooks/roles/backup/files/recovery/immich_database
									
										
									
									
									
										Executable file
									
								
							
							
						
						
									
										32
									
								
								playbooks/roles/backup/files/recovery/immich_database
									
										
									
									
									
										Executable file
									
								
							| 
						 | 
					@ -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
 | 
				
			||||||
| 
						 | 
					@ -31,6 +31,8 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    - name: Import tasks specific to the hooks scripts
 | 
					    - name: Import tasks specific to the hooks scripts
 | 
				
			||||||
      ansible.builtin.import_tasks: hooks.yml
 | 
					      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
 | 
					    - name: Import tasks specific to systemd
 | 
				
			||||||
      ansible.builtin.import_tasks: systemd.yml
 | 
					      ansible.builtin.import_tasks: systemd.yml
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										13
									
								
								playbooks/roles/backup/tasks/recovery.yml
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								playbooks/roles/backup/tasks/recovery.yml
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -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"
 | 
				
			||||||
| 
						 | 
					@ -177,7 +177,7 @@ services = {
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  "immich" = {
 | 
					  "immich" = {
 | 
				
			||||||
    host = "node002"
 | 
					    host = "node001"
 | 
				
			||||||
    dns = [{
 | 
					    dns = [{
 | 
				
			||||||
      domain = "gallery.serguzim.me"
 | 
					      domain = "gallery.serguzim.me"
 | 
				
			||||||
    }]
 | 
					    }]
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue