Script for restore DB

This commit is contained in:
Mauricio Baeza 2021-01-28 14:00:05 -06:00
parent f570084f50
commit 1ae64462a5
3 changed files with 38 additions and 1 deletions

View File

@ -1,4 +1,9 @@
0.4.0 [28-Ene-2021]
---------------------
- Script para restaurar DB.
0.3.0 [28-Ene-2021] 0.3.0 [28-Ene-2021]
--------------------- ---------------------
- Script para iniciar VPN de soporte. - Script para iniciar VPN de soporte.

View File

@ -1 +1 @@
0.3.0 0.4.0

32
source/restaurardb.sh Executable file
View File

@ -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"