Last active
December 12, 2019 10:09
-
-
Save jarnaldich/953c0c437e4c2f67482a63d7e2f32067 to your computer and use it in GitHub Desktop.
Recuperar Backup Postgres #postgresql #backup #shell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
SRC_DBNAME=$1 | |
TARGET_DBNAME=$2 | |
DATE=`date +%Y%m%d` | |
PGPASSWORD=$SRCPASS /usr/lib/postgresql/9.5/bin/pg_dump -F c --file /mnt/d/public/lliscat_$DATE.backup --host 172.30.22.110 --username postgres --format=c --blobs $SRC_DBNAME | |
PGPASSWORD=$DSTPASS psql -h phineas -U postgres <<END | |
SELECT pg_terminate_backend(pid) | |
FROM pg_stat_activity | |
WHERE pid <> pg_backend_pid() AND datname = '$TARGET_DBNAME'; | |
DROP DATABASE IF EXISTS $TARGET_DBNAME; | |
CREATE DATABASE $TARGET_DBNAME; | |
\\c $TARGET_DBNAME | |
CREATE EXTENSION postgis; | |
SELECT postgis_full_version(); | |
END | |
PGPASSWORD=$DSTPASS pg_restore -h phineas -U postgres -d $TARGET_DBNAME /mnt/d/public/lliscat_$DATE.backup |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment