views:

290

answers:

1

Can I programatically(or whichever way works fine) create the backup of a database, with only the tables I want? I have around 100 tables in my database and I want only 10 tables backup(ofcourse all are interdependant). How can I achieve this? And by the way I have a postgresql database.

+7  A: 

Of course. pg_dump lets you pass list of tables with parameter -t

To clear some doubts. True, the -t parameter accepts only one pattern. But it's a pattern very similar to regular expression, so if you want to dump tables A, B & C you can do:

pg_dump -t '(A|B|C)'
vartec
http://www.postgresql.org/docs/8.3/interactive/backup-dump.html, but add the '-t' option (see pg_dump --help).
Jarret Hardie
I don't think older versions of PostgreSQL allow the '-t' option.
Paul Tomblin
Actually, I think in 8.0, it allowed only *one* -t option, so you could only dump one table at a time.
Paul Tomblin
@Paul "the table parameter is interpreted as a pattern according to the same rules used by psql's \d commands"
vartec