Merge ~cjwatson/launchpad:charm-postgresql-extras-push-backups-primary-only into launchpad:master

Proposed by Colin Watson
Status: Needs review
Proposed branch: ~cjwatson/launchpad:charm-postgresql-extras-push-backups-primary-only
Merge into: launchpad:master
Diff against target: 33 lines (+15/-0)
1 file modified
charm/launchpad-postgresql-extras/files/push-backups (+15/-0)
Reviewer Review Type Date Requested Status
Launchpad code reviewers Pending
Review via email: mp+456278@code.launchpad.net

Commit message

charm: Only run push-backups on primary database units

Description of the change

We don't want to be pushing backups from more than one unit.

To post a comment you must log in.

Unmerged commits

513b1bc... by Colin Watson

charm: Only run push-backups on primary database units

We don't want to be pushing backups from more than one unit.

Succeeded
[SUCCEEDED] docs:0 (build)
[SUCCEEDED] lint:0 (build)
[SUCCEEDED] mypy:0 (build)
13 of 3 results

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/charm/launchpad-postgresql-extras/files/push-backups b/charm/launchpad-postgresql-extras/files/push-backups
2index 8a48574..9e2989d 100755
3--- a/charm/launchpad-postgresql-extras/files/push-backups
4+++ b/charm/launchpad-postgresql-extras/files/push-backups
5@@ -9,6 +9,18 @@ from argparse import ArgumentParser
6 from pathlib import Path
7
8
9+def is_primary():
10+ return (
11+ subprocess.run(
12+ ["psql", "-At", "-c", "SELECT pg_is_in_recovery();"],
13+ capture_output=True,
14+ check=True,
15+ text=True,
16+ ).stdout.strip()
17+ == "f"
18+ )
19+
20+
21 def find_latest_dumps(backups_path, database, count):
22 yield from sorted(backups_path.glob(f"{glob.escape(database)}.*.dump"))[
23 -count:
24@@ -49,6 +61,9 @@ def main():
25 parser.add_argument("databases", metavar="database", nargs="+")
26 args = parser.parse_args()
27
28+ if not is_primary():
29+ return
30+
31 command = ["rsync"]
32 if args.bwlimit is not None:
33 command.append(f"--bwlimit={args.bwlimit}")

Subscribers

People subscribed via source and target branches

to status/vote changes: