导出模式

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

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

操作步骤

  1. 以操作系统用户omm登录数据库主节点。

  2. 使用gs_dump同时导出hr和public模式。

    1. gs_dump -U jack -f /home/omm/backup/MPPDB_schema_backup -p 8000 human_resource -n hr -n public -F d
    2. Password:
  1. **表 1** 常用参数说明
  2. <a name="zh-cn_topic_0237121170_table1781122816253"></a>
  3. <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>
  4. </th>
  5. <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>
  6. </th>
  7. <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>
  8. </th>
  9. </tr>
  10. </thead>
  11. <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>
  12. </td>
  13. <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>
  14. </td>
  15. <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>
  16. </td>
  17. </tr>
  18. <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>
  19. </td>
  20. <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>
  21. <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>
  22. </td>
  23. <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>
  24. </td>
  25. </tr>
  26. <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>
  27. </td>
  28. <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>
  29. </td>
  30. <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>
  31. </td>
  32. </tr>
  33. <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>
  34. </td>
  35. <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>
  36. </td>
  37. <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>
  38. </td>
  39. </tr>
  40. <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>
  41. </td>
  42. <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>
  43. </td>
  44. <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>
  45. </td>
  46. </tr>
  47. <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>
  48. </td>
  49. <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>
  50. <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>
  51. </td>
  52. <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>
  53. </td>
  54. </tr>
  55. <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>
  56. </td>
  57. <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>
  58. <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>
  59. </td>
  60. <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>
  61. </td>
  62. </tr>
  63. </tbody>
  64. </table>
  65. 其他参数说明请参见《工具参考》中“服务端工具 \> gs\_dump”章节。
  66. ## 示例<a name="zh-cn_topic_0237121170_zh-cn_topic_0096392705_s221cf543e4004d598aa6fafa8b79f843"></a>
  67. 示例一:执行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

  1. 示例二:执行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

  1. 示例三:执行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

  1. 示例四:执行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

  1. 示例五:执行gs\_dump,同时导出hrpublic模式,且仅导出模式定义,并对导出文件进行加密,导出文件格式为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

  1. 示例六:执行gs\_dump,导出human\_resource数据库时,排除hrpublic模式,导出文件格式为自定义归档格式。

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

  1. 示例七:执行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