当前位置:网站首页>Easy to use GS_ Dump and GS_ Dumpall command export data

Easy to use GS_ Dump and GS_ Dumpall command export data

2022-06-11 15:47:00 Gauss squirrel Club

  • summary

  • Export a single database

  • Export all databases

  • No permission role to export data

One 、 summary

openGauss Provided gs_dump and gs_dumpall Tools , It can help users export the required database objects or their related information . Import the exported data information into the required database through the import tool , You can complete the migration of database information .gs_dump Support the export of a single database or its objects , and gs_dumpall Support export openGauss The common global object of all databases or libraries in the . See table for detailed usage scenarios 1.

surface 1  Applicable scenario

Applicable scenario

Supported export granularity

Supported export formats

Supporting import methods

Export a single database

Database level export .

  • Export full information .

    Using the exported full information, you can create the same database as the current library , And the data in the library is the same as the current library .

  • Export only the definitions of all objects in the library , Include library definitions 、 Function definition 、 Pattern definition 、 The table definition 、 Index definition and stored procedure definition .

    Use the exported object definition , You can quickly create the same database , But there is no data from the original database in the database .

  • Export data only .
  • Plain text format
  • Custom archive format
  • Catalog archive format
  • tar Archive format

Mode level export .

  • Export the full information of the mode .
  • Export only data in schema .
  • Export only the definition of the object , Contains table definitions 、 Stored procedure definition and index definition .
Table level export .
  • Export the full information of the table .
  • Export only the data in the table .
  • Export table definitions only .

Export all databases

Database level export .

  • Export full information .

    Using the exported full information, you can create a host environment that is the same as the current host , Have the same database and common global objects , And the data in the library is the same as that in the current libraries .

  • Export only the object definitions in each database , Include tablespaces 、 Library definition 、 Function definition 、 Pattern definition 、 The table definition 、 Index definition and stored procedure definition .

    Use the exported object definition , You can quickly create the same host environment as the current host , Have the same database and tablespace , But there is no data from the original database in the database .

  • Export data only .

Plain text format

For data file import, see Use gsql Meta data import command .

The public global objects of each library are exported .
  • Export only tablespace information .
  • Export only role information .
  • Export roles and tablespaces .

gs_dump and gs_dumpall adopt -U Specify the user account to perform the export . If the currently used account does not have the permissions required for export , You will not be able to export data . here , You can set... In the export command –role To specify the permissions of the role . After executing the command ,gs_dump and gs_dumpall Will use –role The role specified by the parameter , Complete the export action . Please refer to table... For scenarios that can use this function 1, Please refer to No permission role to export data .

gs_dump and gs_dumpall By encrypting the exported data file , Decrypt the encrypted data file when importing , It can prevent the leakage of data information , Provide guarantee for the security of database . Be careful , Use gs_dump Encrypted plain text format file , If the exported database contains stored procedures , Unsupported use gsql Command restore file , Please use the other three modes to export the database , And use gs_restore recovery .

gs_dump and gs_dumpall When the tool is exporting data , Other users can access the database ( Read or write ).

gs_dump and gs_dumpall The tool supports exporting complete and consistent data . for example ,T1 Always start gs_dump export A database , Or start gs_dumpall export openGauss database , Then the result of exporting data will be T1 moment A Database or the openGauss The data status of the database ,T1 Right after the moment A A database or openGauss Database modifications will not be exported .

matters needing attention

  • It is forbidden to modify the exported files and contents , Otherwise, you may not be able to recover successfully .
  • If the number of objects contained in the database ( Data sheet 、 View 、 Indexes ) stay 50 All the above , To improve performance and avoid memory problems , Recommended by gs_guc The tool sets the following parameters of the database node ( If the parameter value is greater than the following recommended value , There is no need to set ).

    gs_guc set -N all -I all -c 'max_prepared_transactions = 1000'
    gs_guc set -N all -I all -c 'max_locks_per_transaction = 512'
    
  • To ensure data consistency and integrity , The export tool will set a shared lock on the table to be dumped . If the lock is set in another transaction table ,gs_dump and gs_dumpall Will wait for the lock to release and lock the table . If a table cannot be locked within the specified time , Dump will fail . Users can specify –lock-wait-timeout Options , Custom wait lock timeout .

  • because gs_dumpall Read all tables in the database , Therefore, we must openGauss Connect as Administrator , To export the complete file . In the use of gsql When executing script file import , You also need administrator privileges , To add users and groups , And creating databases .

Two 、 Export a single database

  • Export database

  • Export mode

  • Export table

① Export database

openGauss Support use gs_dump The tool exports the content of a database level , Contains database data and all object definitions . You can customize and export the following information as needed :

  • Export the full information of the database , Contains data and all object definitions .

    Using the exported full information, you can create the same database as the current library , And the data in the library is the same as the current library .

  • Export only all object definitions , Include : Library definition 、 Function definition 、 Pattern definition 、 The table definition 、 Index definition and stored procedure definition .

    Use the exported object definition , You can quickly create the same database , But there is no data from the original database in the database .

  • Export data only , Does not contain all object definitions .

Operation steps

  1. Operating system users omm Log in to the database master node .
  2. Use gs_dump export userdatabase database .

     Copy code gs_dump -U jack -f /home/omm/backup/userdatabase_backup.tar -p 8000 postgres -F t 
    Password:
    

    surface 1  Description of common parameters

    Parameters

    Parameter description

    give an example

    -U

    User name to connect to the database .

    explain :

    When the user name to connect to the database is not specified , The default is the initial system administrator connection created during installation .

    -U jack

    -W

    Specify the password for the user connection .

    • If the authentication policy of the host is trust, The database administrator will not be password verified , That is, there is no need to enter -W Options ;
    • without -W Options , And not a database administrator , The user will be prompted to enter the password .

    -W [email protected]

    -f

    Send the exported file to the specified directory folder . If you omit , Use standard output .

    -f /home/omm/backup/postgres_backup.tar

    -p

    Specifies the server is listening on TCP Port or local Unix Domain socket suffix , To ensure the connection .

    -p 8000

    dbname

    The name of the database to be exported

    postgres

    -F

    Select the export file format .-F The parameter values are as follows :

    • p: Plain text format
    • c: Custom archive
    • d: Catalog archive format
    • t:tar Archive format

    -F t

    Please refer to... For other parameter descriptions 《 Tool reference 》 in “ Server tools > gs_dump” chapter .

Example

Example 1 : perform gs_dump, export postgres Database full information , The export file format is sql Text format .

gs_dump -f /home/omm/backup/postgres_backup.sql -p 8000 postgres -F p
Password:
gs_dump[port='8000'][postgres][2017-07-21 15:36:13]: dump database postgres successfully
gs_dump[port='8000'][postgres][2017-07-21 15:36:13]: total time: 3793  ms

Example 2 : perform gs_dump, Export only postgres Data in the database , Does not contain database object definitions , The export file format is custom archive format .

gs_dump -f /home/omm/backup/postgres_data_backup.dmp -p 8000 postgres -a -F c
Password:
gs_dump[port='8000'][postgres][2017-07-21 15:36:13]: dump database postgres successfully
gs_dump[port='8000'][postgres][2017-07-21 15:36:13]: total time: 3793  ms

Example 3 : perform gs_dump, Export only postgres Definition of all objects in the database , The export file format is sql Text format .

gs_dump -f /home/omm/backup/postgres_def_backup.sql -p 8000 postgres -s -F p
Password:
gs_dump[port='8000'][postgres][2017-07-20 15:04:14]: dump database postgres successfully
gs_dump[port='8000'][postgres][2017-07-20 15:04:14]: total time: 472 ms

Example 4 : perform gs_dump, Export only postgres Definition of all objects in the database , The export file format is text format , And encrypt the exported file .

gs_dump -f /home/omm/backup/postgres_def_backup.sql -p 8000 postgres --with-encryption AES128 --with-key 1234567812345678 -s -F p
Password:
gs_dump[port='8000'][postgres][2018-11-14 11:25:18]: dump database postgres successfully
gs_dump[port='8000'][postgres][2018-11-14 11:25:18]: total time: 1161  ms

② Export mode

openGauss Currently supports the use of gs_dump Tools export schema level content , Contains the data and definition of the schema . Users can export schema content through flexible customization , It not only supports the export of one or more modes , It also supports the export of excluding one or more modes . You can customize and export the following information as needed :

  • Export the full information of the mode , Contains data and object definitions .
  • Export data only , That is, the schema contains the data in the table , Does not contain object definitions .
  • Export schema object definitions only , Include : The table definition 、 Stored procedure definition and index definition .

Operation steps

  1. Operating system users omm Log in to the database master node .
  2. Use gs_dump Simultaneous export hr and public Pattern .

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

    surface 1  Description of common parameters

    Parameters

    Parameter description

    give an example

    -U

    User name to connect to the database .

    -U jack

    -W

    Specify the password for the user connection .

    • If the authentication policy of the host is trust, The database administrator will not be password verified , That is, there is no need to enter -W Options .
    • without -W Options , And not a database administrator , The user will be prompted to enter the password .

    -W [email protected]

    -f

    Send the exported file to the specified directory folder . If you omit , Use standard output .

    -f /home/omm/backup/MPPDB_schema_backup

    -p

    Specifies the server is listening on TCP Port or local Unix Domain socket suffix , To ensure the connection .

    -p 8000

    dbname

    The name of the database to be exported

    human_resource

    -n

    Export only patterns that match the pattern name , This option includes the schema itself and all the objects it contains .

    • Single mode :-n schemaname
    • Multiple patterns : Enter more than once -n schemaname
    • Single mode :-n hr
    • Multiple patterns :-n hr -n public

    -F

    Select the export file format .-F The parameter values are as follows :

    • p: Plain text format
    • c: Custom archive
    • d: Catalog archive format
    • t:tar Archive format

    -F d

    Please refer to... For other parameter descriptions 《 Tool reference 》 in “ Server tools > gs_dump” chapter .

Example

Example 1 : perform gs_dump, export hr Mode full information , The export file format is text format .

gs_dump -f /home/omm/backup/MPPDB_schema_backup.sql -p 8000 human_resource -n hr -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

Example 2 : perform gs_dump, Export only hr Data for patterns , The export file format is tar Archive format .

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

Example 3 : perform gs_dump, Export only hr Definition of pattern , The export file format is directory archive format .

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

Example 4 : perform gs_dump, export human_resource Database time , exclude hr Pattern , The export file format is custom archive format .

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

Example 5 : perform gs_dump, Simultaneous export hr and public Pattern , And only export schema definitions , The export file format is tar Archive format .

gs_dump -f /home/omm/backup/MPPDB_schema_backup1.tar -p 8000 human_resource -n hr -n public -s -F t
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

Example 6 : perform gs_dump, export human_resource Database time , exclude hr and public Pattern , The export file format is custom archive format .

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

Example 7 : perform gs_dump, export public All tables in mode ( View 、 Sequence and appearance ) and hr In the pattern staffs surface , Contains data and table definitions , The export file format is custom archive format .

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

③ Export table

openGauss Support use gs_dump Tools export table level content , Contains table definitions and table data . View 、 Sequences and appearances belong to special tables . Users can export table contents through flexible customization , It not only supports the export of a selected table or multiple tables , It also supports the export of excluding one or more tables . You can customize and export the following information as needed :

  • Export table full information , Contains table data and table definitions .
  • Export data only , Does not contain table definitions .
  • Export table definitions only .

Operation steps

  1. Operating system users omm Log in to the database master node .
  2. Use gs_dump Export the specified table at the same time hr.staffs and hr.employments.

    gs_dump -U jack -f /home/omm/backup/MPPDB_table_backup -p 8000 human_resource -t hr.staffs -t hr.employments -F d
    Password:
    

    surface 1  Description of common parameters

    Parameters

    Parameter description

    give an example

    -U

    User name to connect to the database .

    -U jack

    -W

    Specify the password for the user connection .

    • If the authentication policy of the host is trust, The database administrator will not be password verified , That is, there is no need to enter -W Options .
    • without -W Options , And not a database administrator , The user will be prompted to enter the password .

    -W [email protected]

    -f

    Send the exported file to the specified directory folder . If you omit , Use standard output .

    -f /home/omm/backup/MPPDB_table_backup

    -p

    Specifies the server is listening on TCP Port or local Unix Domain socket suffix , To ensure the connection .

    -p 8000

    dbname

    The name of the database to be exported .

    human_resource

    -t

    Specify the exported table ( Or view 、 Sequence 、 appearance ), Multiple can be used -t Select multiple options from the table , You can also use wildcards to specify multiple table objects . When multiple table objects are specified using wildcards , Pay attention to pattern Quote , prevent shell Extended wildcard .

    • A single watch :-t schema.table
    • Multiple tables : Enter more than once -t schema.table
    • A single watch :-t hr.staffs
    • Multiple tables :-t hr.staffs -t hr.employments

    -F

    Select the export file format .-F The parameter values are as follows :

    • p: Plain text format
    • c: Custom archive
    • d: Catalog archive format
    • t:tar Archive format

    -F d

    -T

    Tables that are not dumped ( Or view 、 Or sequence 、 Or appearance ) The object list , Multiple can be used -t Select multiple options from the table , You can also use wildcards to specify multiple table objects .

    When entering at the same time -t and -T when , Will dump in -t In the list , Instead of -T Table objects in the list .

    -T table1

Please refer to... For other parameter descriptions 《 Tool reference 》 in “ Server tools > gs_dump” chapter .

Example

Example 1 : perform gs_dump, Export table hr.staffs Definition and data of , The export file format is text format .

gs_dump -f /home/omm/backup/MPPDB_table_backup.sql -p 8000 human_resource -t hr.staffs  -F p
Password:
gs_dump[port='8000'][human_resource][2017-07-21 17:05:10]: dump database human_resource successfully
gs_dump[port='8000'][human_resource][2017-07-21 17:05:10]: total time: 3116  ms

Example 2 : perform gs_dump, Export only tables hr.staffs The data of , The export file format is tar Archive format .

gs_dump -f /home/omm/backup/MPPDB_table_data_backup.tar -p 8000 human_resource -t hr.staffs -a -F t 
Password:
gs_dump[port='8000'][human_resource][2017-07-21 17:04:26]: dump database human_resource successfully
gs_dump[port='8000'][human_resource][2017-07-21 17:04:26]: total time: 2570  ms

Example 3 : perform gs_dump, Export table hr.staffs The definition of , The export file format is directory archive format .

gs_dump -f /home/omm/backup/MPPDB_table_def_backup -p 8000 human_resource -t hr.staffs -s -F d 
Password:
gs_dump[port='8000'][human_resource][2017-07-21 17:03:09]: dump database human_resource successfully
gs_dump[port='8000'][human_resource][2017-07-21 17:03:09]: total time: 2297  ms 

Example 4 : perform gs_dump, Do not export tables hr.staffs, The export file format is custom archive format .

gs_dump -f /home/omm/backup/MPPDB_table_backup4.dmp -p 8000 human_resource -T hr.staffs -F c
Password:
gs_dump[port='8000'][human_resource][2017-07-21 17:14:11]: dump database human_resource successfully
gs_dump[port='8000'][human_resource][2017-07-21 17:14:11]: total time: 2450  ms

Example 5 : perform gs_dump, Export two tables at the same time hr.staffs and hr.employments, The export file format is text format .

gs_dump -f /home/omm/backup/MPPDB_table_backup1.sql -p 8000 human_resource -t hr.staffs -t hr.employments -F p
Password:
gs_dump[port='8000'][human_resource][2017-07-21 17:19:42]: dump database human_resource successfully
gs_dump[port='8000'][human_resource][2017-07-21 17:19:42]: total time: 2414  ms

Example 6 : perform gs_dump, Export time , Exclude two tables hr.staffs and hr.employments, The export file format is text format .

gs_dump -f /home/omm/backup/MPPDB_table_backup2.sql -p 8000 human_resource -T hr.staffs -T hr.employments -F p
Password:
gs_dump[port='8000'][human_resource][2017-07-21 17:21:02]: dump database human_resource successfully
gs_dump[port='8000'][human_resource][2017-07-21 17:21:02]: total time: 3165  ms

Example 7 : perform gs_dump, Export table hr.staffs Definition and data of , Export only tables hr.employments The definition of , The export file format is tar Archive format .

gs_dump -f /home/omm/backup/MPPDB_table_backup3.tar -p 8000 human_resource -t hr.staffs -t hr.employments --exclude-table-data hr.employments -F t
Password:
gs_dump[port='8000'][human_resource][2018-11-14 11:32:02]: dump database human_resource successfully
gs_dump[port='8000'][human_resource][2018-11-14 11:32:02]: total time: 1645  ms

Example 8 : perform gs_dump, Export table hr.staffs Definition and data of , And encrypt the exported file , The export file format is text format .

gs_dump -f /home/omm/backup/MPPDB_table_backup4.sql -p 8000 human_resource -t hr.staffs --with-encryption AES128 --with-key abcdefg_?1234567 -F p
Password:
gs_dump[port='8000'][human_resource][2018-11-14 11:35:30]: dump database human_resource successfully
gs_dump[port='8000'][human_resource][2018-11-14 11:35:30]: total time: 6708  ms

Example 9 : perform gs_dump, export public All tables in mode ( Include views 、 Sequence and appearance ) and hr In the pattern staffs surface , Contains data and table definitions , The export file format is custom archive format .

gs_dump -f /home/omm/backup/MPPDB_table_backup5.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

Example 10 : perform gs_dump, Export only depends on t1 Mode of test1 View information of table object , The export file format is directory archive format .

gs_dump -U jack -f /home/omm/backup/MPPDB_view_backup6 -p 8000 human_resource -t t1.test1 --include-depend-objs --exclude-self -F d
Password:
gs_dump[port='8000'][jack][2018-11-14 17:21:18]: dump database human_resource successfully
gs_dump[port='8000'][jack][2018-11-14 17:21:23]: total time: 4239  ms


3、 ... and 、 Export all databases  

  • Export all databases

  • Export global objects

① Export all databases

openGauss Support use gs_dumpall The tool exports the full information of all databases , contain openGauss Each database information and common global object information in . You can customize and export the following information as needed :

  • Export the full information of all databases , contain openGauss Each database information and common global object information in ( Contains role and tablespace information ).

    Using the exported full information, you can create a host environment that is the same as the current host , Have the same database and common global objects , And the data in the library is the same as that in the current libraries .

  • Export data only , That is, export the data in each database , And does not contain all object definitions and public global object information .

  • Export only all object definitions , Include : Table space 、 Library definition 、 Function definition 、 Pattern definition 、 The table definition 、 Index definition and stored procedure definition .

    Use the exported object definition , You can quickly create the same host environment as the current host , Have the same database and tablespace , But there is no data from the original database in the database .

Operation steps

  1. Operating system users omm Log in to the database master node .
  2. Use gs_dumpall Export all database information at once .

    gs_dumpall  -U omm -f /home/omm/backup/MPPDB_backup.sql -p 8000 
    Password:
    

    surface 1  Description of common parameters

    Parameters

    Parameter description

    give an example

    -U

    User name to connect to the database , Need to be openGauss Administrator user .

    -U omm

    -W

    Specify the password for the user connection .

    • If the authentication policy of the host is trust, The database administrator will not be password verified , That is, there is no need to enter -W Options ;
    • without -W Options , And not a database administrator , The user will be prompted to enter the password .

    -W [email protected]

    -f

    Send the exported file to the specified directory folder . If you omit , Use standard output .

    -f /home/omm/backup/MPPDB_backup.sql

    -p

    Specifies the number of messages that the server listens to TCP Port or local Unix Domain socket suffix , To ensure the connection .

    -p 8000

    Please refer to... For other parameter descriptions 《 Tool reference 》 in “ Server tools > gs_dumpall” chapter .

Example

Example 1 : perform gs_dumpall, Export the full information of all databases (omm The user is an administrator user ), The exported file is in text format . After executing the command , There will be a long print message , In the end total time It means successful execution . The printing information in the middle will not be reflected in the example .

gs_dumpall -U omm -f /home/omm/backup/MPPDB_backup.sql -p 8000 
Password:
gs_dumpall[port='8000'][2017-07-21 15:57:31]: dumpall operation successful
gs_dumpall[port='8000'][2017-07-21 15:57:31]: total time: 9627  ms

Example 2 : perform gs_dumpall, Export only all database definitions (omm The user is an administrator user ), The exported file is in text format . After executing the command , There will be a long print message , In the end total time It means successful execution . The printing information in the middle will not be reflected in the example .

gs_dumpall  -U omm -f /home/omm/backup/MPPDB_backup.sql -p 8000 -s 
Password:
gs_dumpall[port='8000'][2018-11-14 11:28:14]: dumpall operation successful
gs_dumpall[port='8000'][2018-11-14 11:28:14]: total time: 4147  ms

Example 3 : perform gs_dumpall, Export only the data in all databases , And encrypt the exported file , The exported file is in text format . After executing the command , There will be a long print message , In the end total time It means successful execution . The printing information in the middle will not be reflected in the example .

gs_dumpall -f /home/omm/backup/MPPDB_backup.sql -p 8000 -a --with-encryption AES128 --with-key abcdefg_?1234567
gs_dumpall[port='8000'][2018-11-14 11:32:26]: dumpall operation successful
gs_dumpall[port='8000'][2018-11-14 11:23:26]: total time: 4147  ms

② Export global objects

openGauss Support use gs_dumpall The tool exports global objects common to all databases , Contains database users and groups , Tablespaces and attributes ( for example : Applicable to the overall access rights of the database ) Information .

Operation steps

  1. Operating system users omm Log in to the database master node .
  2. Use gs_dumpall Export tablespace object information .

    gs_dumpall -U omm -f /home/omm/backup/MPPDB_tablespace.sql -p 8000 -t
    Password:
    

    surface 1  Description of common parameters

    Parameters

    Parameter description

    give an example

    -U

    User name to connect to the database , Need to be openGauss Administrator user .

    -U omm

    -W

    Specify the password for the user connection .

    • If the authentication policy of the host is trust, The database administrator will not be password verified , That is, there is no need to enter -W Options ;
    • without -W Options , And not a database administrator , The user will be prompted to enter the password .

    -W [email protected]

    -f

    Send the exported file to the specified directory folder . If you omit , Use standard output .

    -f /home/omm/backup/MPPDB_tablespace.sql

    -p

    Specifies the server is listening on TCP Port or local Unix Domain socket suffix , To ensure the connection .

    -p 8000

    -t

    perhaps –tablespaces-only, Dump only tablespaces , Do not dump databases or roles .

    -

    Please refer to... For other parameter descriptions 《 Tool reference 》 in “ Server tools > gs_dumpall” chapter .

Example

Example 1 : perform gs_dumpall, Export the common global tablespace information and user information of all databases (omm The user is an administrator user ), The exported file is in text format .

gs_dumpall -U omm -f /home/omm/backup/MPPDB_globals.sql -p 8000 -g
Password:
gs_dumpall[port='8000'][2018-11-14 19:06:24]: dumpall operation successful
gs_dumpall[port='8000'][2018-11-14 19:06:24]: total time: 1150  ms

Example 2 : perform gs_dumpall, Export the common global tablespace information of all databases (omm The user is an administrator user ), And encrypt the exported file , The exported file is in text format .

gs_dumpall -U omm -f /home/omm/backup/MPPDB_tablespace.sql -p 8000 -t --with-encryption AES128 --with-key abcdefg_?1234567
Password:
gs_dumpall[port='8000'][2018-11-14 19:00:58]: dumpall operation successful
gs_dumpall[port='8000'][2018-11-14 19:00:58]: total time: 186  ms

Example 3 : perform gs_dumpall, Export the common global user information of all databases (omm The user is an administrator user ), The exported file is in text format .

gs_dumpall -U omm -f /home/omm/backup/MPPDB_user.sql -p 8000 -r
Password:
gs_dumpall[port='8000'][2018-11-14 19:03:18]: dumpall operation successful
gs_dumpall[port='8000'][2018-11-14 19:03:18]: total time: 162  ms

Four 、 No permission role to export data

gs_dump and gs_dumpall adopt -U Specify the user account to perform the export . If the currently used account does not have the permissions required for export , You will not be able to export data . here , You need to empower authorized users to unauthorized users , You can then set... In the export command –role To specify the permissions of the role . After executing the command ,gs_dump and gs_dumpall Will use –role The role specified by the parameter , Complete the export action .

Operation steps

  1. Operating system users omm Log in to the database master node .
  2. Use gs_dump export human_resource Database data .

    user jack Do not have the ability to export database human_resource Authority , And the role role1 Have this permission , To export the database human_resource, Need to put role1 Empowering jack, You can then set... In the export command –role The role of role1, Use role1 Authority , Complete the export purpose . The export file format is tar Archive format .

    gs_dump -U jack -f /home/omm/backup/MPPDB_backup.tar -p 8000 human_resource --role role1 --rolepassword  [email protected] -F t
    Password:
    

    surface 1  Description of common parameters

    Parameters

    Parameter description

    give an example

    -U

    User name to connect to the database .

    -U jack

    -W

    Specify the password for the user connection .

    • If the authentication policy of the host is trust, The database administrator will not be password verified , That is, there is no need to enter -W Options .
    • without -W Options , And not a database administrator , The user will be prompted to enter the password .

    -W [email protected]

    -f

    Send the exported file to the specified directory folder . If you omit , Use standard output .

    -f /home/omm/backup/MPPDB_backup.tar

    -p

    Specifies the server is listening on TCP Port or local Unix Domain socket suffix , To ensure the connection .

    -p 8000

    dbname

    The name of the database to be exported

    human_resource

    –role

    Specifies the role name used for the export . Select this option , After the export tool connects to the database , To launch a SET ROLE Role name command . When the authorized user ( from -U Appoint ) When you do not have the permissions required by the export tool , This option will work , That is, switch to the role with corresponding permissions .

    -r role1

    –rolepassword

    Specify the role password of the specific role user .

    –rolepassword [email protected]

    -F

    Select the export file format .-F The parameter values are as follows :

    • p: Plain text format
    • c: Custom archive
    • d: Catalog archive format
    • t:tar Archive format

    -F t

    Please refer to... For other parameter descriptions 《 Tool reference 》 in “ Server tools > gs_dump” Chapter or “ Server tools > gs_dumpall” chapter .

Example

Example 1 : perform gs_dump Derived data , user jack Do not have the ability to export database human_resource Authority , And the role role1 Have this permission , To export the database human_resource, You can set... In the export command –role The role of role1, Use role1 Authority , Complete the export purpose . The export file format is tar Archive format .

human_resource=# CREATE USER jack IDENTIFIED BY "[email protected]";
CREATE ROLE
human_resource=# GRANT role1 TO jack;
GRANT ROLE

gs_dump -U jack -f /home/omm/backup/MPPDB_backup11.tar -p 8000 human_resource --role role1 --rolepassword [email protected] -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

Example 2 : perform gs_dump Derived data , user jack No export mode public Authority , And the role role1 Have this permission , To implement the export mode public, You can set... In the export command –role The role of role1, Use role1 Authority , Complete the export purpose . The export file format is tar Archive format .

human_resource=# CREATE USER jack IDENTIFIED BY "[email protected]";
CREATE ROLE
human_resource=# GRANT role1 TO jack;
GRANT ROLE

gs_dump -U jack -f /home/omm/backup/MPPDB_backup12.tar -p 8000 human_resource -n public --role role1 --rolepassword [email protected] -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

Example 3 : perform gs_dumpall Derived data , user jack Do not have permission to export all databases , And the role role1( Administrators ) Have this permission , To export all databases , You can set... In the export command –role The role of role1, Use role1 Authority , Complete the export purpose . The export file format is text archive format .

human_resource=# CREATE USER jack IDENTIFIED BY "[email protected]";
CREATE ROLE
human_resource=# GRANT role1 TO jack;
GRANT ROLE

gs_dumpall -U jack -f /home/omm/backup/MPPDB_backup.sql -p 8000 --role role1 --rolepassword [email protected]
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

That's all for sharing in this section , Thank you for reading . 

原网站

版权声明
本文为[Gauss squirrel Club]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/162/202206111535104279.html