Skip to content

Instantly share code, notes, and snippets.

@altmas5
Created March 5, 2013 16:54
Show Gist options
  • Save altmas5/5091789 to your computer and use it in GitHub Desktop.
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
#!/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