From 0f6ecc1d9ee47933347813b461a0da631115d41c Mon Sep 17 00:00:00 2001 From: Haos Games Date: Tue, 9 Sep 2025 20:26:10 +0200 Subject: [PATCH 1/5] feat: pg_dumpall with fullBackup --- bin/backup.sh | 10 +++++++--- charts/backup/templates/backup-cronjob.yaml | 2 ++ test/helm-values-backup.yaml | 6 ++++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/bin/backup.sh b/bin/backup.sh index 0866d39..d82b11d 100755 --- a/bin/backup.sh +++ b/bin/backup.sh @@ -21,9 +21,13 @@ fi mkdir -p "/pg_dump" -# Dump individual databases directly to restic repository. -echo "Dumping database '$PGDATABASE'" -pg_dump -Fc -f /pg_dump/$PGDATABASE.dump $PGDATABASE || true # Ignore failures +if [[ "DO_FULL_BACKUP" == "true" ]]; then + echo "Dumping enitre instance" + pg_dumpall --clean --if-exists -f /pg_dump/$PGDATABASE.dumpall +else + echo "Dumping individual database '$PGDATABASE'" + pg_dump -Fc -f /pg_dump/$PGDATABASE.dump $PGDATABASE +fi # echo "Dumping global objects for '$PGHOST'" # pg_dumpall --file="/pg_dump/!globals.sql" --globals-only diff --git a/charts/backup/templates/backup-cronjob.yaml b/charts/backup/templates/backup-cronjob.yaml index 8818549..b7a9290 100644 --- a/charts/backup/templates/backup-cronjob.yaml +++ b/charts/backup/templates/backup-cronjob.yaml @@ -31,6 +31,8 @@ spec: env: - name: DB_RESTIC_NAME value: {{ $value.namespace}}-{{ $value.name }} + - name: DO_FULL_BACKUP + value: '{{ $value.fullBackup | default "false" | quote }}' - name: PGHOST valueFrom: secretKeyRef: diff --git a/test/helm-values-backup.yaml b/test/helm-values-backup.yaml index 35c5b34..c1b91f7 100644 --- a/test/helm-values-backup.yaml +++ b/test/helm-values-backup.yaml @@ -4,6 +4,12 @@ backups: dbAppConfig: cluster-example-app resticSecretName: restic-secret schedule: "*/5 * * * *" + - name: example-full + namespace: default + dbAppConfig: cluster-example-app + resticSecretName: restic-secret + schedule: "*/5 * * * *" + fullBackup: true extraVolumes: - name: restic-test-repo From 69059f76e7f259ccd76524483d94955eea31cc36 Mon Sep 17 00:00:00 2001 From: Haos Games Date: Tue, 9 Sep 2025 20:35:41 +0200 Subject: [PATCH 2/5] ci: tag branch images with branch name --- .github/workflows/ci-cd.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index 9381c61..1d31771 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -38,9 +38,9 @@ jobs: docker push ghcr.io/haosgames/restic-pg-dump-docker:${{ env.IMAGE_TAG }} # If this is the master branch, also tag as latest - if [[ "${{ github.ref }}" == "refs/heads/master" ]]; then - docker tag ghcr.io/haosgames/restic-pg-dump-docker:${{ env.IMAGE_TAG }} ghcr.io/haosgames/restic-pg-dump-docker:latest - docker push ghcr.io/haosgames/restic-pg-dump-docker:latest + if [[ "${{ github.ref_type }}" == "branch" ]]; then + docker tag ghcr.io/haosgames/restic-pg-dump-docker:${{ env.IMAGE_TAG }} ghcr.io/haosgames/restic-pg-dump-docker:${{ github.ref_name }} + docker push ghcr.io/haosgames/restic-pg-dump-docker:${{ github.ref_name }} fi push-helmchart: From c1f6d537d3bb023d1570a5ac085a476a473a3720 Mon Sep 17 00:00:00 2001 From: Haos Games Date: Tue, 9 Sep 2025 20:53:15 +0200 Subject: [PATCH 3/5] fix(fullBackup): conflicting repos --- charts/backup/values.yaml | 3 ++- test/kind-cluster.sh | 2 ++ test/restic-secret-full.yaml | 10 ++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 test/restic-secret-full.yaml diff --git a/charts/backup/values.yaml b/charts/backup/values.yaml index ac4322d..76caf63 100644 --- a/charts/backup/values.yaml +++ b/charts/backup/values.yaml @@ -4,8 +4,9 @@ # dbAppConfig: cluster-example-app # resticSecretName: restic-secret # schedule: "0 0 * * *" +# fullBackup: false image: pullPolicy: IfNotPresent - tag: latest + tag: master repo: ghcr.io/haosgames/restic-pg-dump-docker \ No newline at end of file diff --git a/test/kind-cluster.sh b/test/kind-cluster.sh index 9f1a077..71fcb7f 100644 --- a/test/kind-cluster.sh +++ b/test/kind-cluster.sh @@ -15,6 +15,7 @@ kubectl delete cluster --ignore-not-found=true cluster-example cluster-restored kubectl delete -f test/persistent-volume-claim.yaml --ignore-not-found=true kubectl delete -f test/persistent-volume.yaml --ignore-not-found=true kubectl delete -f test/restic-secret.yaml --ignore-not-found=true +kubectl delete -f test/restic-secret-full.yaml --ignore-not-found=true helm uninstall backup --ignore-not-found=true helm uninstall restore --ignore-not-found=true @@ -24,6 +25,7 @@ sleep 10 # Apply resources kubectl apply -f test/restic-secret.yaml +kubectl apply -f test/restic-secret-full.yaml kubectl apply -f test/persistent-volume.yaml kubectl apply -f test/persistent-volume-claim.yaml diff --git a/test/restic-secret-full.yaml b/test/restic-secret-full.yaml new file mode 100644 index 0000000..b068427 --- /dev/null +++ b/test/restic-secret-full.yaml @@ -0,0 +1,10 @@ +apiVersion: v1 +kind: Secret +metadata: + name: restic-secret + namespace: default +data: + RESTIC_REPOSITORY: L3Jlc3RpYy10ZXN0LXJlcG8vZnVsbC1yZXBv + RESTIC_PASSWORD: bm90aGluZwo= + AWS_ACCESS_KEY_ID: "" + AWS_SECRET_ACCESS_KEY: "" From 3aad5ac70b1cd8ea0de8315ccf60c2e8f45229b1 Mon Sep 17 00:00:00 2001 From: Haos Games Date: Tue, 9 Sep 2025 20:55:00 +0200 Subject: [PATCH 4/5] docs: restore not compatibel with pg_dumpall --- charts/restore/values.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/charts/restore/values.yaml b/charts/restore/values.yaml index 49decb5..eb675ab 100644 --- a/charts/restore/values.yaml +++ b/charts/restore/values.yaml @@ -7,6 +7,8 @@ # snapshotID: latest # jobIteration: 1 +# Restore is not supported for backups made with pg_dumpall + imagePullPolicy: IfNotPresent image: pullPolicy: IfNotPresent From 791ed49c131a07a5367106a21f6f78785952fa61 Mon Sep 17 00:00:00 2001 From: Haos Games Date: Tue, 9 Sep 2025 20:56:23 +0200 Subject: [PATCH 5/5] ci: dont build for pull requests --- .github/workflows/ci-cd.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index 1d31771..24e36fc 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -6,8 +6,6 @@ on: - '**' tags: - 'v[0-9]+.[0-9]+.[0-9]+*' - pull_request: - branches: [ master ] jobs: build-and-push: