Skip to content

Commit

Permalink
feat: first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Reynadi531 committed Jul 15, 2024
0 parents commit 80d107d
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 0 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.env*
15 changes: 15 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
NAME_RCLONE_CONFIG=r2
BUCKET_NAME=
BACKUP_PREFIX=

# S3 Configuration Especially for Cloudflare R2
RCLONE_CONIFG_R2_TYPE=s3
RCLONE_CONIFG_R2_PROVIDER=Other
RCLONE_CONIFG_R2_ACCESS_KEY_ID=
RCLONE_CONIFG_R2_SECRET_ACCESS_KEY=
RCLONE_CONIFG_R2_ENDPOINT=
RCLONE_CONIFG_R2_ACL=private
RCLONE_CONFIG_R2_NO_CHECK_BUCKET=true

# Database Configuration
PG_URL=
49 changes: 49 additions & 0 deletions .github/workflows/dokcer_build_and_publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Build and Push Docker Image

on:
push:
branches:
- main

permissions:
contents: read
packages: write

jobs:
build-and-push:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Generate Docker Image Metadata
uses: docker/[email protected]
id: img_meta
with:
flavor: |
latest=auto
images: ghcr.io/${{ github.repository }}
tags: |
type=raw,value=latest,enable={{is_default_branch}}
- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: ./
tags: |
${{ steps.img_meta.outputs.tags }}
labels: ${{ steps.img_meta.outputs.labels }}
push: ${{ github.event_name != 'pull_request' }}
cache-from: type=gha,mode=max
cache-to: type=gha,mode=max
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.env
15 changes: 15 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM alpine:latest

RUN apk add --no-cache postgresql curl unzip

RUN curl -O https://downloads.rclone.org/rclone-current-linux-amd64.zip && \
unzip rclone-current-linux-amd64.zip

RUN cd rclone-*-linux-amd64 && \
cp rclone /usr/bin/ && \
chmod +x /usr/bin/rclone

COPY ./backup.sh /tmp/backup.sh
RUN chmod +x /tmp/backup.sh

CMD ["sh", "/tmp/backup.sh"]
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# PostgreSQL to S3 backup docker container

How to use:
```bash
docker run --rm \
-e NAME_RCLONE_CONFIG=r2 \
-e BUCKET_NAME= \
-e BACKUP_PREFIX= \
-e RCLONE_CONFIG_R2_TYPE=s3 \
-e RCLONE_CONFIG_R2_PROVIDER=Other \
-e RCLONE_CONFIG_R2_ACCESS_KEY_ID= \
-e RCLONE_CONFIG_R2_SECRET_ACCESS_KEY= \
-e RCLONE_CONFIG_R2_ENDPOINT= \
-e RCLONE_CONFIG_R2_ACL=private \
-e RCLONE_CONFIG_R2_NO_CHECK_BUCKET=true \
-e PG_URL= \
ghcr.io/reynadi/psql-s3-backup:latest
```
11 changes: 11 additions & 0 deletions backup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/env sh

export filename=$(date +"$BACKUP_PREFIX-%Y-%m-%d-%H-%M-%S.dump")

pg_dump $PG_URL --create --compress=zstd --format=c --file=/tmp/$filename

rclone copy "/tmp/$filename" $NAME_RCLONE_CONFIG:$BUCKET_NAME

rm -rf "/tmp/$filename"

exit

0 comments on commit 80d107d

Please sign in to comment.