Menu

文档

导出模式

openGauss目前支持使用gs_dump工具导出模式级的内容,包含模式的数据和定义。用户可通过灵活的自定义方式导出模式内容,不仅支持选定一个模式或多个模式的导出,还支持排除一个模式或者多个模式的导出。可根据需要自定义导出如下信息:

  • 导出模式全量信息,包含数据和对象定义。
  • 仅导出数据,即模式包含表中的数据,不包含对象定义。
  • 仅导出模式对象定义,包括:表定义、存储过程定义和索引定义等。

操作步骤

  1. 以操作系统用户omm登录数据库主节点。
  2. 使用gs_dump同时导出hr和public模式。

    gs_dump -U jack -f /home/omm/backup/MPPDB_schema_backup -p 8000 human_resource -n hr -n public -F d 
    Password:
    

表 1 常用参数说明

<a name="zh-cn_topic_0237121170_table1781122816253"></a>
<table><thead align="left"><tr id="zh-cn_topic_0237121170_row10837281257"><th class="cellrowborder" valign="top" width="24.169999999999998%" id="mcps1.2.4.1.1"><p id="zh-cn_topic_0237121170_p48382816258"><a name="zh-cn_topic_0237121170_p48382816258"></a><a name="zh-cn_topic_0237121170_p48382816258"></a>参数</p>
</th>
<th class="cellrowborder" valign="top" width="44.16%" id="mcps1.2.4.1.2"><p id="zh-cn_topic_0237121170_p18332812257"><a name="zh-cn_topic_0237121170_p18332812257"></a><a name="zh-cn_topic_0237121170_p18332812257"></a>参数说明</p>
</th>
<th class="cellrowborder" valign="top" width="31.669999999999998%" id="mcps1.2.4.1.3"><p id="zh-cn_topic_0237121170_p583122816257"><a name="zh-cn_topic_0237121170_p583122816257"></a><a name="zh-cn_topic_0237121170_p583122816257"></a>举例</p>
</th>
</tr>
</thead>
<tbody><tr id="zh-cn_topic_0237121170_row1483528152520"><td class="cellrowborder" valign="top" width="24.169999999999998%" headers="mcps1.2.4.1.1 "><p id="zh-cn_topic_0237121170_p3830287252"><a name="zh-cn_topic_0237121170_p3830287252"></a><a name="zh-cn_topic_0237121170_p3830287252"></a>-U</p>
</td>
<td class="cellrowborder" valign="top" width="44.16%" headers="mcps1.2.4.1.2 "><p id="zh-cn_topic_0237121170_p8232111218592"><a name="zh-cn_topic_0237121170_p8232111218592"></a><a name="zh-cn_topic_0237121170_p8232111218592"></a>连接数据库的用户名。</p>
</td>
<td class="cellrowborder" valign="top" width="31.669999999999998%" headers="mcps1.2.4.1.3 "><p id="zh-cn_topic_0237121170_p1583152842510"><a name="zh-cn_topic_0237121170_p1583152842510"></a><a name="zh-cn_topic_0237121170_p1583152842510"></a>-U jack</p>
</td>
</tr>
<tr id="zh-cn_topic_0237121170_row199295855317"><td class="cellrowborder" valign="top" width="24.169999999999998%" headers="mcps1.2.4.1.1 "><p id="zh-cn_topic_0237121170_p89920588539"><a name="zh-cn_topic_0237121170_p89920588539"></a><a name="zh-cn_topic_0237121170_p89920588539"></a>-W</p>
</td>
<td class="cellrowborder" valign="top" width="44.16%" headers="mcps1.2.4.1.2 "><p id="zh-cn_topic_0237121170_p69431335210"><a name="zh-cn_topic_0237121170_p69431335210"></a><a name="zh-cn_topic_0237121170_p69431335210"></a>指定用户连接的密码。</p>
<a name="zh-cn_topic_0237121170_ul194074341627"></a><a name="zh-cn_topic_0237121170_ul194074341627"></a><ul id="zh-cn_topic_0237121170_ul194074341627"><li>如果主机的认证策略是trust,则不会对数据库管理员进行密码验证,即无需输入-W选项。</li><li>如果没有-W选项,并且不是数据库管理员,会提示用户输入密码。</li></ul>
</td>
<td class="cellrowborder" valign="top" width="31.669999999999998%" headers="mcps1.2.4.1.3 "><p id="zh-cn_topic_0237121170_p1898043113581"><a name="zh-cn_topic_0237121170_p1898043113581"></a><a name="zh-cn_topic_0237121170_p1898043113581"></a>-W abcd@123</p>
</td>
</tr>
<tr id="zh-cn_topic_0237121170_row1823810139566"><td class="cellrowborder" valign="top" width="24.169999999999998%" headers="mcps1.2.4.1.1 "><p id="zh-cn_topic_0237121170_p11238171316560"><a name="zh-cn_topic_0237121170_p11238171316560"></a><a name="zh-cn_topic_0237121170_p11238171316560"></a>-f</p>
</td>
<td class="cellrowborder" valign="top" width="44.16%" headers="mcps1.2.4.1.2 "><p id="zh-cn_topic_0237121170_p323861311565"><a name="zh-cn_topic_0237121170_p323861311565"></a><a name="zh-cn_topic_0237121170_p323861311565"></a>将导出文件发送至指定目录文件夹。如果这里省略,则使用标准输出。</p>
</td>
<td class="cellrowborder" valign="top" width="31.669999999999998%" headers="mcps1.2.4.1.3 "><p id="zh-cn_topic_0237121170_p11238513175619"><a name="zh-cn_topic_0237121170_p11238513175619"></a><a name="zh-cn_topic_0237121170_p11238513175619"></a>-f /home/<span id="zh-cn_topic_0237121170_text1189611819533"><a name="zh-cn_topic_0237121170_text1189611819533"></a><a name="zh-cn_topic_0237121170_text1189611819533"></a>omm</span>/backup/MPPDB<em id="zh-cn_topic_0237121170_i158581933132416"><a name="zh-cn_topic_0237121170_i158581933132416"></a><a name="zh-cn_topic_0237121170_i158581933132416"></a>_</em>schema_backup</p>
</td>
</tr>
<tr id="zh-cn_topic_0237121170_row9411195215519"><td class="cellrowborder" valign="top" width="24.169999999999998%" headers="mcps1.2.4.1.1 "><p id="zh-cn_topic_0237121170_p84119521250"><a name="zh-cn_topic_0237121170_p84119521250"></a><a name="zh-cn_topic_0237121170_p84119521250"></a>-p</p>
</td>
<td class="cellrowborder" valign="top" width="44.16%" headers="mcps1.2.4.1.2 "><p id="zh-cn_topic_0237121170_p14838631464"><a name="zh-cn_topic_0237121170_p14838631464"></a><a name="zh-cn_topic_0237121170_p14838631464"></a>指定服务器所侦听的TCP端口或本地Unix域套接字后缀,以确保连接。</p>
</td>
<td class="cellrowborder" valign="top" width="31.669999999999998%" headers="mcps1.2.4.1.3 "><p id="zh-cn_topic_0237121170_p341117521853"><a name="zh-cn_topic_0237121170_p341117521853"></a><a name="zh-cn_topic_0237121170_p341117521853"></a>-p <span id="zh-cn_topic_0237121170_text6660142225020"><a name="zh-cn_topic_0237121170_text6660142225020"></a><a name="zh-cn_topic_0237121170_text6660142225020"></a>8000</span></p>
</td>
</tr>
<tr id="zh-cn_topic_0237121170_row1362511481379"><td class="cellrowborder" valign="top" width="24.169999999999998%" headers="mcps1.2.4.1.1 "><p id="zh-cn_topic_0237121170_p8782872280"><a name="zh-cn_topic_0237121170_p8782872280"></a><a name="zh-cn_topic_0237121170_p8782872280"></a>dbname</p>
</td>
<td class="cellrowborder" valign="top" width="44.16%" headers="mcps1.2.4.1.2 "><p id="zh-cn_topic_0237121170_p1278211752814"><a name="zh-cn_topic_0237121170_p1278211752814"></a><a name="zh-cn_topic_0237121170_p1278211752814"></a>需要导出的数据库名称</p>
</td>
<td class="cellrowborder" valign="top" width="31.669999999999998%" headers="mcps1.2.4.1.3 "><p id="zh-cn_topic_0237121170_p12782147122820"><a name="zh-cn_topic_0237121170_p12782147122820"></a><a name="zh-cn_topic_0237121170_p12782147122820"></a>human_resource</p>
</td>
</tr>
<tr id="zh-cn_topic_0237121170_row1280163131716"><td class="cellrowborder" valign="top" width="24.169999999999998%" headers="mcps1.2.4.1.1 "><p id="zh-cn_topic_0237121170_p14801831178"><a name="zh-cn_topic_0237121170_p14801831178"></a><a name="zh-cn_topic_0237121170_p14801831178"></a>-n</p>
</td>
<td class="cellrowborder" valign="top" width="44.16%" headers="mcps1.2.4.1.2 "><p id="zh-cn_topic_0237121170_p2391133813175"><a name="zh-cn_topic_0237121170_p2391133813175"></a><a name="zh-cn_topic_0237121170_p2391133813175"></a>只导出与模式名称匹配的模式,此选项包括模式本身和所有它包含的对象。</p>
<a name="zh-cn_topic_0237121170_ul11933635102416"></a><a name="zh-cn_topic_0237121170_ul11933635102416"></a><ul id="zh-cn_topic_0237121170_ul11933635102416"><li>单个模式:-n <em id="zh-cn_topic_0237121170_i182341435112017"><a name="zh-cn_topic_0237121170_i182341435112017"></a><a name="zh-cn_topic_0237121170_i182341435112017"></a>schemaname</em></li><li>多个模式:多次输入-n <em id="zh-cn_topic_0237121170_i65454714206"><a name="zh-cn_topic_0237121170_i65454714206"></a><a name="zh-cn_topic_0237121170_i65454714206"></a>schemaname</em></li></ul>
</td>
<td class="cellrowborder" valign="top" width="31.669999999999998%" headers="mcps1.2.4.1.3 "><a name="zh-cn_topic_0237121170_ul13923102591912"></a><a name="zh-cn_topic_0237121170_ul13923102591912"></a><ul id="zh-cn_topic_0237121170_ul13923102591912"><li>单个模式:-n hr</li><li>多个模式:-n hr -n public</li></ul>
</td>
</tr>
<tr id="zh-cn_topic_0237121170_row1885993510341"><td class="cellrowborder" valign="top" width="24.169999999999998%" headers="mcps1.2.4.1.1 "><p id="zh-cn_topic_0237121170_p141711116303"><a name="zh-cn_topic_0237121170_p141711116303"></a><a name="zh-cn_topic_0237121170_p141711116303"></a>-F</p>
</td>
<td class="cellrowborder" valign="top" width="44.16%" headers="mcps1.2.4.1.2 "><p id="zh-cn_topic_0237121170_p9417511183018"><a name="zh-cn_topic_0237121170_p9417511183018"></a><a name="zh-cn_topic_0237121170_p9417511183018"></a>选择导出文件格式。-F参数值如下:</p>
<a name="zh-cn_topic_0237121170_ul4489102813339"></a><a name="zh-cn_topic_0237121170_ul4489102813339"></a><ul id="zh-cn_topic_0237121170_ul4489102813339"><li>p:纯文本格式</li><li>c:自定义归档</li><li>d:目录归档格式</li><li>t:tar归档格式</li></ul>
</td>
<td class="cellrowborder" valign="top" width="31.669999999999998%" headers="mcps1.2.4.1.3 "><p id="zh-cn_topic_0237121170_p4417181118302"><a name="zh-cn_topic_0237121170_p4417181118302"></a><a name="zh-cn_topic_0237121170_p4417181118302"></a>-F d</p>
</td>
</tr>
</tbody>

其他参数说明请参见《工具参考》中“服务端工具 \> gs\_dump”章节。

示例

示例一:执行gs_dump,导出hr模式全量信息,并对导出文件进行压缩,导出文件格式为文本格式。

gs_dump -f /home/omm/backup/MPPDB_schema_backup.sql -p 8000 human_resource -n hr -Z 6 -F p
Password:
gs_dump[port='8000'][human_resource][2017-07-21 16:05:55]: dump database human_resource successfully
gs_dump[port='8000'][human_resource][2017-07-21 16:05:55]: total time: 2425  ms

示例二:执行gs_dump,仅导出hr模式的数据,导出文件格式为tar归档格式。

gs_dump -f /home/omm/backup/MPPDB_schema_data_backup.tar -p 8000 human_resource -n hr -a -F t
Password:
gs_dump[port='8000'][human_resource][2018-11-14 15:07:16]: dump database human_resource successfully
gs_dump[port='8000'][human_resource][2018-11-14 15:07:16]: total time: 1865  ms

示例三:执行gs_dump,仅导出hr模式的定义,导出文件格式为目录归档格式。

gs_dump -f /home/omm/backup/MPPDB_schema_def_backup -p 8000 human_resource -n hr -s -F d
Password:
gs_dump[port='8000'][human_resource][2018-11-14 15:11:34]: dump database human_resource successfully
gs_dump[port='8000'][human_resource][2018-11-14 15:11:34]: total time: 1652  ms

示例四:执行gs_dump,导出human_resource数据库时,排除hr模式,导出文件格式为自定义归档格式。

gs_dump -f /home/omm/backup/MPPDB_schema_backup.dmp -p 8000 human_resource -N hr -F c
Password:
gs_dump[port='8000'][human_resource][2017-07-21 16:06:31]: dump database human_resource successfully
gs_dump[port='8000'][human_resource][2017-07-21 16:06:31]: total time: 2522  ms

示例五:执行gs_dump,同时导出hr和public模式,且仅导出模式定义,并对导出文件进行加密,导出文件格式为tar归档格式。

gs_dump -f /home/omm/backup/MPPDB_schema_backup1.tar -p 8000 human_resource -n hr -n public -s --with-encryption AES128 --with-key 1234567812345678 -F t
Password:
gs_dump[port='8000'][human_resource][2017-07-21 16:07:16]: dump database human_resource successfully
gs_dump[port='8000'][human_resource][2017-07-21 16:07:16]: total time: 2132  ms

示例六:执行gs_dump,导出human_resource数据库时,排除hr和public模式,导出文件格式为自定义归档格式。

gs_dump -f /home/omm/backup/MPPDB_schema_backup2.dmp -p 8000 human_resource -N hr -N public -F c
Password:
gs_dump[port='8000'][human_resource][2017-07-21 16:07:55]: dump database human_resource successfully
gs_dump[port='8000'][human_resource][2017-07-21 16:07:55]: total time: 2296  ms

示例七:执行gs_dump,导出public模式下所有表(视图、序列和外表)和hr模式中staffs表,包含数据和表定义,导出文件格式为自定义归档格式。

gs_dump -f /home/omm/backup/MPPDB_backup3.dmp -p 8000 human_resource -t public.* -t hr.staffs -F c
Password:
gs_dump[port='8000'][human_resource][2018-12-13 09:40:24]: dump database human_resource successfully
gs_dump[port='8000'][human_resource][2018-12-13 09:40:24]: total time: 896  ms

本文档遵循知识共享许可协议CC 4.0 (http://creativecommons.org/Licenses/by/4.0/)。