Search Postgresql Archives

Re: split pg_dumpall backups per database

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Luca Ferrari wrote:
Hi all,
is it possible to instrument pg_dumpall to produce separate sql files for each database it is going to backup? I'd like to keep separate backups of my databases, but using pg_dump can lead to forgetting a database.....

You could build a shell script to repeatedly call pg_dump:

#!/bin/sh
DBLIST=`/path/to/psql -p 5483 -U postgres -d postgres -q -t -c 'SELECT datname from pg_database'`
for d in $DBLIST
do
    echo "db = $d";
    pg_dump -U postgres -Fc $d > /path/to/backups/$d.dump
done


Two things to remember:
1. If you're going to have spaces or punctuation in the database names you'll need to quote all the $d 2. You'll want to call pg_dumpall --globals-only to get all the user details.

--
  Richard Huxton
  Archonet Ltd

--
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux