1.備份命令介紹
(1)gs_probackup
gs_probackup是一個(gè)用于管理MogDB數(shù)據(jù)庫備份和恢復(fù)的工具。它對(duì)MogDB實(shí)例進(jìn)行定期備份,以便在數(shù)據(jù)庫出現(xiàn)故障時(shí)能夠恢復(fù)服務(wù)器。
可用于備份單機(jī)數(shù)據(jù)庫,也可對(duì)主機(jī)或者主節(jié)點(diǎn)數(shù)據(jù)庫備機(jī)進(jìn)行備份,為物理備份。
可備份外部目錄的內(nèi)容,如腳本文件、配置文件、日志文件、dump文件等。
支持增量備份、定期備份和遠(yuǎn)程備份。
可設(shè)置備份的留存策略。
常用備份參數(shù):
-B 備份的路徑。
-D 數(shù)據(jù)目錄的路徑
-d 數(shù)據(jù)庫名
-p 數(shù)據(jù)庫端口
-b 指定備份模式,支持FULL和PTRACK。
2.全量備份
—設(shè)置數(shù)據(jù)庫參數(shù)
[omm@node1 ~]$ gs_guc reload -N all -I all -c "enable_cbm_tracking=on"
NOTICE: Turn on cbm tracking function.
Begin to perform the total nodes: 1.
Popen count is 1, Popen success count is 1, Popen failure count is 0.
Begin to perform gs_guc for datanodes.
Command count is 1, Command success count is 1, Command failure count is 0.
Total instances: 1. Failed instances: 0.
ALL: Success to perform gs_guc!
—初始化備份目錄
[omm@node1 ~]$ gs_probackup init -B /home/omm/bak
INFO: Backup catalog '/home/omm/bak' successfully inited
—添加備份實(shí)例
[omm@node1 ~]$ gs_probackup add-instance --instance test1 -B /home/omm/bak -D /opt/mogdb/data
INFO: Instance 'test1' successfully inited
—連接數(shù)據(jù)庫
[omm@node1 ~]$ gs_probackup set-config --instance=test1 -B /home/omm/bak -d postgres -p26000
—?jiǎng)?chuàng)建表test1并插入數(shù)據(jù)
openGauss=# Create table test1 (id int);
CREATE TABLE
openGauss=# Insert into test1 values (1);
INSERT 0 1
openGauss=# Insert into test1 values (2);
INSERT 0 1
openGauss=# Select * from test1;
id
----
1
2
(2 rows)
—數(shù)據(jù)庫全量備份
[omm@node1 ~]$ gs_probackup backup -B /home/omm/bak --instance test1 -b full
INFO: Backup start, gs_probackup version: 2.4.2, instance: test1, backup ID: RHH7GZ, backup mode: FULL, wal mode: STREAM, remote: false, compress-algorithm: none, compress-level: 1
LOG: Backup destination is initialized
WARNING: This openGauss instance was initialized without data block checksums. gs_probackup have no way to detect data block corruption without them. Reinitialize PGDATA with option '--data-checksums'.
LOG: Database backup start
LOG: started streaming WAL at 0/3000000 (timeline 1)
[2022-08-31 18:50:59]: check identify system success
[2022-08-31 18:50:59]: send START_REPLICATION 0/3000000 success
[2022-08-31 18:50:59]: keepalive message is received
INFO: Cannot parse path "base"
[2022-08-31 18:50:59]: keepalive message is received
INFO: PGDATA size: 600MB
INFO: Start transferring data files
LOG: Creating page header map "/home/omm/bak/backups/test1/RHH7GZ/page_header_map"
[2022-08-31 18:51:02]: keepalive message is received
[2022-08-31 18:51:05]: keepalive message is received
[2022-08-31 18:51:05]: keepalive message is received
INFO: Data files are transferred, time elapsed: 7s
INFO: wait for pg_stop_backup()
INFO: pg_stop backup() successfully executed
LOG: stop_lsn: 0/30001E8
LOG: Looking for LSN 0/30001E8 in segment: 000000010000000000000003
LOG: Found WAL segment: /home/omm/bak/backups/test1/RHH7GZ/database/pg_xlog/000000010000000000000003
LOG: Thread [0]: Opening WAL segment "/home/omm/bak/backups/test1/RHH7GZ/database/pg_xlog/000000010000000000000003"
LOG: Found LSN: 0/30001E8
LOG: finished streaming WAL at 0/4000000 (timeline 1)
LOG: Getting the Recovery Time from WAL
LOG: Thread [0]: Opening WAL segment "/home/omm/bak/backups/test1/RHH7GZ/database/pg_xlog/000000010000000000000003"
INFO: Syncing backup files to disk
INFO: Backup files are synced, time elapsed: 1s
INFO: Validating backup RHH7GZ
INFO: Backup RHH7GZ data files are valid
INFO: Backup RHH7GZ resident size: 616MB
INFO: Backup RHH7GZ completed
–驗(yàn)證備份是否成功
[omm@node1 ~]$ gs_probackup show -B /home/omm/bak/
BACKUP INSTANCE 'test1'
=================================================================================================================================
Instance Version ID Recovery Time Mode WAL Mode TLI Time Data WAL Zratio Start LSN Stop LSN Status
=================================================================================================================================
test1 9.2 RHH7GZ 2022-08-31 18:51:06+08 FULL STREAM 1/0 13s 600MB 16MB 1.00 0/3000028 0/30001E8 OK
3.增量備份
-b 指定備份模式,支持FULL和PTRACK。
FULL:創(chuàng)建全量備份,全量備份包含所有數(shù)據(jù)文件。
PTRACK:創(chuàng)建PTRACK增量備份。
—?jiǎng)?chuàng)建表test2并插入數(shù)據(jù)
openGauss=# Create table test2 (id int);
CREATE TABLE
openGauss=#
openGauss=# Insert into test2 values (1);
INSERT 0 1
openGauss=#
openGauss=# Insert into test2 values (2);
INSERT 0 1
openGauss=#
openGauss=# Select * from test2;
id
----
1
2
(2 rows)
—數(shù)據(jù)庫增量備份
[omm@node1 ~]$ gs_probackup backup -B /home/omm/bak/ --instance test1 -b PTRACK
INFO: Backup start, gs_probackup version: 2.4.2, instance: test1, backup ID: RHH7OA, backup mode: PTRACK, wal mode: STREAM, remote: false, compress-algorithm: none, compress-level: 1
LOG: Backup destination is initialized
WARNING: This openGauss instance was initialized without data block checksums. gs_probackup have no way to detect data block corruption without them. Reinitialize PGDATA with option '--data-checksums'.
LOG: Database backup start
LOG: Latest valid FULL backup: RHH7GZ
INFO: Parent backup: RHH7GZ
LOG: started streaming WAL at 0/5000000 (timeline 1)
[2022-08-31 18:55:22]: check identify system success
[2022-08-31 18:55:22]: send START_REPLICATION 0/5000000 success
[2022-08-31 18:55:22]: keepalive message is received
INFO: Cannot parse path "base"
[2022-08-31 18:55:22]: keepalive message is received
INFO: PGDATA size: 600MB
LOG: Current tli: 1
LOG: Parent start_lsn: 0/3000028
LOG: start_lsn: 0/5000028
INFO: Extracting pagemap of changed blocks
INFO: change bitmap start lsn location is 0/3000028
INFO: change bitmap end lsn location is 00000000/05000028
INFO: Pagemap successfully extracted, time elapsed: 0 sec
INFO: Start transferring data files
LOG: Creating page header map "/home/omm/bak/backups/test1/RHH7OA/page_header_map"
[2022-08-31 18:55:25]: keepalive message is received
INFO: Data files are transferred, time elapsed: 4s
INFO: wait for pg_stop_backup()
INFO: pg_stop backup() successfully executed
LOG: stop_lsn: 0/50001E8
LOG: Looking for LSN 0/50001E8 in segment: 000000010000000000000005
LOG: Found WAL segment: /home/omm/bak/backups/test1/RHH7OA/database/pg_xlog/000000010000000000000005
LOG: Thread [0]: Opening WAL segment "/home/omm/bak/backups/test1/RHH7OA/database/pg_xlog/000000010000000000000005"
LOG: Found LSN: 0/50001E8
LOG: finished streaming WAL at 0/6000000 (timeline 1)
LOG: Getting the Recovery Time from WAL
LOG: Thread [0]: Opening WAL segment "/home/omm/bak/backups/test1/RHH7OA/database/pg_xlog/000000010000000000000005"
INFO: Syncing backup files to disk
INFO: Backup files are synced, time elapsed: 0
INFO: Validating backup RHH7OA
INFO: Backup RHH7OA data files are valid
INFO: Backup RHH7OA resident size: 273MB
INFO: Backup RHH7OA completed
—查看當(dāng)前所有備份
[omm@node1 ~]$ gs_probackup show -B /home/omm/bak/
BACKUP INSTANCE 'test1'
===================================================================================================================================
Instance Version ID Recovery Time Mode WAL Mode TLI Time Data WAL Zratio Start LSN Stop LSN Status
===================================================================================================================================
test1 9.2 RHH7OA 2022-08-31 18:55:26+08 PTRACK STREAM 1/1 11s 257MB 16MB 1.00 0/5000028 0/50001E8 OK
test1 9.2 RHH7GZ 2022-08-31 18:51:06+08 FULL STREAM 1/0 13s 600MB 16MB 1.00 0/3000028 0/30001E8 OK
「喜歡這篇文章,您的關(guān)注和贊賞是給作者最好的鼓勵(lì)」
關(guān)注作者
【版權(quán)聲明】本文為墨天輪用戶原創(chuàng)內(nèi)容,轉(zhuǎn)載時(shí)必須標(biāo)注文章的來源(墨天輪),文章鏈接,文章作者等基本信息,否則作者和墨天輪有權(quán)追究責(zé)任。如果您發(fā)現(xiàn)墨天輪中有涉嫌抄襲或者侵權(quán)的內(nèi)容,歡迎發(fā)送郵件至:contact@modb.pro進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),墨天輪將立刻刪除相關(guān)內(nèi)容。




