Created
October 4, 2018 09:59
-
-
Save tomredsky/3c7770510a4ac33abe72678e67895ff1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
PSQL="/usr/bin/psql" | |
PGUSER="dpaikkos" | |
DBNAME="for_import" | |
DUMP="www-latest.pg" | |
REMOTE="proxima" | |
echo "Fetch $DUMP from $REMOTE" | |
rm -f $DUMP | |
/usr/bin/rsync -azL --progress $REMOTE:/mnt/sdb1/splupload/backups/spl-live-06/latest.pg $DUMP | |
echo "Dropping and creating temporary database" | |
$PSQL -d postgres -U $PGUSER<<EOF | |
DROP DATABASE IF EXISTS "${PGUSER}_old"; | |
DROP DATABASE IF EXISTS $DBNAME; | |
CREATE DATABASE $DBNAME WITH OWNER $PGUSER; | |
EOF | |
echo "Importing data" | |
$PSQL -d $DBNAME -U $PGUSER -f $DUMP | |
echo "Create and clone database $PGUSER" | |
$PSQL -d postgres -U $PGUSER<<EOF | |
BEGIN; | |
ALTER DATABASE $PGUSER RENAME TO "${PGUSER}_old"; | |
ALTER DATABASE $DBNAME RENAME TO "$PGUSER"; | |
COMMIT; | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment