课程作业
1.逻辑备份和恢复案例1:使用sql格式进行备份和恢复omm数据库
--创建备份文件目录
omm@modb:/var/lib/opengauss$ mkdir -p /var/lib/opengauss/yangkai/backup
--创建备份用户
omm=# create user yangkai identified by 'Yangkai@123';
NOTICE: The encrypted password contains MD5 ciphertext, which is not secure.
CREATE ROLE
omm=# alter user yangkai sysadmin;
ALTER ROLE
--准备测试数据
omm=# create table t1(id int);
CREATE TABLE
omm=# create table t2(id int);
omm=# CREATE TABLE

--使用sql格式进行备份omm数据库

准备目标数据库
omm=# create tablespace yangkai_tbs RELATIVE LOCATION 'tablespace/yangkai_tbs1';
CREATE TABLESPACE
omm=# create database yangkaidb WITH TABLESPACE yangkai_tbs;
CREATE DATABASE
--使用sql格式进行把omm数据库恢复到新的数据库yangkaidb

--在新数据库验证数据

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

--使用dump格式进行备份omm数据库
omm@modb:/var/lib/opengauss$ gs_dump -U yangkai -W Yangkai@123 omm -F p -f /var/lib/opengauss/yangkai/backup/yangkai.dump
gs_dump[port='5432'][omm][2022-12-13 11:17:38]: The total objects number is 417.
gs_dump[port='5432'][omm][2022-12-13 11:17:38]: [100.00%] 417 objects have been dumped.
gs_dump[port='5432'][omm][2022-12-13 11:17:38]: dump database omm successfully
gs_dump[port='5432'][omm][2022-12-13 11:17:38]: total time: 1728 ms
--使用dump格式进行把omm数据库恢复到新的数据库yangkaidb
omm@modb:/var/lib/opengauss$ gsql -d yangkaidb -U yangkai -W Yangkai@123 -f /var/lib/opengauss/yangkai/backup/yangkai.dump
SET
SET
SET
SET
SET
SET
ALTER SCHEMA
SET
SET
SET
ALTER TABLE
CREATE TABLE
ALTER TABLE
CREATE TABLE
ALTER TABLE
REVOKE
REVOKE
GRANT
GRANT
total time: 24 ms
--恢复数据验证
omm@modb:/var/lib/opengauss$ gsql -d yangkaidb -U yangkai -W Yangkai@123 -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)
omm@modb:/var/lib/opengauss$
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




