Improve usage of pg_dump in backup
This commit is contained in:
parent
731647be9d
commit
f7936633e5
3 changed files with 13 additions and 14 deletions
|
|
@ -3,10 +3,11 @@
|
|||
set -e
|
||||
|
||||
target="$1"
|
||||
recovery_file="pg_dumpall.sql.gz"
|
||||
if [ -n "$target" ]; then
|
||||
recovery_file="pg_dump_$target.sql.gz"
|
||||
if [ -z "$target" ]; then
|
||||
echo "No target given!"
|
||||
exit 1
|
||||
fi
|
||||
recovery_file="pg_dump_$target.dump"
|
||||
|
||||
tmp_dir=$(mktemp -d)
|
||||
recovery_file_path="$tmp_dir/opt/services/_backup/postgresql/$recovery_file"
|
||||
|
|
@ -20,9 +21,7 @@ echo "Backup restored."
|
|||
echo "Recovery file: $recovery_file"
|
||||
|
||||
echo "Restoring database..."
|
||||
cat "$recovery_file_path" \
|
||||
| gunzip \
|
||||
| sudo -u postgres psql
|
||||
sudo -u postgres pg_restore -C "$recovery_file_path"
|
||||
echo "Database restored."
|
||||
|
||||
echo "Removing temporary files..."
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue