Created
November 7, 2010 01:32
-
-
Save wyanez/665875 to your computer and use it in GitHub Desktop.
[Pg/MySQL]Script de respaldo detallado (un archivo .sql por cada bd) de cada una de las bases de datos de un servidor postgres/mysql
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 | |
## BEGIN CONFIG ## | |
HOST=localhost | |
USER=root | |
PASS=12345 | |
BACKUP_DIR=$HOME/mysql_bak | |
## END CONFIG ## | |
if [ ! -d $BACKUP_DIR ]; then | |
mkdir -p $BACKUP_DIR | |
fi | |
# Backup de MySQL | |
MYSQL_DBS=$(mysqlshow -h $HOST -u $USER -p$PASS | awk ' (NR > 2) && (/[a-zA-Z0-9]+[ ]+[|]/) && ( $0 !~ /mysql/) { print $2 }'); | |
for DB in $MYSQL_DBS ; do | |
echo "* Backuping MySQL data from $DB@$HOST..." | |
mysqldump -h $HOST -u $USER -p$PASS $DB > $BACKUP_DIR/mysql_$DB.sql | |
done |
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 | |
## BEGIN CONFIG ## | |
HOST=localhost | |
BACKUP_DIR=$HOME/pg_bak | |
## END CONFIG ## | |
if [ ! -d $BACKUP_DIR ]; then | |
mkdir -p $BACKUP_DIR | |
fi | |
POSTGRE_DBS=$(psql -h $HOST -U postgres -l | awk ' (NR > 2) && (/[a-zA-Z0-9]+[ ]+[|]/) && ( $0 !~ /template[0-9]/) { print $1 }'); | |
for DB in $POSTGRE_DBS ; do | |
echo "* Backuping PostgreSQL data from $DB@$HOST..." | |
pg_dump -h $HOST -U postgres $DB > $BACKUP_DIR/pg_$DB.sql | |
done |
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 | |
# | |
# backup_bd.sh - Script de respaldo a las Bases de datos del servidor postgresql comprimidas con gzip | |
# Crea un archivo por dia y escribe al log del sistema | |
# William Yanez - Actualizado al 08/01/2011 | |
# | |
DIR_BAK="/backup_bd" | |
LIST=$(psql -h localhost -Upostgres -l | awk '(NR>3) {print $1}' | grep -vE 'template[0|1]|postgres|^\(' ) | |
for Bd in $LIST | |
do | |
OF=$DIR_BAK/pg-$Bd-$(date +%a).sql.gz | |
logger - f /var/log/messages -t [BACKUP] "Respaldando $Bd en $OF" | |
pg_dump -h localhost -Upostgres $Bd | gzip -c > $OF | |
done | |
logger -t backup - f /var/log/messages "Respaldo de BD Postgres completado con exito" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment