From 1ae64462a51c5b6dc1b1187080145199940053da Mon Sep 17 00:00:00 2001 From: Mauricio Baeza Date: Thu, 28 Jan 2021 14:00:05 -0600 Subject: [PATCH] Script for restore DB --- CHANGELOG.md | 5 +++++ VERSION | 2 +- source/restaurardb.sh | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100755 source/restaurardb.sh diff --git a/CHANGELOG.md b/CHANGELOG.md index d50109f..0ff98ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,9 @@ +0.4.0 [28-Ene-2021] +--------------------- + - Script para restaurar DB. + + 0.3.0 [28-Ene-2021] --------------------- - Script para iniciar VPN de soporte. diff --git a/VERSION b/VERSION index 0d91a54..1d0ba9e 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.3.0 +0.4.0 diff --git a/source/restaurardb.sh b/source/restaurardb.sh new file mode 100755 index 0000000..f2b7da3 --- /dev/null +++ b/source/restaurardb.sh @@ -0,0 +1,32 @@ + #!/bin/bash + +WHITE='\033[1;37m' +NC='\033[0m' + +echo -e "\033[33;5;7m¡CUIDADO! ESTE ES UN PROCESO DESTRUCTIVO\033[0m" +echo '' +echo "CONTINUA SOLO SI ESTAS 100% SEGURO" +echo '' +sleep 1 + +read -p "¿Estas seguro de restaurar esta base de datos? (escribe Si para confirmar)" +if [ "$REPLY" != "Si" ]; then + exit +fi + +echo '' +rfc="${1:0:-3}" +rfc="${rfc,,}" +name="$1" +path="$HOME/compartido/$name" + +if ! [ -f $path ]; then + echo "No se encontró la base de datos: $name" + exit +fi + +echo "Restaurando base de datos: $name" +psql -U postgres -c "DROP DATABASE $rfc" +psql -U postgres -c "CREATE DATABASE $rfc WITH OWNER $rfc" +pg_restore -U postgres -d $rfc $path +echo "Base de datos restaurada correctamente"