Redconnection
Redconnection

Reputation: 615

Dumping psql tables with specific prefixes

Im currently using the tool pg_dump to dump tables from my database. I would like to automate this process, however, i have not found a way to specify pg_dump to dump multiple databases that have the same prefix.

Any help in this matter would be greatly appreciated

Upvotes: 7

Views: 7857

Answers (3)

Mamad Asgari
Mamad Asgari

Reputation: 127

You can use parameter "-t" multiple times if you want to dump more than one table.

$ pg_dump -t table1 -t table2 mydb > dump.sql

-t table --table=table

Dump only tables (or views or sequences) matching table. Multiple

tables can be selected by writing multiple -t switches.

Upvotes: 1

Frank Heikens
Frank Heikens

Reputation: 127116

Examples from the manual:

To dump all tables whose names start with emp in the detroit schema, except for the table named employee_log:

$ pg_dump -t 'detroit.emp*' -T detroit.employee_log mydb > db.sql

To dump all schemas whose names start with east or west and end in gsm, excluding any schemas whose names contain the word test:

$ pg_dump -n 'east*gsm' -n 'west*gsm' -N 'test' mydb > db.sql

The same, using regular expression notation to consolidate the switches:

$ pg_dump -n '(east|west)*gsm' -N 'test' mydb > db.sql

To dump all database objects except for tables whose names begin with ts_:

$ pg_dump -T 'ts_*' mydb > db.sql

Upvotes: 12

francs
francs

Reputation: 9189

I'm not sure that if I undstand what you said exactly. I advise you that you can edit a shell script to dump each database .

Upvotes: 0

Related Questions