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

openGauss每日一练第 20 天| 学习心得体会

原创 肖雪松 2022-12-13
973

学习心得

本课程我觉得非常重要,备份恢复永远是数据库技术的核心内容

课后作业

1.逻辑备份和恢复案例1:使用sql格式进行备份和恢复omm数据库

root@modb:~# su - omm omm@modb:~$ mkdir /var/lib/opengauss/backup 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 test IDENTIFIED BY 'huawei@1234' sysadmin; NOTICE: The encrypted password contains MD5 ciphertext, which is not secure. CREATE ROLE omm=# create tablespace test_tbs relative location 'tablespace/test_tbs1'; CREATE TABLESPACE omm=# create database testdb with tablespace=test_tbs; CREATE DATABASE omm=# create table test1(i int); CREATE TABLE omm=# create table test2(i int); CREATE TABLE omm=# \dt List of relations Schema | Name | Type | Owner | Storage --------+-------+-------+-------+---------------------------------- public | test1 | table | omm | {orientation=row,compression=no} public | test2 | table | omm | {orientation=row,compression=no} (2 rows) omm=# insert into test1 values(1); <----------模拟数据插入 omm=# INSERT 0 1 omm=# insert into test2 values(2); <----------模拟数据插入 INSERT 0 1 omm=# exit omm-# omm-# omm-# \q omm@modb:~$ gs_dump -U test -W huawei@1234 omm -F p -f /var/lib/opengauss/backup/backuptest.sql <----------备份 gs_dump[port='5432'][omm][2022-12-13 20:19:52]: The total objects number is 413. gs_dump[port='5432'][omm][2022-12-13 20:19:52]: [100.00%] 413 objects have been dumped. gs_dump[port='5432'][omm][2022-12-13 20:19:52]: dump database omm successfully gs_dump[port='5432'][omm][2022-12-13 20:19:52]: total time: 1655 ms omm=# drop table test1; <--------------------模拟删除数据 DROP TABLE omm=# \q omm@modb:~$ gsql -d omm -U test -W huawei@1234 -f /var/lib/opengauss/backup/backuptest.sql <-------恢复 SET SET SET SET SET SET gsql:/var/lib/opengauss/backup/backuptest.sql:16: ERROR: schema "test" already exists ALTER SCHEMA SET SET SET CREATE TABLE ALTER TABLE gsql:/var/lib/opengauss/backup/backuptest.sql:46: ERROR: relation "test2" already exists in schema "public" DETAIL: creating new table with existing name in the same schema ALTER TABLE REVOKE REVOKE GRANT GRANT total time: 16 ms 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=# select * from test1; <-----------------数据已经恢复 i --- 1 (1 row)

2.逻辑备份和恢复案例2:使用dump格式进行备份和恢复omm数据库

omm@modb:~$ gs_dump -U test -W huawei@1234 omm -F p -f /var/lib/opengauss/backup/backup.dump <----------备份 gs_dump[port='5432'][omm][2022-12-13 20:36:55]: The total objects number is 413. gs_dump[port='5432'][omm][2022-12-13 20:36:55]: [100.00%] 413 objects have been dumped. gs_dump[port='5432'][omm][2022-12-13 20:36:55]: dump database omm successfully gs_dump[port='5432'][omm][2022-12-13 20:36:55]: total time: 1708 ms 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=# drop table test2; <--------------------模拟删除数据 DROP TABLE omm=# exit omm-# ^C omm=# \q omm@modb:~$ gsql -d omm -U test -W huawei@1234 -f /var/lib/opengauss/backup/backup.dump <----------恢复 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 CREATE TABLE ALTER TABLE REVOKE REVOKE GRANT GRANT total time: 16 ms 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=# select * from test2; i --- 2 2 (2 rows)
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论