Postgresql:备份所有表结构但只备份少数数据表

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24517168/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 01:31:48  来源:igfitidea点击:

Postgresql: backup all table structures but only a few data table

postgresqldatabase-backupspg-dump

提问by Juan Carlos Oropeza

I have a database with some tables for the application settings, lists like users, departments, cities. I want the structure and the data for those tables. So if i get a new user the backup will save it.

我有一个数据库,其中包含一些用于应用程序设置的表,以及用户、部门、城市等列表。我想要这些表的结构和数据。因此,如果我获得新用户,备份将保存它。

But also have some data for historic and calculated data, that data came from another sources and only work for some time and then expire, so backup that data will be a waste. But will need have the structure so the restore will create the tables need it for the application.

但也有一些历史数据和计算数据,这些数据来自其他来源,只能工作一段时间然后过期,所以备份这些数据将是一种浪费。但是将需要具有结构,以便恢复将创建应用程序需要它的表。

right now I'm using this command but this save all table and all data.

现在我正在使用这个命令,但这会保存所有表和所有数据。

pg_dump -U "postgres" -h "local" -p "5432" 
        -d dbName -F c -b -v -f c:\uti\backup.dmp

I have 2 additional questions regarding pg_dump.

我还有 2 个关于 pg_dump 的问题。

A) docs say option -b is for blob data. I have very big tables, but i guess this options is for only tables with a BLOB field, so shouldn't make any difference in my backup because i don't have those fields ?.

A) 文档说选项 -b 用于 blob 数据。我有非常大的表,但我想这个选项只适用于带有 BLOB 字段的表,所以我的备份不应该有任何不同,因为我没有这些字段?。

B) I see pg_dump options are for tables and schemas. How you specify if want save the functions code?

B) 我看到 pg_dump 选项用于表和模式。您如何指定是否要保存功能代码?

回答by Clodoaldo Neto

Exclude the tables you do not want to backup

排除不想备份的表

pg_dump -U "postgres" -h "local" -p "5432" 
        -d dbName -F c -b -v -f c:\uti\backup.dmp
        --exclude-table-data '*.table_name_pattern_*'
        --exclude-table-data 'some_schema.another_*_pattern_*'

The function creation code is part of the schema.

函数创建代码是架构的一部分。