29 lines
		
	
	
	
		
			624 B
		
	
	
	
		
			Bash
		
	
	
		
			Executable file
		
	
	
	
	
			
		
		
	
	
			29 lines
		
	
	
	
		
			624 B
		
	
	
	
		
			Bash
		
	
	
		
			Executable file
		
	
	
	
	
| #!/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"
 |