学习目标
掌握openGauss数据库的逻辑备份和恢复技术。
课程作业
1.逻辑备份和恢复案例1:使用sql格式进行备份和恢复omm数据库
root@modb:~# su - omm omm@modb:~$ pwd /home/omm omm@modb:~$ mkdir bk 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 user dhr identified by 'dhr@1234' sysadmin; NOTICE: The encrypted password contains MD5 ciphertext, which is not secure. CREATE ROLE omm=# create tablespace testtbs relative location 'tablespace/tbs'; CREATE TABLESPACE omm=# create database testdb with tablespace=testtbs; omm=# CREATE DATABASE omm=# create table t1(id int); CREATE TABLE omm=# create table t2(id int); CREATE TABLE omm=# \dt List of relations Schema | Name | Type | Owner | Storage --------+------+-------+-------+---------------------------------- public | t1 | table | omm | {orientation=row,compression=no} public | t2 | table | omm | {orientation=row,compression=no} (2 rows) omm@modb:~$ gs_dump -U dhr -W dhr@1234 omm -F p -f /home/omm/bk/backup.sql gs_dump[port='5432'][omm][2022-12-13 11:13:30]: The total objects number is 413. gs_dump[port='5432'][omm][2022-12-13 11:13:30]: [100.00%] 413 objects have been dumped. gs_dump[port='5432'][omm][2022-12-13 11:13:30]: dump database omm successfully gs_dump[port='5432'][omm][2022-12-13 11:13:30]: total time: 1724 ms omm@modb:~$ gsql -d testdb -U dhr -W dhr@1234 -f /home/omm/bk/backup.sql SET SET SET SET SET SET CREATE SCHEMA ALTER SCHEMA SET SET SET CREATE TABLE ALTER TABLE CREATE TABLE ALTER TABLE REVOKE REVOKE GRANT GRANT total time: 20 ms omm@modb:~$ gsql -d omm -c "\dt" List of relations Schema | Name | Type | Owner | Storage --------+------+-------+-------+---------------------------------- public | t1 | table | omm | {orientation=row,compression=no} public | t2 | table | omm | {orientation=row,compression=no} (2 rows) omm@modb:~$ gsql -d testdb -U dhr -W dhr@1234 -c "\dt" List of relations Schema | Name | Type | Owner | Storage --------+------+-------+-------+---------------------------------- public | t1 | table | omm | {orientation=row,compression=no} public | t2 | table | omm | {orientation=row,compression=no} (2 rows)
复制
2.逻辑备份和恢复案例2:使用dump格式进行备份和恢复omm数据库
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 t3(id int); CREATE TABLE omm=# create table t4(id int); CREATE TABLE omm=# \q omm@modb:~$ gs_dump -U dhr -W dhr@1234 omm -F p -f /home/omm/bk/bk.dump gs_dump[port='5432'][omm][2022-12-13 11:18:16]: The total objects number is 417. gs_dump[port='5432'][omm][2022-12-13 11:18:16]: [100.00%] 417 objects have been dumped. gs_dump[port='5432'][omm][2022-12-13 11:18:16]: dump database omm successfully gs_dump[port='5432'][omm][2022-12-13 11:18:16]: total time: 1575 ms omm@modb:~$ gsql -d testdb -U dhr -W dhr@1234 -f /home/omm/bk/bk.dump SET SET SET SET SET SET gsql:/home/omm/bk/bk.dump:16: ERROR: schema "dhr" already exists ALTER SCHEMA SET SET SET gsql:/home/omm/bk/bk.dump:34: ERROR: relation "t1" already exists in schema "public" DETAIL: creating new table with existing name in the same schema ALTER TABLE gsql:/home/omm/bk/bk.dump:46: ERROR: relation "t2" 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: 21 ms omm@modb:~$ gsql -d testdb -U dhr -W dhr@1234 -c "\dt" List of relations Schema | Name | Type | Owner | Storage --------+------+-------+-------+---------------------------------- public | t1 | table | omm | {orientation=row,compression=no} public | t2 | table | omm | {orientation=row,compression=no} public | t3 | table | omm | {orientation=row,compression=no} public | t4 | table | omm | {orientation=row,compression=no} (4 rows)
复制
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。
评论

2年前

评论
相关阅读
2025年3月国产数据库大事记
墨天轮编辑部
865次阅读
2025-04-03 15:21:16
MogDB 发布更新,解决 openGauss 数据库在长事务情况下Ustore表膨胀问题
MogDB
285次阅读
2025-04-17 10:41:41
openGauss 7.0.0-RC1 版本正式发布!
Gauss松鼠会
195次阅读
2025-04-01 12:27:03
MogDB 发布更新,解决 openGauss 数据库在长事务情况下Ustore表膨胀问题
云和恩墨
182次阅读
2025-04-16 09:52:02
openGauss 7.0.0-RC1 版本体验:一主一备快速安装指南
孙莹
175次阅读
2025-04-01 10:30:07
鲲鹏RAG一体机解决方案正式发布 openGauss DataVec向量数据库助力DeepSeek行业应用
Gauss松鼠会
120次阅读
2025-03-31 10:00:29
一文快速上手openGauss
进击的CJR
112次阅读
2025-03-26 16:12:54
荣誉时刻!openGauss认证证书快递已发,快来看看谁榜上有名!
墨天轮小教习
102次阅读
2025-04-23 17:39:13
openGauss6.0.0适配操作系统自带的软件,不依赖三方库
来杯拿铁
74次阅读
2025-04-18 10:49:53
opengauss使用gs_probackup进行增量备份恢复
进击的CJR
69次阅读
2025-04-09 16:11:58