Skip to content

Commit 8914b1d

Browse files
committed
add BACKUP_NAME and RESTORE_NAME param
1 parent cc3a88c commit 8914b1d

File tree

4 files changed

+25
-4
lines changed

4 files changed

+25
-4
lines changed

platforms/kubernetes/postgres-operator/deploy/postgres-operator.yaml.template

+4
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,10 @@ spec:
161161
type: string
162162
PATH:
163163
type: string
164+
BACKUP_NAME:
165+
type: string
166+
RESTORE_NAME:
167+
type: string
164168
services:
165169
type: array
166170
items:

platforms/kubernetes/postgres-operator/deploy/postgresql.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ spec:
164164
ENDPOINT: "http://s3.pek3.qingstor.com/"
165165
BUCKET: "postgresql"
166166
PATH: "test/backup"
167+
# BACKUP_NAME: "postgresql-backup"
168+
# RESTORE_NAME: "postgresql-backup"
167169
# backupCluster:
168170
# manual:
169171
# trigger-id: 2

platforms/kubernetes/postgres-operator/postgres/constants.py

+2
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@
153153
SPEC_S3_ENDPOINT = "ENDPOINT"
154154
SPEC_S3_BUCKET = "BUCKET"
155155
SPEC_S3_PATH = "PATH"
156+
SPEC_S3_BACKUP_NAME = "BACKUP_NAME"
157+
SPEC_S3_RESTORE_NAME = "RESTORE_NAME"
156158

157159
# pod PriorityClass
158160
SPEC_POD_PRIORITY_CLASS = "priorityClassName"

platforms/kubernetes/postgres-operator/postgres/handle.py

+17-4
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@
152152
SPEC_S3_ENDPOINT,
153153
SPEC_S3_BUCKET,
154154
SPEC_S3_PATH,
155+
SPEC_S3_BACKUP_NAME,
156+
SPEC_S3_RESTORE_NAME,
155157
SPEC_BACKUP,
156158
SPEC_BACKUP_MANUAL,
157159
SPEC_BACKUP_TRIGGER_ID,
@@ -295,6 +297,7 @@
295297
BARMAN_BACKUP_END = "end_time"
296298
BARMAN_BACKUP_ID = "backup_id"
297299
BARMAN_BACKUP_SIZE = "size"
300+
BARMAN_BACKUP_NAME = "BARMAN_BACKUPNAME"
298301
BARMAN_STATUS_DEFAULT_NEED_FIELD = ["backup_id", "begin_time", "end_time", "begin_xlog", "end_xlog"]
299302
BARMAN_TIME_FORMAT = "%a %b %d %H:%M:%S %Y"
300303
### end
@@ -1610,9 +1613,17 @@ def get_oldest_backupid(backup_info: TypedDict) -> str:
16101613
return backupid
16111614

16121615

1613-
def get_s3_env(s3: TypedDict) -> List:
1616+
def get_s3_env(meta: kopf.Meta, s3: TypedDict) -> List:
16141617
res = list()
16151618

1619+
name = meta["name"]
1620+
if SPEC_S3_BACKUP_NAME in s3:
1621+
name = s3.pop(SPEC_S3_BACKUP_NAME)
1622+
if SPEC_S3_RESTORE_NAME in s3:
1623+
name = s3.pop(SPEC_S3_RESTORE_NAME)
1624+
res.append("-e")
1625+
res.append(BARMAN_BACKUP_NAME + '="' + name + '"')
1626+
16161627
# use SPEC_S3 prefix replace S3 key (must use S3_ prefix)
16171628
for k in list(s3.keys()):
16181629
old = k
@@ -1668,7 +1679,8 @@ def restore_postgresql_froms3(
16681679

16691680
# add s3 env by pgtools -e
16701681
s3 = spec[SPEC_S3].copy()
1671-
s3_info = get_s3_env(s3)
1682+
s3.pop(SPEC_S3_BACKUP_NAME, None)
1683+
s3_info = get_s3_env(meta, s3)
16721684

16731685
tmpconns: InstanceConnections = InstanceConnections()
16741686
tmpconns.add(conn)
@@ -1901,7 +1913,8 @@ def backup_postgresql_to_s3(
19011913

19021914
# add s3 env by pgtools
19031915
s3 = spec[SPEC_S3].copy()
1904-
s3_list = get_s3_env(s3)
1916+
s3.pop(SPEC_S3_RESTORE_NAME, None)
1917+
s3_list = get_s3_env(meta, s3)
19051918

19061919
backup_policy = spec.get(SPEC_BACKUP, {}).get(SPEC_BACKUP_POLICY, {})
19071920
policy_list = get_policy_env(backup_policy)
@@ -3579,7 +3592,7 @@ def correct_s3_profile(
35793592
) -> None:
35803593
if is_s3_manual_backup_mode(meta, spec, patch, status, logger) or is_s3_cron_backup_mode(meta, spec, patch, status, logger):
35813594
s3 = spec[SPEC_S3].copy()
3582-
s3_info = get_s3_env(s3)
3595+
s3_info = get_s3_env(meta, s3)
35833596
readwrite_conns = connections(spec, meta, patch,
35843597
get_field(POSTGRESQL, READWRITEINSTANCE),
35853598
False, None, logger, None, status, False)

0 commit comments

Comments
 (0)