Created
July 21, 2017 21:12
-
-
Save raczajko/d19bc4e146f489d4ac44c668be0751cf to your computer and use it in GitHub Desktop.
Script para el backup automatizado de TODAS las bases de datos de un servidor Postgresql utilizando jenkins
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 | |
SERVIDOR=`hostname` | |
SERVIDOR_BACKUP=xxx.yyy.tld | |
PG_VERSION=9.3 | |
BACKUP_DIR=/tmp/ | |
REMOTE_COPY=/mnt/backup/`hostname`/`date +%Y`/`date +%m`/`date +%d`/ | |
ssh root@$SERVIDOR_BACKUP mkdir -p $REMOTE_COPY | |
TIMESLOT=`date +%Y%m%d%H%M%S` | |
databases=`/usr/pgsql-$PG_VERSION/bin/psql -U postgres -q -c "\l" | awk '{ print $1}' | grep -vE '^\||^-|^List|^Name|template[0|1]|^\('` | |
for i in $databases; | |
do | |
if ! [ "${i}" == "Nombre" ]; then | |
timeinfo=`date '+%T %x'` | |
echo "Copia de seguridad iniciado $timeinfo para el corte $TIMESLOT de la BD: $i " | |
# /usr/bin/vacuumdb -z -U postgres $i >/dev/null 2>&1 | |
/usr/pgsql-$PG_VERSION/bin/pg_dump $i -U postgres | gzip > $BACKUP_DIR/$SERVIDOR-$TIMESLOT-$i-database.gz | |
/usr/bin/scp $BACKUP_DIR/$SERVIDOR-$TIMESLOT-$i-database.gz root@$SERVIDOR_BACKUP:$REMOTE_COPY/$SERVIDOR-$TIMESLOT-$i-database.gz | |
timeinfo=`date '+%T %x'` | |
# echo "Backup and Vacuum complete at $timeinfo for time slot $TIMESLOT on database: $i " | |
echo "Backup completo a las $timeinfo para el corte $TIMESLOT de la BD: $i " | |
echo "=======================================================================" | |
fi | |
done | |
# Borra los backups en /tmp despues de haberlos copiado al servidor de backup | |
find $BACKUP_DIR/$SERVIDOR* -mmin +1 -exec rm {} \; | |
#=========================================================================== |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment