Crunchy PG手動備份實驗

zchbaby2000發表於2023-02-15

Crunchy PostgreSQL在Kubernets/Openshift安裝以後,可以透過yaml檔案非常容易的配置自動備份和手動備份,自動備份是由Crunchy Postgres Operator建立了CronJobs控制在什麼時間,執行什麼備份,和Linux裡面的Cronjob類似。


例如如下示例定義了自動備份的策略

每週日 1am執行一個全量備份

每週 週一到週六 1am 執行增量備份

spec:
  backups:
    pgbackrest:
      repos:
      - name: repo1
        schedules:
          full: "0 1 * * 0"
          differential: "0 1 * * 1-6"


3種備份定義如下

(1) full: A backup of your entire Postgres cluster. This is the largest of all of the backup types.
(2) differential: A backup of all of the data since the last full backup.
(3) incremental: A backup of all of the data since the last full, differential, or incremental backup.


對於手工備份,這裡做3個實驗來驗證3種不同的備份 (full, differential, incremental)。


第一個實驗:手工全量備份
yaml檔案中的相關的設定部分

      manual:
        repoName: repo1
        options:
        - --type=full



第一次安裝完成以後自動做一個full backup

$ oc get po
NAME                              READY   STATUS      RESTARTS   AGE
demo-backup-r7fk-27shq            0/1     Completed   0          4m52s
demo-instance1-2wkh-0             5/5     Running     0          6m34s
demo-instance1-6hv6-0             5/5     Running     0          6m34s
demo-pgbouncer-866898f6c4-wh7zf   2/2     Running     0          6m34s
demo-repo-host-0                  2/2     Running     0          6m34s



第一次手動full備份

$ oc annotate postgrescluster demo postgres-operator.crunchydata.com/pgbackrest-backup="$(date)"
postgrescluster.postgres-operator.crunchydata.com/demo annotated
$ oc get po
NAME                              READY   STATUS      RESTARTS   AGE
demo-backup-qpf7-nhhvh            0/1     Completed   0          27s
demo-backup-r7fk-27shq            0/1     Completed   0          5m25s
demo-instance1-2wkh-0             5/5     Running     0          7m7s
demo-instance1-6hv6-0             5/5     Running     0          7m7s
demo-pgbouncer-866898f6c4-wh7zf   2/2     Running     0          7m7s
demo-repo-host-0                  2/2     Running     0          7m7s




第二次手動full備份,要加 --overwrite 選項才行

$ oc annotate postgrescluster demo --overwrite postgres-operator.crunchydata.com/pgbackrest-backup="$(date)"
postgrescluster.postgres-operator.crunchydata.com/demo annotated
$ oc get po
NAME                              READY   STATUS              RESTARTS   AGE
demo-backup-c7vw-l4fg4            0/1     ContainerCreating   0          1s
demo-backup-r7fk-27shq            0/1     Completed           0          7m23s
demo-instance1-2wkh-0             5/5     Running             0          9m5s
demo-instance1-6hv6-0             5/5     Running             0          9m5s
demo-pgbouncer-866898f6c4-wh7zf   2/2     Running             0          9m5s
demo-repo-host-0                  2/2     Running             0          9m5s
$ oc get po
NAME                              READY   STATUS      RESTARTS   AGE
demo-backup-c7vw-l4fg4            0/1     Completed   0          27s
demo-backup-r7fk-27shq            0/1     Completed   0          7m49s
demo-instance1-2wkh-0             5/5     Running     0          9m31s
demo-instance1-6hv6-0             5/5     Running     0          9m31s
demo-pgbouncer-866898f6c4-wh7zf   2/2     Running     0          9m31s
demo-repo-host-0                  2/2     Running     0          9m31s



檢視pgbackrest的備份資訊,應該有3個備份資訊
$ oc exec -it demo-repo-host-0 -c pgbackrest -- pgbackrest info

stanza: db
    status: ok
    cipher: none
    db (current)
        wal archive min/max (14): 000000010000000000000001/000000010000000000000008
        full backup: 20230215-094253F
            timestamp start/stop: 2023-02-15 09:42:53 / 2023-02-15 09:44:44
            wal start/stop: 000000010000000000000004 / 000000010000000000000004
            database size: 37.0MB, database backup size: 37.0MB
            repo1: backup set size: 4.5MB, backup size: 4.5MB
        full backup: 20230215-094505F
            timestamp start/stop: 2023-02-15 09:45:05 / 2023-02-15 09:45:23
            wal start/stop: 000000010000000000000006 / 000000010000000000000006
            database size: 37MB, database backup size: 37MB
            repo1: backup set size: 4.5MB, backup size: 4.5MB
        full backup: 20230215-094728F
            timestamp start/stop: 2023-02-15 09:47:28 / 2023-02-15 09:47:44
            wal start/stop: 000000010000000000000008 / 000000010000000000000008
            database size: 37.2MB, database backup size: 37.2MB
            repo1: backup set size: 4.5MB, backup size: 4.5MB


實驗二:differential 備份
修改yaml檔案,改成

      manual:
        repoName: repo1
        options:
        - --type=diff


然後apply yaml檔案。
執行和full backup同樣的命令2次,可以透過 pgbackrest info檢視備份的資訊

$ oc exec -it demo-repo-host-0 -c pgbackrest -- pgbackrest info
stanza: db
    status: ok
    cipher: none
    db (current)
        wal archive min/max (14): 000000010000000000000001/000000010000000000000008
        full backup: 20230215-102129F
            timestamp start/stop: 2023-02-15 10:21:29 / 2023-02-15 10:22:42
            wal start/stop: 000000010000000000000004 / 000000010000000000000004
            database size: 36.9MB, database backup size: 36.9MB
            repo1: backup set size: 4.5MB, backup size: 4.5MB
        diff backup: 20230215-102129F_20230215-102455D
            timestamp start/stop: 2023-02-15 10:24:55 / 2023-02-15 10:25:21
            wal start/stop: 000000010000000000000006 / 000000010000000000000006
            database size: 37MB, database backup size: 6.5MB
            repo1: backup set size: 4.5MB, backup size: 1015.8KB
            backup reference list: 20230215-102129F
        diff backup: 20230215-102129F_20230215-102636D
            timestamp start/stop: 2023-02-15 10:26:36 / 2023-02-15 10:26:40
            wal start/stop: 000000010000000000000008 / 000000010000000000000008
            database size: 37.2MB, database backup size: 6.6MB
            repo1: backup set size: 4.5MB, backup size: 1019.6KB
            backup reference list: 20230215-102129F



實驗三:Incremental 備份
修改yaml檔案,改成

      manual:
        repoName: repo1
        options:
        - --type=incr


然後apply yaml檔案。
執行和full backup同樣的命令2次,可以透過 pgbackrest info檢視備份的資訊

$ oc exec -it demo-repo-host-0 -c pgbackrest -- pgbackrest info
stanza: db
    status: ok
    cipher: none
    db (current)
        wal archive min/max (14): 000000010000000000000001/00000001000000000000000D
        full backup: 20230215-102129F
            timestamp start/stop: 2023-02-15 10:21:29 / 2023-02-15 10:22:42
            wal start/stop: 000000010000000000000004 / 000000010000000000000004
            database size: 36.9MB, database backup size: 36.9MB
            repo1: backup set size: 4.5MB, backup size: 4.5MB
        diff backup: 20230215-102129F_20230215-102455D
            timestamp start/stop: 2023-02-15 10:24:55 / 2023-02-15 10:25:21
            wal start/stop: 000000010000000000000006 / 000000010000000000000006
            database size: 37MB, database backup size: 6.5MB
            repo1: backup set size: 4.5MB, backup size: 1015.8KB
            backup reference list: 20230215-102129F
        diff backup: 20230215-102129F_20230215-102636D
            timestamp start/stop: 2023-02-15 10:26:36 / 2023-02-15 10:26:40
            wal start/stop: 000000010000000000000008 / 000000010000000000000008
            database size: 37.2MB, database backup size: 6.6MB
            repo1: backup set size: 4.5MB, backup size: 1019.6KB
            backup reference list: 20230215-102129F
        incr backup: 20230215-102129F_20230215-103608I
            timestamp start/stop: 2023-02-15 10:36:08 / 2023-02-15 10:36:10
            wal start/stop: 00000001000000000000000B / 00000001000000000000000B
            database size: 38.0MB, database backup size: 1.7MB
            repo1: backup set size: 4.6MB, backup size: 96.8KB
            backup reference list: 20230215-102129F, 20230215-102129F_20230215-102636D
        incr backup: 20230215-102129F_20230215-103656I
            timestamp start/stop: 2023-02-15 10:36:56 / 2023-02-15 10:36:58
            wal start/stop: 00000001000000000000000D / 00000001000000000000000D
            database size: 38MB, database backup size: 1.7MB
            repo1: backup set size: 4.6MB, backup size: 98.4KB
            backup reference list: 20230215-102129F, 20230215-102129F_20230215-102636D, 20230215-102129F_20230215-103608I




來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/725820/viewspace-2935467/,如需轉載,請註明出處,否則將追究法律責任。

相關文章