1.全量备份。
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_162446
[MASTER] Time taken : 28s
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.
--全量备份的备份键:20240408_162446
2.增量备份1
create database mydb1;
\c mydb1;
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)
--validate-prior-backups force:强制验证上次的备份是否有效。
python3 GaussRoach.py -t backup --master-port 3000 --media-destination /data/backup --media-type disk --metadata-destination /data/backup2 --prior-backup-key 20240408_162446 --validate-prior-backups force
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] VALIDATE SUCCESSFUL.
[MASTER] Time taken : 1s
Cleaning temp files after backup or restore.
Successfully cleaned temp files after backup or restore.
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_162921
[MASTER] Time taken : 25s
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.
--第一次增量备份后的备份键:20240408_162921
3.增量备份2
mydb1=> create table test2(id int);
CREATE TABLE
mydb1=> insert into test2 values(1),(2);
INSERT 0 2
mydb1=> select * from test2;
id
----
1
2
(2 rows)
--第二次增量备份。
python3 GaussRoach.py -t backup --master-port 3000 --media-destination /data/backup --media-type disk --metadata-destination /data/backup2 --prior-backup-key 20240408_162921 --validate-prior-backups force
Parsing the configuration file.
Validate operation in-progress for 'FULL BACKUP' key[1/2]: 20240408_162446
Roach master is ready to accept connections. Starting agents now...
Performing presetup activities...
N0 192.168.0.142: 100% COMPLETED
[MASTER] VALIDATE SUCCESSFUL.
[MASTER] Time taken : 1s
--------------------------------------------------------------------------------
Validate operation in-progress for 'INCREMENTAL BACKUP' key[2/2]: 20240408_162921
Roach master is ready to accept connections. Starting agents now...
Performing presetup activities...
N0 192.168.0.142: 100% COMPLETED
[MASTER] VALIDATE SUCCESSFUL.
[MASTER] Time taken : 1
Cleaning temp files after backup or restore.
Successfully cleaned temp files after backup or restore.
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_163223
[MASTER] Time taken : 25s
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.
--可以看到,第二次增量备份时,验证了全备的有效性(20240408_162446)
--验证了第一次增量备份的有效性(20240408_162921)
--本次生成的备份键:20240408_163223
4.增量备份3
create table test3(id int,name varchar2(20));
insert into test3 values(1,'雪霜去'),(2,'薛双奇2');
id | name
----+---------
1 | 雪霜去
2 | 薛双奇2
(2 rows)
mydb1=> \d
List of relations
Schema | Name | Type | Owner | Storage
--------+-------+-------+-------+------------------------------------------------------------------
public | test1 | table | root | {orientation=row,compression=no,storage_type=USTORE,segment=off}
public | test2 | table | root | {orientation=row,compression=no,storage_type=USTORE,segment=off}
public | test3 | table | root | {orientation=row,compression=no,storage_type=USTORE,segment=off}
(3 rows)
--第三次增量备份。
python3 GaussRoach.py -t backup --master-port 3000 --media-destination /data/backup --media-type disk --metadata-destination /data/backup2 --prior-backup-key 20240408_163223 --validate-prior-backups force
Parsing the configuration file.
Validate operation in-progress for 'FULL BACKUP' key[1/3]: 20240408_162446
Roach master is ready to accept connections. Starting agents now...
Performing presetup activities...
N0 192.168.0.142: 100% COMPLETED
[MASTER] VALIDATE SUCCESSFUL.
[MASTER] Time taken : 2s
--------------------------------------------------------------------------------
Validate operation in-progress for 'INCREMENTAL BACKUP' key[2/3]: 20240408_162921
Roach master is ready to accept connections. Starting agents now...
Performing presetup activities...
N0 192.168.0.142: 100% COMPLETED
[MASTER] VALIDATE SUCCESSFUL.
[MASTER] Time taken : 1s
--------------------------------------------------------------------------------
Validate operation in-progress for 'INCREMENTAL BACKUP' key[3/3]: 20240408_163223
Roach master is ready to accept connections. Starting agents now...
Performing presetup activities...
N0 192.168.0.142: 100% COMPLETED
[MASTER] VALIDATE SUCCESSFUL.
[MASTER] Time taken : 1s
Cleaning temp files after backup or restore.
Successfully cleaned temp files after backup or restore.
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_163805
[MASTER] Time taken : 45s
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.
--验证了全备:20240408_162446
--验证了第一次增量备份:20240408_162921
--验证了第二次增量备份:20240408_163223
--第三次增量备份生产的备份键:20240408_163805
5.对增量备份进行恢复。
python3 GaussRoach.py -t restore --clean --master-port 3000 --media-destination /data/backup \
--media-type DISK --backup-key 20240408_163805 --metadata-destination /data/backup2
--恢复时只需要指定最后一次备份时的备份键,即可自动恢复到最后一次备份时的位置。
Cleaning cluster.
Parsing the configuration file.
Stopping cluster.
Successfully stopped cluster.
Cleaning data before restoration.
Successfully cleaned data before restoration.
Successfully cleaned cluster.
Restore operation in-progress for 'FULL BACKUP' key[1/4]: 20240408_162446
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 : 12s
--------------------------------------------------------------------------------
Restore operation in-progress for 'INCREMENTAL BACKUP' key[2/4]: 20240408_162921
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 : 2s
--------------------------------------------------------------------------------
Restore operation in-progress for 'INCREMENTAL BACKUP' key[3/4]: 20240408_163223
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 : 1s
--------------------------------------------------------------------------------
Restore operation in-progress for 'INCREMENTAL BACKUP' key[4/4]: 20240408_163805
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 : 1s
Cleaning temp files after backup or restore.
Successfully cleaned temp files after backup or restore.
Roach operation restore completed.
6.启动数据库
[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.
7.验证数据
mydb1=> \d
List of relations
Schema | Name | Type | Owner | Storage
--------+-------+-------+-------+------------------------------------------------------------------
public | test1 | table | root | {orientation=row,compression=no,storage_type=USTORE,segment=off}
public | test2 | table | root | {orientation=row,compression=no,storage_type=USTORE,segment=off}
public | test3 | table | root | {orientation=row,compression=no,storage_type=USTORE,segment=off}
(3 rows)
mydb1=> select * from test1;
id
----
1
2
(2 rows)
mydb1=> select * from test2;
id
----
1
2
(2 rows)
mydb1=> select * from test3;
id | name
----+---------
1 | 雪霜去
2 | 薛双奇2
(2 rows)
8.总结
由此可见我们已经恢复到了最后一次增量备份的数据的视点。
增量备份恢复,恢复时只需要指定最后一次的增量的备份集的名称,既可以恢复到指定的位置。
这样恢复是非常方便的,不需要先恢复全备,再挨着进行恢复增量的数据。