Created
February 11, 2013 08:43
-
-
Save mohammedhanine/4753308 to your computer and use it in GitHub Desktop.
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 | |
#version : 1.1 | |
### Local ### | |
BACKUP="backup" | |
### Datos POSTGRESQL ### | |
MDB="DB_name" | |
MUSER="user_postgres" | |
MPASS="pass_postgres" | |
MHOST="host_postgres" | |
MPORT="5432" | |
### Otro servidor (¡Hay que tener activado el soporte de ssh sin contraseña (claves privada/publica)!)### | |
SERVIDOR="192.168.1.10" | |
PORT=25 | |
USUARIO="user-backup" | |
FOLDER="/var/backup" | |
### Binarios ### | |
GZIP="$(which gzip)" | |
PG_DUMP="$(which pg_dump)" | |
SCP="$(which scp)" | |
### Fecha ### | |
HOY=$(date +"%F") | |
## Carpetas ## | |
FILEBACKUP=$MDB.$HOY.sql.gz | |
BACKUPGZIP=$BACKUP/$FILEBACKUP | |
## Hacer la copia ## | |
[ -d $BACKUP ] && echo "" || mkdir -p $BACKUP | |
[ -e $BACKUPGZIP ] && echo -e '\e[1;31mYa existe la copia de seguridad, ¡Va ser remplazada en 5 segundos!\e[0m' && sleep 5 | |
$PG_DUMP -U $MUSER -h $MHOST -p $MPORT $MDB | gzip -c > $BACKUPGZIP | |
## Copiar la backup a otro servidor ## | |
[ -e $BACKUPGZIP ] && $SCP -P $PORT $BACKUPGZIP $USUARIO@$SERVIDOR:$FOLDER | |
[ -e $BACKUPGZIP ] && echo -e '\e[1;32mLa copia de seguridad esta lista en\nLocal \t\t\t '$BACKUPGZIP'\nServidor '$SERVIDOR'\t '$FOLDER'/'$FILEBACKUP' \e[0m' || echo -e '\e[1;32m Hubo algun error al crear la copia de seguridad '$BACKUP$FILEBACKUP' \e[0m' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment