-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 80d107d
Showing
7 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.env* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |