云服务器内容精选

  • 示例 示例一:执行gs_restore,导入指定MPPDB_backup.dmp文件(自定义归档格式)中postgres数据库的数据和对象定义。 1 2 3 gs_restore -W password backup/MPPDB_backup.dmp -p 8000 -h 10.10.10.100 -d backupdb gs_restore[2017-07-21 19:16:26]: restore operation successfu gs_restore: total time: 13053 ms 示例二:执行gs_restore,导入指定MPPDB_backup.tar文件(tar归档格式)中postgres数据库的数据和对象定义。 1 2 3 gs_restore backup/MPPDB_backup.tar -p 8000 -h 10.10.10.100 -d backupdb gs_restore[2017-07-21 19:21:32]: restore operation successful gs_restore[2017-07-21 19:21:32]: total time: 21203 ms 示例三:执行gs_restore,导入指定MPPDB_backup目录文件(目录归档格式)中postgres数据库的数据和对象定义。 1 2 3 gs_restore backup/MPPDB_backup -p 8000 -h 10.10.10.100 -d backupdb gs_restore[2017-07-21 19:26:46]: restore operation successful gs_restore[2017-07-21 19:26:46]: total time: 21003 ms 示例四:执行gs_restore,将postgres数据库的所有对象的定义导入至backupdb数据库。导入前,postgres存在完整的定义和数据,导入后,backupdb数据库只存在所有对象定义,表没有数据。 1 2 3 gs_restore -W password /home//backup/MPPDB_backup.tar -p 8000 -h 10.10.10.100 -d backupdb -s -e -c gs_restore[2017-07-21 19:46:27]: restore operation successful gs_restore[2017-07-21 19:46:27]: total time: 32993 ms 示例五:执行gs_restore,导入MPPDB_backup.dmp文件中PUBLIC模式的所有定义和数据。在导入时会先删除已经存在的对象,如果原对象存在跨模式的依赖则需手工强制干预。 1 2 3 4 5 6 7 gs_restore backup/MPPDB_backup.dmp -p 8000 -h 10.10.10.100 -d backupdb -e -c -n PUBLIC gs_restore: [archiver (db)] Error while PROCESSING TOC: gs_restore: [archiver (db)] Error from TOC entry 313; 1259 337399 TABLE table1 gaussdba gs_restore: [archiver (db)] could not execute query: ERROR: cannot drop table table1 because other objects depend on it DETAIL: view t1.v1 depends on table table1 HINT: Use DROP ... CASCADE to drop the dependent objects too. Command was: DROP TABLE public.table1; 手工删除依赖,导入完成后再重新创建。 1 2 3 gs_restore backup/MPPDB_backup.dmp -p 8000 -h 10.10.10.100 -d backupdb -e -c -n PUBLIC gs_restore[2017-07-21 19:52:26]: restore operation successful gs_restore[2017-07-21 19:52:26]: total time: 2203 ms 示例六:执行gs_restore,导入MPPDB_backup.dmp文件中PUBLIC模式下表hr.staffs的定义。在导入之前,hr.staffs表不存在。 1 2 3 gs_restore backup/MPPDB_backup.dmp -p 8000 -h 10.10.10.100 -d backupdb -e -c -s -n PUBLIC -t hr.staffs gs_restore[2017-07-21 19:56:29]: restore operation successful gs_restore[2017-07-21 19:56:29]: total time: 21000 ms 示例七:执行gs_restore,导入MPPDB_backup.dmp文件中PUBLIC模式下表hr.staffs的数据。在导入之前,hr.staffs表不存在数据。 1 2 3 gs_restore backup/MPPDB_backup.dmp -p 8000 -h 10.10.10.100 -d backupdb -e -a -n PUBLIC -t hr.staffs gs_restore[2017-07-21 20:12:32]: restore operation successful gs_restore[2017-07-21 20:12:32]: total time: 20203 ms 示例八:执行gs_restore,导入指定表hr.staffs的定义。在导入之前,hr.staffs表的数据是存在的。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 human_resource=# select * from hr.staffs; staff_id | first_name | last_name | email | phone_number | hire_date | employment_id | salary | commission_pct | manager_id | section_id ----------+-------------+-------------+----------+--------------------+---------------------+---------------+----------+----------------+------------+------------ 200 | Jennifer | Whalen | JWHALEN | 515.123.4444 | 1987-09-17 00:00:00 | AD_ASST | 4400.00 | | 101 | 10 201 | Michael | Hartstein | MHARTSTE | 515.123.5555 | 1996-02-17 00:00:00 | MK_MAN | 13000.00 | | 100 | 20 gsql -d human_resource -p 8000 gsql ((GaussDB 8.1.3 build 39137c2d) compiled at 2022-04-01 15:43:11 commit 3629 last mr 5138 release) Non-SSL connection (SSL connection is recommended when requiring high-security) Type "help" for help. human_resource=# drop table hr.staffs CASCADE; NOTICE: drop cascades to view hr.staff_details_view gs_restore -W password /home//backup/MPPDB_backup.tar -p 8000 -h 10.10.10.100-d human_resource -n hr -t staffs -s -e restore operation successful total time: 904 ms human_resource=# select * from hr.staffs; staff_id | first_name | last_name | email | phone_number | hire_date | employment_id | salary | commission_pct | manager_id | section_id ----------+------------+-----------+-------+--------------+-----------+---------------+--------+----------------+------------+------------ (0 rows) 示例九:执行gs_restore,导入staffs和areas两个指定表的定义和数据。在导入之前,staffs和areas表不存在。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 human_resource=# \d List of relations Schema | Name | Type | Owner | Storage --------+--------------------+-------+----------+---------------------------------- hr | employment_history | table | | {orientation=row,compression=no} hr | employments | table | | {orientation=row,compression=no} hr | places | table | | {orientation=row,compression=no} hr | sections | table | | {orientation=row,compression=no} hr | states | table | | {orientation=row,compression=no} (5 rows) gs_restore -W password /home/mppdb/backup/MPPDB_backup.tar -p 8000 -h 10.10.10.100 -d human_resource -n hr -t staffs -n hr -t areas restore operation successful total time: 724 ms human_resource=# \d List of relations Schema | Name | Type | Owner | Storage --------+--------------------+-------+----------+---------------------------------- hr | areas | table | | {orientation=row,compression=no} hr | employment_history | table | | {orientation=row,compression=no} hr | employments | table | | {orientation=row,compression=no} hr | places | table | | {orientation=row,compression=no} hr | sections | table | | {orientation=row,compression=no} hr | staffs | table | | {orientation=row,compression=no} hr | states | table | | {orientation=row,compression=no} (7 rows) human_resource=# select * from hr.areas; area_id | area_name ---------+------------------------ 4 | Iron 1 | Wood 2 | Lake 3 | Desert (4 rows) 示例十:执行gs_restore,导入hr的模式,包含模式下的所有对象定义和数据。 1 2 3 gs_restore -W password /home//backup/MPPDB_backup1.sql -p 8000 -h 10.10.10.100 -d backupdb -n hr -e -c restore operation successful total time: 702 ms 示例十一:执行gs_restore,同时导入hr和hr1两个模式,仅导入模式下的所有对象定义。 1 2 3 gs_restore -W password /home//backup/MPPDB_backup2.dmp -p 8000 -h 10.10.10.100 -d backupdb -n hr -n hr1 -s restore operation successful total time: 665 ms 示例十二:执行gs_restore,将human_resource数据库导出文件进行解密并导入至backupdb数据库中。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 create database backupdb; gs_restore /home//backup/MPPDB_backup.tar -p 8000 -h 10.10.10.100 -d backupdb --with-key=1234567812345678 restore operation successful total time: 23472 ms gsql -d backupdb -p 8000 -r gsql ((GaussDB 8.1.3 build 39137c2d) compiled at 2022-04-01 15:43:11 commit 3629 last mr 5138 release) Non-SSL connection (SSL connection is recommended when requiring high-security) Type "help" for help. backupdb=# select * from hr.areas; area_id | area_name ---------+------------------------ 4 | Iron 1 | Wood 2 | Lake 3 | Desert (4 rows) 示例十三:用户user1不具备将导出文件中数据导入至数据库backupdb的权限,而角色role1具备该权限,要实现将文件数据导入数据库backupdb,可以在导出命令中设置--role角色为role1,使用role1的权限,完成导出目的。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 human_resource=# CREATE USER user1 IDENTIFIED BY 'password'; gs_restore -U user1 -W password /home//backup/MPPDB_backup.tar -p 8000 -h 10.10.10.100 -d backupdb --role role1 --rolepassword password restore operation successful total time: 554 ms gsql -d backupdb -p 8000 -r gsql ((GaussDB 8.1.3 build 39137c2d) compiled at 2022-04-01 15:43:11 commit 3629 last mr 5138 release) Non-SSL connection (SSL connection is recommended when requiring high-security) Type "help" for help. backupdb=# select * from hr.areas; area_id | area_name ---------+------------------------ 4 | Iron 1 | Wood 2 | Lake 3 | Desert (4 rows)
  • 操作场景 gs_restore是GaussDB(DWS)提供的与gs_dump配套的导入工具。通过该工具,可将gs_dump导出的文件导入至数据库。gs_restore支持导入的文件格式包含自定义归档格式、目录归档格式和tar归档格式。 gs_restore具备如下两种功能。 导入至数据库 如果指定了数据库,则数据将被导入到指定的数据库中。其中,并行导入必须指定连接数据库的密码。 导入至脚本文件 如果未指定导入数据库,则创建包含重建数据库所需的SQL语句脚本,并将其写入至文件或者标准输出。该脚本文件等效于gs_dump导出的纯文本格式文件。 gs_restore工具在导入时,允许用户选择需要导入的内容,并支持在数据导入前对等待导入的内容进行排序。
  • 示例 示例一:执行gs_restore,导入指定MPPDB_backup.dmp文件(自定义归档格式)中postgres数据库的数据和对象定义。 gs_restore -W Passwd@123 backup/MPPDB_backup.dmp -p 8000 -h 10.10.10.100 -d backupdb gs_restore[2017-07-21 19:16:26]: restore operation successfu gs_restore: total time: 13053 ms 示例二:执行gs_restore,导入指定MPPDB_backup.tar文件(tar归档格式)中postgres数据库的数据和对象定义。 gs_restore backup/MPPDB_backup.tar -p 8000 -h 10.10.10.100 -d backupdb gs_restore[2017-07-21 19:21:32]: restore operation successful gs_restore[2017-07-21 19:21:32]: total time: 21203 ms 示例三:执行gs_restore,导入指定MPPDB_backup目录文件(目录归档格式)中postgres数据库的数据和对象定义。 gs_restore backup/MPPDB_backup -p 8000 -h 10.10.10.100 -d backupdb gs_restore[2017-07-21 19:26:46]: restore operation successful gs_restore[2017-07-21 19:26:46]: total time: 21003 ms 示例四:执行gs_restore,将postgres数据库的所有对象的定义导入至backupdb数据库。导入前,postgres存在完整的定义和数据,导入后,backupdb数据库只存在所有对象定义,表没有数据。 gs_restore -W Passwd@123 /home//backup/MPPDB_backup.tar -p 8000 -h 10.10.10.100 -d backupdb -s -e -c gs_restore[2017-07-21 19:46:27]: restore operation successful gs_restore[2017-07-21 19:46:27]: total time: 32993 ms 示例五:执行gs_restore,导入MPPDB_backup.dmp文件中PUBLIC模式的所有定义和数据。在导入时会先删除已经存在的对象,如果原对象存在跨模式的依赖则需手工强制干预。 gs_restore backup/MPPDB_backup.dmp -p 8000 -h 10.10.10.100 -d backupdb -e -c -n PUBLIC gs_restore: [archiver (db)] Error while PROCESSING TOC: gs_restore: [archiver (db)] Error from TOC entry 313; 1259 337399 TABLE table1 gaussdba gs_restore: [archiver (db)] could not execute query: ERROR: cannot drop table table1 because other objects depend on it DETAIL: view t1.v1 depends on table table1 HINT: Use DROP ... CASCADE to drop the dependent objects too. Command was: DROP TABLE public.table1; 手工删除依赖,导入完成后再重新创建。 gs_restore backup/MPPDB_backup.dmp -p 8000 -h 10.10.10.100 -d backupdb -e -c -n PUBLIC gs_restore[2017-07-21 19:52:26]: restore operation successful gs_restore[2017-07-21 19:52:26]: total time: 2203 ms 示例六:执行gs_restore,导入MPPDB_backup.dmp文件中PUBLIC模式下表hr.staffs的定义。在导入之前,hr.staffs表不存在。 gs_restore backup/MPPDB_backup.dmp -p 8000 -h 10.10.10.100 -d backupdb -e -c -s -n PUBLIC -t hr.staffs gs_restore[2017-07-21 19:56:29]: restore operation successful gs_restore[2017-07-21 19:56:29]: total time: 21000 ms 示例七:执行gs_restore,导入MPPDB_backup.dmp文件中PUBLIC模式下表hr.staffs的数据。在导入之前,hr.staffs表不存在数据。 gs_restore backup/MPPDB_backup.dmp -p 8000 -h 10.10.10.100 -d backupdb -e -a -n PUBLIC -t hr.staffs gs_restore[2017-07-21 20:12:32]: restore operation successful gs_restore[2017-07-21 20:12:32]: total time: 20203 ms 示例八:执行gs_restore,导入指定表hr.staffs的定义。在导入之前,hr.staffs表的数据是存在的。 human_resource=# select * from hr.staffs; staff_id | first_name | last_name | email | phone_number | hire_date | employment_id | salary | commission_pct | manager_id | section_id ----------+-------------+-------------+----------+--------------------+---------------------+---------------+----------+----------------+------------+------------ 200 | Jennifer | Whalen | JWHALEN | 515.123.4444 | 1987-09-17 00:00:00 | AD_ASST | 4400.00 | | 101 | 10 201 | Michael | Hartstein | MHARTSTE | 515.123.5555 | 1996-02-17 00:00:00 | MK_MAN | 13000.00 | | 100 | 20 gsql -d human_resource -p 8000 gsql ((GaussDB 8.2.0 build 39137c2d) compiled at 2022-09-23 15:43:11 commit 3629 last mr 5138 release) Non-SSL connection (SSL connection is recommended when requiring high-security) Type "help" for help. human_resource=# drop table hr.staffs CASCADE; NOTICE: drop cascades to view hr.staff_details_view gs_restore -W Passwd@123 /home//backup/MPPDB_backup.tar -p 8000 -h 10.10.10.100-d human_resource -n hr -t staffs -s -e restore operation successful total time: 904 ms human_resource=# select * from hr.staffs; staff_id | first_name | last_name | email | phone_number | hire_date | employment_id | salary | commission_pct | manager_id | section_id ----------+------------+-----------+-------+--------------+-----------+---------------+--------+----------------+------------+------------ (0 rows) 示例九:执行gs_restore,导入staffs和areas两个指定表的定义和数据。在导入之前,staffs和areas表不存在。 human_resource=# \d List of relations Schema | Name | Type | Owner | Storage --------+--------------------+-------+----------+---------------------------------- hr | employment_history | table | | {orientation=row,compression=no} hr | employments | table | | {orientation=row,compression=no} hr | places | table | | {orientation=row,compression=no} hr | sections | table | | {orientation=row,compression=no} hr | states | table | | {orientation=row,compression=no} (5 rows) gs_restore -W Passwd@123 /home/mppdb/backup/MPPDB_backup.tar -p 8000 -h 10.10.10.100 -d human_resource -n hr -t staffs -n hr -t areas restore operation successful total time: 724 ms human_resource=# \d List of relations Schema | Name | Type | Owner | Storage --------+--------------------+-------+----------+---------------------------------- hr | areas | table | | {orientation=row,compression=no} hr | employment_history | table | | {orientation=row,compression=no} hr | employments | table | | {orientation=row,compression=no} hr | places | table | | {orientation=row,compression=no} hr | sections | table | | {orientation=row,compression=no} hr | staffs | table | | {orientation=row,compression=no} hr | states | table | | {orientation=row,compression=no} (7 rows) human_resource=# select * from hr.areas; area_id | area_name ---------+------------------------ 4 | Iron 1 | Wood 2 | Lake 3 | Desert (4 rows) 示例十:执行gs_restore,导入hr的模式,包含模式下的所有对象定义和数据。 gs_restore -W Passwd@123 /home//backup/MPPDB_backup1.sql -p 8000 -h 10.10.10.100 -d backupdb -n hr -e -c restore operation successful total time: 702 ms 示例十一:执行gs_restore,同时导入hr和hr1两个模式,仅导入模式下的所有对象定义。 gs_restore -W Passwd@123 /home//backup/MPPDB_backup2.dmp -p 8000 -h 10.10.10.100 -d backupdb -n hr -n hr1 -s restore operation successful total time: 665 ms 示例十二:执行gs_restore,将human_resource数据库导出文件进行解密并导入至backupdb数据库中。 create database backupdb; gs_restore /home//backup/MPPDB_backup.tar -p 8000 -h 10.10.10.100 -d backupdb --with-key=1234567812345678 restore operation successful total time: 23472 ms gsql -d backupdb -p 8000 -r gsql ((GaussDB 8.2.0 build 39137c2d) compiled at 2022-09-23 15:43:11 commit 3629 last mr 5138 release) Non-SSL connection (SSL connection is recommended when requiring high-security) Type "help" for help. backupdb=# select * from hr.areas; area_id | area_name ---------+------------------------ 4 | Iron 1 | Wood 2 | Lake 3 | Desert (4 rows) 示例十三:用户user1不具备将导出文件中数据导入至数据库backupdb的权限,而角色role1具备该权限,要实现将文件数据导入数据库backupdb,可以在导出命令中设置--role角色为role1,使用role1的权限,完成导出目的。 human_resource=# CREATE USER user1 IDENTIFIED BY 'password'; gs_restore -U user1 -W 1234@abc /home//backup/MPPDB_backup.tar -p 8000 -h 10.10.10.100 -d backupdb --role role1 --rolepassword password restore operation successful total time: 554 ms gsql -d backupdb -p 8000 -r gsql ((GaussDB 8.2.0 build 39137c2d) compiled at 2022-09-23 15:43:11 commit 3629 last mr 5138 release) Non-SSL connection (SSL connection is recommended when requiring high-security) Type "help" for help. backupdb=# select * from hr.areas; area_id | area_name ---------+------------------------ 4 | Iron 1 | Wood 2 | Lake 3 | Desert (4 rows)
  • 操作场景 gs_restore是GaussDB(DWS)提供的与gs_dump配套的导入工具。通过该工具,可将gs_dump导出的文件导入至数据库。gs_restore支持导入的文件格式包含自定义归档格式、目录归档格式和tar归档格式。 gs_restore具备如下两种功能。 导入至数据库 如果指定了数据库,则数据将被导入到指定的数据库中。其中,并行导入必须指定连接数据库的密码。 导入至脚本文件 如果未指定导入数据库,则创建包含重建数据库所需的SQL语句脚本,并将其写入至文件或者标准输出。该脚本文件等效于gs_dump导出的纯文本格式文件。 gs_restore工具在导入时,允许用户选择需要导入的内容,并支持在数据导入前对等待导入的内容进行排序。
  • 请求示例 创建元数据迁移任务。 POST https://{endpoint}/v2/{project_id}/instances/{instance_id}/metadata { "rabbit_version" : "3.8.35", "rabbitmq_version" : "3.8.35", "product_name" : "RabbitMQ", "product_version" : "3.8.35", "users" : [ { "name" : "root", "password_hash" : "password_hash", "hashing_algorithm" : "rabbit_password_hashing_sha256", "tags" : "administrator", "limits" : { } } ], "vhosts" : [ { "name" : "DeleteVhost123" } ], "permissions" : [ { "name" : "root", "vhost" : "DeleteVhost123", "configure" : ".*", "write" : ".*", "read" : ".*" } ], "topic_permissions" : [ ], "parameters" : [ ], "global_parameters" : [ { "name" : "internal_cluster_id", "value" : "rabbitmq-cluster-id-123" } ], "policies" : [ ], "queues" : [ { "name" : "test-001", "vhost" : "/", "durable" : false, "auto_delete" : false, "arguments" : { } } ], "exchanges" : [ { "name" : "direct", "vhost" : "/", "durable" : false, "auto_delete" : false, "internal" : false, "arguments" : { } } ], "bindings" : [ { "source" : "direct", "vhost" : "/", "destination" : "test-001", "destination_type" : "queue", "routing_key" : "test-001", "arguments" : { } } ] }
  • URI POST /v2/{project_id}/instances/{instance_id}/metadata 表1 路径参数 参数 是否必选 参数类型 描述 project_id 是 String 项目ID,获取方式请参见获取项目ID。 instance_id 是 String 实例ID。 表2 Query参数 参数 是否必选 参数类型 描述 overwrite 是 String true开启同名覆盖,会对已有的同名元数据的配置进行修改,false时当topic或group已存在则会报错。 name 是 String 迁移任务名称,名称规则参考创建实例 type 是 String 迁移任务类型,分为自建RocketMQ上云(rocketmq)、自建RabbitMQ上云(rabbitToRocket)
  • 示例 示例一:执行gs_restore,导入指定MPPDB_backup.dmp文件(自定义归档格式)中gaussdb数据库的数据和对象定义。 gs_restore -W password backup/MPPDB_backup.dmp -p 8000 -h 10.10.10.100 -d backupdbgs_restore[2017-07-21 19:16:26]: restore operation successfugs_restore: total time: 13053 ms 示例二:执行gs_restore,导入指定MPPDB_backup.tar文件(tar归档格式)中gaussdb数据库的数据和对象定义。 gs_restore backup/MPPDB_backup.tar -p 8000 -h 10.10.10.100 -d backupdb gs_restore[2017-07-21 19:21:32]: restore operation successfulgs_restore[2017-07-21 19:21:32]: total time: 21203 ms 示例三:执行gs_restore,导入指定MPPDB_backup目录文件(目录归档格式)中gaussdb数据库的数据和对象定义。 gs_restore backup/MPPDB_backup -p 8000 -h 10.10.10.100 -d backupdbgs_restore[2017-07-21 19:26:46]: restore operation successfulgs_restore[2017-07-21 19:26:46]: total time: 21003 ms 示例四:执行gs_restore,将gaussdb数据库的所有对象的定义导入至backupdb数据库。导入前,gaussdb存在完整的定义和数据,导入后,backupdb数据库只存在所有对象定义,表没有数据。 gs_restore -W password /home//backup/MPPDB_backup.tar -p 8000 -h 10.10.10.100 -d backupdb -s -e -c gs_restore[2017-07-21 19:46:27]: restore operation successfulgs_restore[2017-07-21 19:46:27]: total time: 32993 ms 示例五:执行gs_restore,导入MPPDB_backup.dmp文件中PUBLIC模式的所有定义和数据。在导入时会先删除已经存在的对象,如果原对象存在跨模式的依赖则需手工强制干预。 gs_restore backup/MPPDB_backup.dmp -p 8000 -h 10.10.10.100 -d backupdb -e -c -n PUBLICgs_restore: [archiver (db)] Error while PROCESSING TOC:gs_restore: [archiver (db)] Error from TOC entry 313; 1259 337399 TABLE table1 gaussdbags_restore: [archiver (db)] could not execute query: ERROR: cannot drop table table1 because other objects depend on itDETAIL: view t1.v1 depends on table table1HINT: Use DROP ... CASCADE to drop the dependent objects too.Command was: DROP TABLE public.table1; 手工删除依赖,导入完成后再重新创建。 gs_restore backup/MPPDB_backup.dmp -p 8000 -h 10.10.10.100 -d backupdb -e -c -n PUBLICgs_restore[2017-07-21 19:52:26]: restore operation successfulgs_restore[2017-07-21 19:52:26]: total time: 2203 ms 示例六:执行gs_restore,导入MPPDB_backup.dmp文件中PUBLIC模式下表hr.staffs的定义。在导入之前,hr.staffs表不存在。 gs_restore backup/MPPDB_backup.dmp -p 8000 -h 10.10.10.100 -d backupdb -e -c -s -n PUBLIC -t hr.staffsgs_restore[2017-07-21 19:56:29]: restore operation successfulgs_restore[2017-07-21 19:56:29]: total time: 21000 ms 示例七:执行gs_restore,导入MPPDB_backup.dmp文件中PUBLIC模式下表hr.staffs的数据。在导入之前,hr.staffs表不存在数据。 gs_restore backup/MPPDB_backup.dmp -p 8000 -h 10.10.10.100 -d backupdb -e -a -n PUBLIC -t hr.staffsgs_restore[2017-07-21 20:12:32]: restore operation successfulgs_restore[2017-07-21 20:12:32]: total time: 20203 ms 示例八:执行gs_restore,导入指定表hr.staffs的定义。在导入之前,hr.staffs表的数据是存在的。 human_resource=# select * from hr.staffs; staff_id | first_name | last_name | email | phone_number | hire_date | employment_id | salary | commission_pct | manager_id | section_id ----------+-------------+-------------+----------+--------------------+---------------------+---------------+----------+----------------+------------+------------ 200 | Jennifer | Whalen | JWHALEN | 515.123.4444 | 1987-09-17 00:00:00 | AD_ASST | 4400.00 | | 101 | 10 201 | Michael | Hartstein | MHARTSTE | 515.123.5555 | 1996-02-17 00:00:00 | MK_MAN | 13000.00 | | 100 | 20gsql -d human_resource -p 8000gsql ((GaussDB 8.1.1 build af002019) compiled at 2020-01-10 05:43:20 commit 6995 last mr 11566 )Non-SSL connection (SSL connection is recommended when requiring high-security)Type "help" for help.human_resource=# drop table hr.staffs CASCADE;NOTICE: drop cascades to view hr.staff_details_viewDROP TABLEgs_restore -W password /home//backup/MPPDB_backup.tar -p 8000 -h 10.10.10.100 -d human_resource -n hr -t staffs -s -e restore operation successfultotal time: 904 mshuman_resource=# select * from hr.staffs; staff_id | first_name | last_name | email | phone_number | hire_date | employment_id | salary | commission_pct | manager_id | section_id ----------+------------+-----------+-------+--------------+-----------+---------------+--------+----------------+------------+------------(0 rows) 示例九:执行gs_restore,导入staffs和areas两个指定表的定义和数据。在导入之前,staffs和areas表不存在。 human_resource=# \d List of relations Schema | Name | Type | Owner | Storage --------+--------------------+-------+----------+---------------------------------- hr | employment_history | table | | {orientation=row,compression=no} hr | employments | table | | {orientation=row,compression=no} hr | places | table | | {orientation=row,compression=no} hr | sections | table | | {orientation=row,compression=no} hr | states | table | | {orientation=row,compression=no}(5 rows)gs_restore -W password /home/mppdb/backup/MPPDB_backup.tar -p 8000 -h 10.10.10.100 -d human_resource -n hr -t staffs -n hr -t areas restore operation successfultotal time: 724 mshuman_resource=# \d List of relations Schema | Name | Type | Owner | Storage --------+--------------------+-------+----------+---------------------------------- hr | areas | table | | {orientation=row,compression=no} hr | employment_history | table | | {orientation=row,compression=no} hr | employments | table | | {orientation=row,compression=no} hr | places | table | | {orientation=row,compression=no} hr | sections | table | | {orientation=row,compression=no} hr | staffs | table | | {orientation=row,compression=no} hr | states | table | | {orientation=row,compression=no}(7 rows)human_resource=# select * from hr.areas; area_id | area_name ---------+------------------------ 4 | Iron 1 | Wood 2 | Lake 3 | Desert(4 rows) 示例十:执行gs_restore,导入hr的模式,包含模式下的所有对象定义和数据。 gs_restore -W password /home//backup/MPPDB_backup1.sql -p 8000 -h 10.10.10.100 -d backupdb -n hr -e -crestore operation successfultotal time: 702 ms 示例十一:执行gs_restore,同时导入hr和hr1两个模式,仅导入模式下的所有对象定义。 gs_restore -W password /home//backup/MPPDB_backup2.dmp -p 8000 -h 10.10.10.100 -d backupdb -n hr -n hr1 -srestore operation successfultotal time: 665 ms 示例十二:执行gs_restore,将human_resource数据库导出文件进行解密并导入至backupdb数据库中。 create database backupdb;CREATE DATABASEgs_restore /home//backup/MPPDB_backup.tar -p 8000 -h 10.10.10.100 -d backupdb --with-key=1234567812345678restore operation successfultotal time: 23472 msgsql -d backupdb -p 8000 -rgsql ((GaussDB 8.1.1 build af002019) compiled at 2020-01-10 05:43:20 commit 6995 last mr 11566 )Non-SSL connection (SSL connection is recommended when requiring high-security)Type "help" for help.backupdb=# select * from hr.areas; area_id | area_name ---------+------------------------ 4 | Iron 1 | Wood 2 | Lake 3 | Desert(4 rows) 示例十三:用户user1不具备将导出文件中数据导入至数据库backupdb的权限,而角色role1具备该权限,要实现将文件数据导入数据库backupdb,可以在导出命令中设置--role角色为role1,使用role1的权限,完成导出目的。 human_resource=# CREATE USER user1 IDENTIFIED BY 'password';gs_restore -U user1 -W password /home//backup/MPPDB_backup.tar -p 8000 -h 10.10.10.100 -d backupdb --role role1 --rolepassword passwordrestore operation successfultotal time: 554 msgsql -d backupdb -p 8000 -r gsql ((GaussDB 8.1.1 build af002019) compiled at 2020-01-10 05:43:20 commit 6995 last mr 11566 )Non-SSL connection (SSL connection is recommended when requiring high-security)Type "help" for help.backupdb=# select * from hr.areas; area_id | area_name ---------+------------------------ 4 | Iron 1 | Wood 2 | Lake 3 | Desert(4 rows)
  • 操作场景 gs_restore是GaussDB(DWS)提供的与gs_dump配套的导入工具。通过该工具,可将gs_dump导出的文件导入至数据库。gs_restore支持导入的文件格式包含自定义归档格式、目录归档格式和tar归档格式。 gs_restore具备如下两种功能。 导入至数据库 如果指定了数据库,则数据将被导入到指定的数据库中。其中,并行导入必须指定连接数据库的密码。 导入至脚本文件 如果未指定导入数据库,则创建包含重建数据库所需的SQL语句脚本,并将其写入至文件或者标准输出。该脚本文件等效于gs_dump导出的纯文本格式文件。 gs_restore工具在导入时,允许用户选择需要导入的内容,并支持在数据导入前对等待导入的内容进行排序。