【GaussDB】普通备份恢复

本文介绍了GaussDB数据库如何通过Roach工具实现物理备份与恢复,包括全量备份、增量备份以及闪回恢复功能。此外,还详细描述了备份介质和细粒度备份的特点,以及使用GaussRoach进行备份和恢复的具体步骤。
摘要由CSDN通过智能技术生成

0.备份与恢复。

数据备份是保护数据安全的重要手段之一,为了更好的保护数据安全,GaussDB数据库提供了Roach工具,
支持多种备份恢复方案,备份和恢复过程中提供数据的可靠性保障机制。
•物理备份与恢复:通过物理文件拷贝的方式对数据库进行备份,以磁盘块为基本单位将数据从主机复制到备机。
通过备份的数据文件及归档日志等文件,数据库可以进行完全恢复。物理备份速度快,
一般被用作对数据进行备份和恢复,用于全量备份的场景。通过合理规划,可以低成本进行备份与恢复。
数据库中通过GaussRoach工具来提供物理备份与恢复功能。
•闪回恢复:闪回DROP、闪回TRUNCATE利用回收站能够恢复删除和TRUNCATE的表。
数据库的回收站功能类似于windows系统的回收站,将删除的表信息保存在回收站中。
闪回表通过旧版本检索机制,能够将表恢复到指定时间点或者CSN点。
以下为GaussDB支持的两类数据备份恢复方案,备份方案也决定了当异常发生时该如何恢复。
本章主要介绍GaussRoach工具和使用方式。


物理备份与恢复

适用于数据量大的场景,主要用于全量数据备份恢复,也可对整个数据库中的WAL归档日志和运行日志进行备份恢复。
目前不仅支持数据库实例的全量备份恢复和增量备份恢复,还支持有着”细粒度备份恢复”之称的从数据库实例的
备份数据中恢复单个或多个数据库、单个或多个表,全量、增量备份单个或多个表以及从表级备份数据中恢复
单个或多个表的功能。
细粒度备份恢复仅支持OBS和NAS介质。
备份介质
•磁盘
•OBS
•NAS

数据量大时,备份效率高

1.全量备份 

--介质目录必须何元数据目录是不同的目录。
--介质目录:/data/backup,元数据目录:/data/backup2
--任意指定一个端口3000启动,GaussRoach;
--开始备份数据。
cd /data/cluster/tools/script/
python3 GaussRoach.py -t backup --master-port 3000 \
--media-type disk --media-destination /data/backup --metadata-destination /data/backup2  --pre-disk-space

Parsing the configuration file.
Roach master is ready to accept connections. Starting agents now...
Performing presetup activities...
N0   192.168.0.142: 100% COMPLETED
[MASTER]Backup operation SUCCESSFUL. Backup key: 20240408_155812
[MASTER] Time taken : 31s
Successfully send signal to kill all gs_roach.
Cleaning temp files after backup or restore.
Successfully cleaned temp files after backup or restore.
Roach operation backup completed.

--media-type:介质类型。
•DISK
•OBS
•NAS

--media-destination:数据存储路径。
--metadata-destination:备份元数据存储路径。

2.插入数据 

gaussdb=> create database mydb1 ;
gaussdb=> \c mydb1
Password for user root: 数据root密码。
mydb1=> create table test1(id int);
CREATE TABLE
mydb1=>  insert into test1 values(1),(2);
INSERT 0 2
mydb1=> select * from test1; 
 id 
----
  1
  2
(2 rows)

mydb1=> \q

3.恢复数据到磁盘。

python3 GaussRoach.py -t restore --clean --master-port 3000 --media-destination /data/backup \
--media-type DISK --backup-key 20240408_155812 --metadata-destination /data/backup2

Roach master is ready to accept connections. Starting agents now...
Performing presetup activities...
N0   192.168.0.142: 100% COMPLETED
[MASTER] Restore SUCCESSFUL.
[MASTER] Time taken : 13s
Cleaning temp files after backup or restore.
Successfully cleaned temp files after backup or restore.
Roach operation restore completed.

--可以看到恢复到原目录,数据库宕机。
[omm@gauss001 script]$ ps -ef |grep gauss
omm      1681505       1  0 16:14 ?        00:00:00 /data/cluster/core/app/bin/om_monitor -L /data/cluster/logs/gaussdb/omm/cm/om_monitor
omm      1681726 1626034  0 16:14 pts/0    00:00:00 grep gauss
[omm@gauss001 script]$ 

4.重启数据库。

[omm@gauss001 script]$ gs_om -t start
Starting cluster.
======================================================================
Successfully started primary instance. Wait for standby instance.
======================================================================
.
Successfully started cluster.
======================================================================
cluster_state      : Normal
redistributing     : No
node_count         : 1
Coordinator State
    normal         : 0
    abnormal       : 0
GTM State
    primary        : 0
    standby        : 0
    abnormal       : 0
    down           : 0
Datanode State
    primary        : 1
    standby        : 0
    secondary      : 0
    building       : 0
    abnormal       : 0
    down           : 0
Successfully started cluster.

[omm@gauss001 script]$ gs_om -t status
-----------------------------------------------------------------------

cluster_state             : Normal
redistributing            : No
balanced                  : Yes

--数据检查,可以看到我们备份之后插入的数据没有了。
--由此我们可以知道,当前的备份类似与冷备,只能恢复到过去,无法恢复到当前。
gaussdb=> \l
                             List of databases
   Name    |  Owner   | Encoding | Collate | Ctype |   Access privileges   
-----------+----------+----------+---------+-------+-----------------------
 drs       | root     | UTF8     | C       | C     | =Tc/root             +
           |          |          |         |       | root=CTc/root        +
           |          |          |         |       | drs=CTc/root         +
           |          |          |         |       | drs=APm/root
 postgres  | rdsAdmin | UTF8     | C       | C     | =Tc/rdsAdmin         +
           |          |          |         |       | rdsAdmin=CTc/rdsAdmin+
           |          |          |         |       | backupUser=c/rdsAdmin+
           |          |          |         |       | repUser=c/rdsAdmin   +
           |          |          |         |       | root=c/rdsAdmin      +
           |          |          |         |       | metricUser=c/rdsAdmin
 template0 | rdsAdmin | UTF8     | C       | C     | =c/rdsAdmin          +
           |          |          |         |       | rdsAdmin=CTc/rdsAdmin
 template1 | rdsAdmin | UTF8     | C       | C     | =c/rdsAdmin          +
           |          |          |         |       | rdsAdmin=CTc/rdsAdmin
(4 rows)

5.启动数据库另外一种方法

--或者使用:GaussRoach启动数据库也可以。
--使用GaussRoach启动数据库的回显如下。
[omm@gauss001 script]$ python3 GaussRoach.py -t start
Stopping the cluster.
Successfully stopped the cluster.
Starting the cluster.
Starting DN master.
Successfully started DN master.
Starting build DN standby.
Successfully start DN standby.
Starting DN dummy standby.
Successfully start DN dummy standby.
Stoping DN instances.
Successfully stop DN instances.
Starting the cluster.
Successfully started primary instance. Please wait for standby instances.
.
Successfully started standby instances.
Waiting for the cluster become normal...
Stopping the cluster.
Successfully stopped the cluster.
Starting the cluster.
Successfully started primary instance. Please wait for standby instances.
.
Successfully started standby instances.
======================================================================
cluster_state      : Normal
redistributing     : No
node_count         : 1
Coordinator State
    normal         : 0
    abnormal       : 0
GTM State
    primary        : 0
    standby        : 0
    abnormal       : 0
    down           : 0
Datanode State
    primary        : 1
    standby        : 0
    secondary      : 0
    building       : 0
    abnormal       : 0
    down           : 0

Successfully started the cluster.
Cleaning backup slot after restore.

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值