-
-
Save vicmagpac/9e7ae20308425418702b to your computer and use it in GitHub Desktop.
This file contains 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 | |
# Baseado em http://mig5.net/content/mysql-postgresql-all-databases-backup-script | |
# Rafael Bernard Rodrigues Araujo - 14/06/2012 | |
today=$(date +%y%m%d) | |
# local dir where the backups go | |
myDir='/disk2/backup/pg' | |
# this is for PostgreSQL. If you don't need it, you | |
# could leave it here, but remove the 'backup_pgsql' | |
# function call at the end of the script | |
CMD_PSQL=/usr/local/pgsql/bin/psql | |
CMD_DUMP=/usr/local/pgsql/bin/pg_dump | |
arq_tar='' | |
function backup_pgsql { | |
#Seleciona os bancos a serem copiados, eliminando os bancos de sistema | |
for db in `psql -U postgres -tq -d template1 -c "select datname from pg_database where datname not in ('template1','template0','postgres')"`; do | |
echo 'Iniciando o backup de '${db}; | |
arq_tar="${myDir}/${db}-${today}.tar"; | |
pg_dump -U postgres -F tar -f $arq_tar $db; | |
gzip $arq_tar; | |
echo 'Backup concluido'; | |
done; | |
} | |
backup_pgsql |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment