-
-
Save luizkowalski/5592203 to your computer and use it in GitHub Desktop.
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 | |
oldbase="gruber" | |
newbase="gruberteste" | |
nomearquivo="$oldbase-$(date +%d%m%Y-%H%M%S).sql" | |
outputfile="/home/gts/sql-base-fiscal/$nomearquivo" | |
httpserver="/srv/http/" | |
echo "===========================================" | |
echo "Fazendo dump da base \"$oldbase\"" | |
echo "===========================================" | |
pg_dump $oldbase -U postgres -f $outputfile | |
#chown $outputfile | |
chmod 655 $outputfile | |
echo "====================================================" | |
echo "Arquivo de dump \"$outputfile\" criado." | |
echo "====================================================" | |
if [ "$1" = "--reload" ]; then | |
# Mata todas as sessoes daquela database | |
psql -U postgres -c "SELECT pg_terminate_backend(procpid) FROM pg_stat_activity WHERE procpid <> pg_backend_pid() AND datname = '$newbase';" | |
# Recria a base e depois roda o dump nela | |
psql -U postgres -c "DROP DATABASE $newbase" | |
psql -U postgres -c "CREATE DATABASE $newbase" | |
psql -d $newbase -U postgres -f $outputfile | |
# psql --user=postgres --command="DROP DATABASE $newbase; CREATE DATABASE $newbase;" | |
echo "DATABASE [$oldbase] IMPORTADA PARA [$newbase] COM SUCESSO" | |
fi | |
# Copia o dump para o servidor | |
cp $outputfile $httpserver | |
echo "Arquivo [$outputfile] copiado com sucesso em [$httpserver]" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment