暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

openGauss 逻辑备份和恢复案例2

suger 2023-01-26
219

逻辑备份和恢复案例2:使用dump格式进行备份和恢复omm数据库
--逻辑备份:使用gs_dump备份数据库,生成归档格式的备份文件
--创建测试数据
omm@modb:~$ gsql -r
gsql ((openGauss 3.0.0 build 02c14696) compiled at 2022-04-01 18:12:00 commit 0 last mr )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.

omm=# create table test3(col int);
CREATE TABLE
omm=# create table test4(col int);
CREATE TABLE
omm=# \q

--使用test用户,备份omm数据库,生成归档格式的备份文件:
omm@modb:~$ gs_dump -U test omm -F p -f /var/lib/opengauss/backup/backup.dump
Password:
gs_dump[port='5432'][omm][2022-12-13 10:11:08]: The total objects number is 417.
gs_dump[port='5432'][omm][2022-12-13 10:11:08]: [100.00%] 417 objects have been dumped.
gs_dump[port='5432'][omm][2022-12-13 10:11:08]: dump database omm successfully
gs_dump[port='5432'][omm][2022-12-13 10:11:08]: total time: 4218 ms

--使用gs_dump生成的归档文件恢复数据库
omm@modb:~$ gsql -d testdb -U test -f /var/lib/opengauss/backup/backup.dump
Password for user test:
SET
SET
SET
SET
SET
SET
gsql:/var/lib/opengauss/backup/backup.dump:16: ERROR: schema "test" already exists
ALTER SCHEMA
SET
SET
SET
gsql:/var/lib/opengauss/backup/backup.dump:34: ERROR: relation "test1" already exists in schema "public"
DETAIL: creating new table with existing name in the same schema
ALTER TABLE
gsql:/var/lib/opengauss/backup/backup.dump:46: ERROR: relation "test2" already exists in schema "public"
DETAIL: creating new table with existing name in the same schema
ALTER TABLE
CREATE TABLE
ALTER TABLE
CREATE TABLE
ALTER TABLE
REVOKE
REVOKE
GRANT
GRANT
total time: 18 ms

--源库(备份的数据库):
omm@modb:~$ gsql -d omm -c "\dt"
(4 rows)

List of relations
Schema | Name | Type | Owner | Storage
--------+-------+-------+-------+----------------------------------
public | test1 | table | omm | {orientation=row,compression=no}
public | test2 | table | omm | {orientation=row,compression=no}
public | test3 | table | omm | {orientation=row,compression=no}
public | test4 | table | omm | {orientation=row,compression=no}

--新库(恢复的数据库):
omm@modb:~$ gsql -d testdb -U test -c "\dt"
Password for user test:
(4 rows)

List of relations
Schema | Name | Type | Owner | Storage
--------+-------+-------+-------+----------------------------------
public | test1 | table | omm | {orientation=row,compression=no}
public | test2 | table | omm | {orientation=row,compression=no}
public | test3 | table | omm | {orientation=row,compression=no}
public | test4 | table | omm | {orientation=row,compression=no}






原文链接:https://blog.csdn.net/dbahaoyuan/article/details/128298219

「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论