Created
March 5, 2013 16:54
-
-
Save altmas5/5091789 to your computer and use it in GitHub Desktop.
backup/dump all PostgreSQL local databases
1. dump each database schema
2. dump each database data
***Run as postgres user
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 | |
timeslot=$(date +"%Y%m%d_%H-%M"); | |
exec > log.$timeslot 2>&1 | |
set -x | |
DBs=$(psql -l|grep -v 'Name\|Nombre\|:\|rows\|filas\|\---\|databases\|Listado\|postgres\|template'|awk '{print $1}'|grep -v ^\|); | |
for db in $DBs; | |
do | |
pg_dump -sv $db -O > /var/lib/postgresql/bckps/sch_$db-$timeslot.sql; | |
sleep 5; | |
pg_dump -Fc -f /var/lib/postgresql/bckps/data_$db-$timeslot.dump --data-only $db; | |
done; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment