Skip to content

Commit

Permalink
* muestra la version de postgres
Browse files Browse the repository at this point in the history
  • Loading branch information
sinfallas committed Jan 7, 2025
1 parent 46805fe commit 85e466f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 2 additions & 0 deletions backupdb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ mkdir -p /app/$fecha

while read -r ip puerto usuario clave db; do
echo "$ip", "$puerto", "$usuario", "$clave", "$db"
verori=$(PGPASSWORD=$clave psql -h $ip -p $puerto -U $usuario -d $db -c 'show server_version;' | grep -v '(1 row)' | grep -v 'server_version' | sed 1d | sed 2d | cut -c 1-6)
echo "version: $verori"
PGPASSWORD="$clave" pg_dump -Fc -h $ip -p $puerto -U $usuario -d $db > /app/$fecha/$db-$ip-$puerto.dump
echo "==================="
done < ./lista.txt
Expand Down
6 changes: 6 additions & 0 deletions comparardb
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,21 @@ clear
contarori=$(PGPASSWORD=$PASS1 psql -h $IP1 -p $PORT1 -U $USER1 -d $DBNAME -c "SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = 'public' AND table_type = 'BASE TABLE'" | grep -v '(1 row)' | sed 1d | sed 1d | sed 2d)
contardes=$(PGPASSWORD=$PASS2 psql -h $IP2 -p $PORT2 -U $USER2 -d $DBNAME -c "SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = 'public' AND table_type = 'BASE TABLE'" | grep -v '(1 row)' | sed 1d | sed 1d | sed 2d)
listaori=$(PGPASSWORD=$PASS1 psql -h $IP1 -p $PORT1 -U $USER1 -d $DBNAME -c "SELECT table_name FROM information_schema.tables WHERE table_schema='public' AND table_type='BASE TABLE';" | sed 1d | sed 1d)
verori=$(PGPASSWORD=$PASS1 psql -h $IP1 -p $PORT1 -U $USER1 -d $DBNAME -c 'show server_version;' | grep -v '(1 row)' | grep -v 'server_version' | sed 1d | sed 2d | cut -c 1-6)
verdes=$(PGPASSWORD=$PASS2 psql -h $IP2 -p $PORT2 -U $USER2 -d $DBNAME -c 'show server_version;' | grep -v '(1 row)' | grep -v 'server_version' | sed 1d | sed 2d | cut -c 1-6)

if [[ "$contarori" == "$contardes" ]]; then
echo "Version de origen: $verori"
echo "Version de origen: $verdes"
echo -e "\e[00;1;92mLa cantidad de TABLAS en las db COINCIDE\e[00m"
echo "La cantidad de TABLAS en las db COINCIDE." >> $archi
echo Cantidad de tablas en origen: $contarori
echo Cantidad de tablas en origen: $contarori >> $archi
echo Cantidad de tablas en origen: $contardes
echo Cantidad de tablas en origen: $contardes >> $archi
else
echo "Version de origen: $verori"
echo "Version de origen: $verdes"
echo -e "\e[00;31mERROR: La cantidad de TABLAS en las db son diferentes.\e[00m"
echo "ERROR: La cantidad de TABLAS en las db son diferentes." >> $archi
echo Cantidad de tablas en origen: $contarori
Expand Down
5 changes: 4 additions & 1 deletion copiardb
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,12 @@ fi
rm -f /app/*.dump
clear
echo "backup"
verori=$(PGPASSWORD=$PASS1 psql -h $IP1 -p $PORT1 -U $USER1 -d $DBNAME -c 'show server_version;' | grep -v '(1 row)' | grep -v 'server_version' | sed 1d | sed 2d | cut -c 1-6)
echo "Version: $verori"
PGPASSWORD=$PASS1 pg_dump --quote-all-identifiers -Fc -h $IP1 -p $PORT1 -U $USER1 -d $DBNAME > /app/$DBNAME.dump
echo "restore"
verdes=$(PGPASSWORD=$PASS2 psql -h $IP2 -p $PORT2 -U $USER2 -d $DBNAME -c 'show server_version;' | grep -v '(1 row)' | grep -v 'server_version' | sed 1d | sed 2d | cut -c 1-6)
echo "Version: $verdes"
PGPASSWORD=$PASS2 pg_restore --single-transaction -h $IP2 -p $PORT2 -U $USER2 -d $DBNAME /app/$DBNAME.dump

echo "duracion $SECONDS segundos"
echo "Finalizado."

0 comments on commit 85e466f

Please sign in to comment.