Skip to content

Instantly share code, notes, and snippets.

@kkdeploy
Created June 18, 2012 16:51
Show Gist options
  • Select an option

  • Save kkdeploy/2949374 to your computer and use it in GitHub Desktop.

Select an option

Save kkdeploy/2949374 to your computer and use it in GitHub Desktop.
pg_dump all tables not consistently (!!!)
#!/bin/bash
mydir=/var/lib/pgsql/backups/`date +%Y-%m-%d_%H-%M`
function dumpdb {
mkdir -p $mydir/$1
for tbl in `psql -qAt -c "select tablename from pg_tables where schemaname = 'public';" $1` ; do
pg_dump -t $tbl $1 | gzip > $mydir/$1/$tbl.sql.gz;
done
}
function dumpall {
for db in `psql -qAt -c "SELECT datname FROM pg_database;"` ; do
dumpdb $db;
done
}
dumpall
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment