无权限角色导出数据

gs_dump和gs_dumpall通过-U指定执行导出的用户帐户。如果当前使用的帐户不具备导出所要求的权限时,会无法导出数据。此时,可在导出命令中设置--role参数来指定具备权限的角色。在执行命令后,gs_dump和gs_dumpall会使用--role参数指定的角色,完成导出动作。

操作步骤

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

  2. 使用gs_dump导出human_resource数据库数据。

    用户jack不具备导出数据库human_resource的权限,而角色role1具备该权限,要实现导出数据库human_resource,可以在导出命令中设置--role角色为role1,使用role1的权限,完成导出目的。导出文件格式为tar归档格式。

    gs_dump -U jack -f /home/omm/backup/MPPDB_backup.tar -p 8000 human_resource --role role1 --rolepassword  abc@1234 -F t
    Password:
    
    
**表 1**  常用参数说明
    
    <a name="zh-cn_topic_0237121175_table1781122816253"></a>
    <table><thead align="left"><tr id="zh-cn_topic_0237121175_row10837281257"><th class="cellrowborder" valign="top" width="24.169999999999998%" id="mcps1.2.4.1.1"><p id="zh-cn_topic_0237121175_p48382816258"><a name="zh-cn_topic_0237121175_p48382816258"></a><a name="zh-cn_topic_0237121175_p48382816258"></a>参数</p>
    </th>
    <th class="cellrowborder" valign="top" width="44.16%" id="mcps1.2.4.1.2"><p id="zh-cn_topic_0237121175_p18332812257"><a name="zh-cn_topic_0237121175_p18332812257"></a><a name="zh-cn_topic_0237121175_p18332812257"></a>参数说明</p>
    </th>
    <th class="cellrowborder" valign="top" width="31.669999999999998%" id="mcps1.2.4.1.3"><p id="zh-cn_topic_0237121175_p583122816257"><a name="zh-cn_topic_0237121175_p583122816257"></a><a name="zh-cn_topic_0237121175_p583122816257"></a>举例</p>
    </th>
    </tr>
    </thead>
    <tbody><tr id="zh-cn_topic_0237121175_row1483528152520"><td class="cellrowborder" valign="top" width="24.169999999999998%" headers="mcps1.2.4.1.1 "><p id="zh-cn_topic_0237121175_p3830287252"><a name="zh-cn_topic_0237121175_p3830287252"></a><a name="zh-cn_topic_0237121175_p3830287252"></a>-U</p>
    </td>
    <td class="cellrowborder" valign="top" width="44.16%" headers="mcps1.2.4.1.2 "><p id="zh-cn_topic_0237121175_p8232111218592"><a name="zh-cn_topic_0237121175_p8232111218592"></a><a name="zh-cn_topic_0237121175_p8232111218592"></a>连接数据库的用户名。</p>
    </td>
    <td class="cellrowborder" valign="top" width="31.669999999999998%" headers="mcps1.2.4.1.3 "><p id="zh-cn_topic_0237121175_p1583152842510"><a name="zh-cn_topic_0237121175_p1583152842510"></a><a name="zh-cn_topic_0237121175_p1583152842510"></a>-U jack</p>
    </td>
    </tr>
    <tr id="zh-cn_topic_0237121175_row199295855317"><td class="cellrowborder" valign="top" width="24.169999999999998%" headers="mcps1.2.4.1.1 "><p id="zh-cn_topic_0237121175_p89920588539"><a name="zh-cn_topic_0237121175_p89920588539"></a><a name="zh-cn_topic_0237121175_p89920588539"></a>-W</p>
    </td>
    <td class="cellrowborder" valign="top" width="44.16%" headers="mcps1.2.4.1.2 "><p id="zh-cn_topic_0237121175_p69431335210"><a name="zh-cn_topic_0237121175_p69431335210"></a><a name="zh-cn_topic_0237121175_p69431335210"></a>指定用户连接的密码。</p>
    <a name="zh-cn_topic_0237121175_ul194074341627"></a><a name="zh-cn_topic_0237121175_ul194074341627"></a><ul id="zh-cn_topic_0237121175_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_0237121175_p1898043113581"><a name="zh-cn_topic_0237121175_p1898043113581"></a><a name="zh-cn_topic_0237121175_p1898043113581"></a>-W abcd@123</p>
    </td>
    </tr>
    <tr id="zh-cn_topic_0237121175_row1823810139566"><td class="cellrowborder" valign="top" width="24.169999999999998%" headers="mcps1.2.4.1.1 "><p id="zh-cn_topic_0237121175_p11238171316560"><a name="zh-cn_topic_0237121175_p11238171316560"></a><a name="zh-cn_topic_0237121175_p11238171316560"></a>-f</p>
    </td>
    <td class="cellrowborder" valign="top" width="44.16%" headers="mcps1.2.4.1.2 "><p id="zh-cn_topic_0237121175_p323861311565"><a name="zh-cn_topic_0237121175_p323861311565"></a><a name="zh-cn_topic_0237121175_p323861311565"></a>将导出文件发送至指定目录文件夹。如果这里省略,则使用标准输出。</p>
    </td>
    <td class="cellrowborder" valign="top" width="31.669999999999998%" headers="mcps1.2.4.1.3 "><p id="zh-cn_topic_0237121175_p11238513175619"><a name="zh-cn_topic_0237121175_p11238513175619"></a><a name="zh-cn_topic_0237121175_p11238513175619"></a>-f /home/<span id="zh-cn_topic_0237121175_text8898641105316"><a name="zh-cn_topic_0237121175_text8898641105316"></a><a name="zh-cn_topic_0237121175_text8898641105316"></a>omm</span>/backup/MPPDB_backup.tar</p>
    </td>
    </tr>
    <tr id="zh-cn_topic_0237121175_row9411195215519"><td class="cellrowborder" valign="top" width="24.169999999999998%" headers="mcps1.2.4.1.1 "><p id="zh-cn_topic_0237121175_p84119521250"><a name="zh-cn_topic_0237121175_p84119521250"></a><a name="zh-cn_topic_0237121175_p84119521250"></a>-p</p>
    </td>
    <td class="cellrowborder" valign="top" width="44.16%" headers="mcps1.2.4.1.2 "><p id="zh-cn_topic_0237121175_p14838631464"><a name="zh-cn_topic_0237121175_p14838631464"></a><a name="zh-cn_topic_0237121175_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_0237121175_p341117521853"><a name="zh-cn_topic_0237121175_p341117521853"></a><a name="zh-cn_topic_0237121175_p341117521853"></a>-p <span id="zh-cn_topic_0237121175_text7679194345113"><a name="zh-cn_topic_0237121175_text7679194345113"></a><a name="zh-cn_topic_0237121175_text7679194345113"></a>8000</span></p>
    </td>
    </tr>
    <tr id="zh-cn_topic_0237121175_row1362511481379"><td class="cellrowborder" valign="top" width="24.169999999999998%" headers="mcps1.2.4.1.1 "><p id="zh-cn_topic_0237121175_p8782872280"><a name="zh-cn_topic_0237121175_p8782872280"></a><a name="zh-cn_topic_0237121175_p8782872280"></a>dbname</p>
    </td>
    <td class="cellrowborder" valign="top" width="44.16%" headers="mcps1.2.4.1.2 "><p id="zh-cn_topic_0237121175_p1278211752814"><a name="zh-cn_topic_0237121175_p1278211752814"></a><a name="zh-cn_topic_0237121175_p1278211752814"></a>需要导出的数据库名称</p>
    </td>
    <td class="cellrowborder" valign="top" width="31.669999999999998%" headers="mcps1.2.4.1.3 "><p id="zh-cn_topic_0237121175_p12782147122820"><a name="zh-cn_topic_0237121175_p12782147122820"></a><a name="zh-cn_topic_0237121175_p12782147122820"></a>human_resource</p>
    </td>
    </tr>
    <tr id="zh-cn_topic_0237121175_row1280163131716"><td class="cellrowborder" valign="top" width="24.169999999999998%" headers="mcps1.2.4.1.1 "><p id="zh-cn_topic_0237121175_p14801831178"><a name="zh-cn_topic_0237121175_p14801831178"></a><a name="zh-cn_topic_0237121175_p14801831178"></a>--role</p>
    </td>
    <td class="cellrowborder" valign="top" width="44.16%" headers="mcps1.2.4.1.2 "><p id="zh-cn_topic_0237121175_p8618101717583"><a name="zh-cn_topic_0237121175_p8618101717583"></a><a name="zh-cn_topic_0237121175_p8618101717583"></a>指定导出使用的角色名。选择该选项,会使导出工具连接数据库后,发起一个SET ROLE角色名命令。当所授权用户(由-U指定)没有导出工具要求的权限时,该选项会起到作用,即切换到具备相应权限的角色。</p>
    </td>
    <td class="cellrowborder" valign="top" width="31.669999999999998%" headers="mcps1.2.4.1.3 "><p id="zh-cn_topic_0237121175_p66581345155917"><a name="zh-cn_topic_0237121175_p66581345155917"></a><a name="zh-cn_topic_0237121175_p66581345155917"></a>-r role1</p>
    </td>
    </tr>
    <tr id="zh-cn_topic_0237121175_row1899681910160"><td class="cellrowborder" valign="top" width="24.169999999999998%" headers="mcps1.2.4.1.1 "><p id="zh-cn_topic_0237121175_p18625164815715"><a name="zh-cn_topic_0237121175_p18625164815715"></a><a name="zh-cn_topic_0237121175_p18625164815715"></a>--rolepassword</p>
    </td>
    <td class="cellrowborder" valign="top" width="44.16%" headers="mcps1.2.4.1.2 "><p id="zh-cn_topic_0237121175_p1962511481717"><a name="zh-cn_topic_0237121175_p1962511481717"></a><a name="zh-cn_topic_0237121175_p1962511481717"></a>指定具体角色用户的角色密码。</p>
    </td>
    <td class="cellrowborder" valign="top" width="31.669999999999998%" headers="mcps1.2.4.1.3 "><p id="zh-cn_topic_0237121175_p1662514481776"><a name="zh-cn_topic_0237121175_p1662514481776"></a><a name="zh-cn_topic_0237121175_p1662514481776"></a>--rolepassword  abc@1234</p>
    </td>
    </tr>
    <tr id="zh-cn_topic_0237121175_row1885993510341"><td class="cellrowborder" valign="top" width="24.169999999999998%" headers="mcps1.2.4.1.1 "><p id="zh-cn_topic_0237121175_p141711116303"><a name="zh-cn_topic_0237121175_p141711116303"></a><a name="zh-cn_topic_0237121175_p141711116303"></a>-F</p>
    </td>
    <td class="cellrowborder" valign="top" width="44.16%" headers="mcps1.2.4.1.2 "><p id="zh-cn_topic_0237121175_p9417511183018"><a name="zh-cn_topic_0237121175_p9417511183018"></a><a name="zh-cn_topic_0237121175_p9417511183018"></a>选择导出文件格式。-F参数值如下:</p>
    <a name="zh-cn_topic_0237121175_ul4489102813339"></a><a name="zh-cn_topic_0237121175_ul4489102813339"></a><ul id="zh-cn_topic_0237121175_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_0237121175_p4417181118302"><a name="zh-cn_topic_0237121175_p4417181118302"></a><a name="zh-cn_topic_0237121175_p4417181118302"></a>-F t</p>
    </td>
    </tr>
    </tbody>
</table>
    
    
    其他参数说明请参见《工具参考》中“服务端工具 \> gs\_dump”章节或“服务端工具 \> gs\_dumpall”章节。


## 示例<a name="zh-cn_topic_0237121175_zh-cn_topic_0096393674_sed072bab085e4087b15699dfeda9a662"></a>

示例一:执行gs\_dump导出数据,用户jack不具备导出数据库human\_resource的权限,而角色role1具备该权限,要实现导出数据库human\_resource,可以在导出命令中设置--role角色为role1,使用role1的权限,完成导出目的。导出文件格式为tar归档格式。

human_resource=# CREATE USER jack IDENTIFIED BY “1234@abc”; CREATE ROLE

gs_dump -U jack -f /home/omm/backup/MPPDB_backup11.tar -p 8000 human_resource --role role1 --rolepassword abc@1234 -F t Password: gs_dump[port='8000'][human_resource][2017-07-21 16:21:10]: dump database human_resource successfully gs_dump[port='8000'][human_resource][2017-07-21 16:21:10]: total time: 4239 ms


示例二:执行gs\_dump导出数据,用户jack不具备导出模式public的权限,而角色role1具备该权限,要实现导出模式public,可以在导出命令中设置--role角色为role1,使用role1的权限,完成导出目的。导出文件格式为tar归档格式。

human_resource=# CREATE USER jack IDENTIFIED BY “1234@abc”; CREATE ROLE

gs_dump -U jack -f /home/omm/backup/MPPDB_backup12.tar -p 8000 human_resource -n public --role role1 --rolepassword abc@1234 -F t Password: gs_dump[port='8000'][human_resource][2017-07-21 16:21:10]: dump database human_resource successfully gs_dump[port='8000'][human_resource][2017-07-21 16:21:10]: total time: 3278 ms


示例三:执行gs\_dumpall导出数据,用户jack不具备导出所有数据库的权限,而角色role1(管理员)具备该权限,要实现导出所有数据库,可以在导出命令中设置--role角色为role1,使用role1的权限,完成导出目的。导出文件格式为文本归档格式。

human_resource=# CREATE USER jack IDENTIFIED BY “1234@abc”; CREATE ROLE

gs_dumpall -U jack -f /home/omm/backup/MPPDB_backup.sql -p 8000 --role role1 --rolepassword abc@1234 Password: gs_dumpall[port='8000'][human_resource][2018-11-14 17:26:18]: dumpall operation successful gs_dumpall[port='8000'][human_resource][2018-11-14 17:26:18]: total time: 6437 ms

意见反馈
编组 3备份
    openGauss 2024-04-18 00:45:06
    取消