Add postgresql role
This commit is contained in:
		
							parent
							
								
									4f97b66c3d
								
							
						
					
					
						commit
						56885d70b6
					
				
					 7 changed files with 152 additions and 4 deletions
				
			
		
							
								
								
									
										29
									
								
								playbooks/roles/backup/files/recovery/postgresql
									
										
									
									
									
										Executable file
									
								
							
							
						
						
									
										29
									
								
								playbooks/roles/backup/files/recovery/postgresql
									
										
									
									
									
										Executable file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,29 @@
 | 
			
		|||
#!/usr/bin/env bash
 | 
			
		||||
 | 
			
		||||
set -e
 | 
			
		||||
 | 
			
		||||
target="$1"
 | 
			
		||||
recovery_file="pg_dumpall.sql.gz"
 | 
			
		||||
if [ -n "$target" ]; then
 | 
			
		||||
	recovery_file="pg_dump_$target.sql.gz"
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
tmp_dir=$(mktemp -d)
 | 
			
		||||
recovery_file_path="$tmp_dir/opt/services/_backup/postgresql/$recovery_file"
 | 
			
		||||
 | 
			
		||||
cd /opt/services/backup/
 | 
			
		||||
 | 
			
		||||
echo "Restoring backup..."
 | 
			
		||||
autorestic -c .autorestic.all.yml restore -l postgresql --from borgbase --to "$tmp_dir"
 | 
			
		||||
echo "Backup restored."
 | 
			
		||||
 | 
			
		||||
echo "Recovery file: $recovery_file"
 | 
			
		||||
 | 
			
		||||
echo "Restoring database..."
 | 
			
		||||
cat "$recovery_file_path" \
 | 
			
		||||
  | gunzip \
 | 
			
		||||
  | sudo -u postgres psql
 | 
			
		||||
echo "Database restored."
 | 
			
		||||
 | 
			
		||||
echo "Removing temporary files..."
 | 
			
		||||
rm -rf "$tmp_dir"
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue