From 48c60dd8789ee3ce0e4719613bea762fb2871c91 Mon Sep 17 00:00:00 2001 From: nihaldivyam Date: Wed, 17 Jul 2024 18:10:34 +0530 Subject: [PATCH] 1.0.2 --- .github/workflows/logical-backup.yml | 54 ++++++++++++++++++++++++++++ logical-backup/dump.sh | 8 ++--- 2 files changed, 58 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/logical-backup.yml diff --git a/.github/workflows/logical-backup.yml b/.github/workflows/logical-backup.yml new file mode 100644 index 00000000..253d9c8e --- /dev/null +++ b/.github/workflows/logical-backup.yml @@ -0,0 +1,54 @@ +name: Docker Image CI + +on: + push: + branches: [ "add-feature-logicalbackup" ] + +jobs: + docker: + runs-on: ubuntu-latest + steps: + + - name: Checkout + uses: actions/checkout@v3.5.2 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v1 + + - name: Docker Login to GitHub Container Registry + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} # github username or org + password: ${{ secrets.GITHUB_TOKEN }} # github actions builtin token. repo has to have pkg access. + + - name: Prepare + id: prep + run: | + echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ') + + - name: Build and push + id: docker_build + uses: docker/build-push-action@v4.0.0 + with: + context: . + file: ./logical-backup/Dockerfile + platforms: linux/amd64 + pull: true # Pull new version of base image, always; avoid bit-rot + push: true + labels: | + org.opencontainers.image.title=${{ github.repository }} + org.opencontainers.image.description=${{ github.event.repository.description }} + org.opencontainers.image.url=${{ github.event.repository.html_url }} + org.opencontainers.image.source=${{ github.event.repository.clone_url }} + org.opencontainers.image.created=${{ steps.prep.outputs.created }} + org.opencontainers.image.revision=${{ github.sha }} + org.opencontainers.image.licenses=${{ github.event.repository.license.spdx_id }} + cache-from: type=gha # all-automatic Github Actions caching + cache-to: type=gha,mode=max + build-args: | + tags: ghcr.io/obmondo/logical-backup:latest \ No newline at end of file diff --git a/logical-backup/dump.sh b/logical-backup/dump.sh index f9de352c..c822fbb9 100755 --- a/logical-backup/dump.sh +++ b/logical-backup/dump.sh @@ -7,7 +7,7 @@ IFS=$'\n\t' # PGHOST PGPASSWORD ALL_DB_SIZE_QUERY="select sum(pg_database_size(datname)::numeric) from pg_database;" -PG_BIN=/usr/lib/postgresql/$PG_VERSION/bin +PG_BIN=/usr/bin DUMP_SIZE_COEFF=5 ERRORCOUNT=0 POSTGRES_OPERATOR=spilo @@ -21,7 +21,7 @@ function estimate_size { function dump { echo "Taking dump of ${PGDATABASE} from ${PGHOST}" # settings are taken from the environment - "$PG_BIN"/pg_dump + "$PG_BIN"/pg_dumpall --exclude-database='postgres' } function compress { @@ -42,7 +42,7 @@ function aws_delete_objects { [[ ! -z "${LOGICAL_BACKUP_S3_ENDPOINT}" ]] && args+=("--endpoint-url=${LOGICAL_BACKUP_S3_ENDPOINT}") [[ ! -z "${LOGICAL_BACKUP_S3_REGION}" ]] && args+=("--region=${LOGICAL_BACKUP_S3_REGION}") - aws s3api delete-objects "${args[@]}" --delete Objects=["$(printf {Key=%q}, "$@")"],Quiet=true + aws s3api delete-objects "${args[@]}" --delete Objects=["$(printf \{Key=%q\}, "$@")"],Quiet=true } export -f aws_delete_objects @@ -129,4 +129,4 @@ else [[ ${PIPESTATUS[0]} != 0 || ${PIPESTATUS[1]} != 0 || ${PIPESTATUS[2]} != 0 ]] && (( ERRORCOUNT += 1 )) set +x exit $ERRORCOUNT -fi +fi \ No newline at end of file