diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index 9381c61..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: @@ -38,9 +36,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: 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/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/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 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 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: ""