Created
December 4, 2012 11:26
-
-
Save pcaro/4202860 to your computer and use it in GitHub Desktop.
Postgres simple backp
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 | |
# Puedes ver la fecha de la fecha en la cabecera de los .sqlc: | |
# pg_restore -l backupu.sqlc | head -n 15 | |
# Echo: "Ejecutar este script como usuario con permisos (postgres)" | |
BKPDIR=postgres-backup-${DATE} | |
RSTFILE=restore.README | |
USER=postgres | |
GLOBALS=globals.sql | |
DATE=`date +%Y%m%d-%Hh%M` | |
mkdir postgres-backup-${DATE} | |
cd postgres-backup-${DATE} | |
pg_dumpall -g -U $USER --file=$GLOBALS; | |
echo "#--- Date: $DATE" >> $RSTFILE | |
echo "#---restore globals: " >> $RSTFILE | |
echo "psql -U postgres < $GLOBALS : " >> $RSTFILE | |
psql -AtU $USER -c "SELECT datname FROM pg_database \ | |
WHERE NOT datistemplate"| \ | |
while read f; | |
do | |
output=$f.sqlc | |
echo "Backup of $f to $output" | |
pg_dump -U$USER --format=c --file=${output} $f; | |
echo "#---restore $f" >> $RSTFILE | |
echo "pg_restore -U postgres --dbname=$f $output" >> $RSTFILE | |
echo "" >> $RSTFILE | |
done; | |
cd .. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment