8 Commits

Author SHA1 Message Date
271420955f chore(deps): update actions/checkout action to v6 (#27)
All checks were successful
CD / Check changes (push) Successful in 12s
CD / Create tag (push) Successful in 8s
CD / Build and push (amd64) (push) Successful in 25s
CD / Build and push (arm64) (push) Successful in 1m8s
CD / Create manifest (push) Successful in 10s
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [actions/checkout](https://github.com/actions/checkout) | action | major | `v5` -> `v6` |

---

### Release Notes

<details>
<summary>actions/checkout (actions/checkout)</summary>

### [`v6`](https://github.com/actions/checkout/blob/HEAD/CHANGELOG.md#v600)

[Compare Source](https://github.com/actions/checkout/compare/v5...v6)

- Persist creds to a separate file by [@&#8203;ericsciple](https://github.com/ericsciple) in [#&#8203;2286](https://github.com/actions/checkout/pull/2286)
- Update README to include Node.js 24 support details and requirements by [@&#8203;salmanmkc](https://github.com/salmanmkc) in [#&#8203;2248](https://github.com/actions/checkout/pull/2248)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0Mi4xMC41IiwidXBkYXRlZEluVmVyIjoiNDIuMjYuMTEiLCJ0YXJnZXRCcmFuY2giOiJtYWluIiwibGFiZWxzIjpbImFjdGlvbiIsImRlcHMiXX0=-->

Reviewed-on: #27
Reviewed-by: t.behrendt <t.behrendt@noreply.localhost>
Co-authored-by: Renovate Bot <renovate@t00n.de>
Co-committed-by: Renovate Bot <renovate@t00n.de>
2025-12-21 10:44:24 +01:00
69738fe88d chore(deps): update docker/setup-buildx-action digest to 8d2750c (#30)
All checks were successful
CD / Check changes (push) Successful in 7s
CD / Create tag (push) Successful in 8s
CD / Build and push (amd64) (push) Successful in 28s
CD / Build and push (arm64) (push) Successful in 2m58s
CD / Create manifest (push) Successful in 43s
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [docker/setup-buildx-action](https://github.com/docker/setup-buildx-action) ([changelog](e468171a9d..8d2750c68a)) | action | digest | `e468171` -> `8d2750c` |

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0Mi40Ny4wIiwidXBkYXRlZEluVmVyIjoiNDIuNDcuMCIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiYWN0aW9uIiwiZGVwcyJdfQ==-->

Reviewed-on: #30
Reviewed-by: t.behrendt <t.behrendt@noreply.localhost>
Co-authored-by: Renovate Bot <renovate@t00n.de>
Co-committed-by: Renovate Bot <renovate@t00n.de>
2025-12-19 19:36:16 +01:00
eca220e960 chore(deps): update docker.io/alpine docker tag to v3.23 (#28)
All checks were successful
CD / Check changes (push) Successful in 12s
CD / Create tag (push) Successful in 8s
CD / Build and push (amd64) (push) Successful in 27s
CD / Build and push (arm64) (push) Successful in 1m9s
CD / Create manifest (push) Successful in 41s
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| docker.io/alpine | final | minor | `3.22` -> `3.23` |

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0Mi4yNi4xMSIsInVwZGF0ZWRJblZlciI6IjQyLjI2LjExIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6W119-->

Reviewed-on: #28
Reviewed-by: t.behrendt <t.behrendt@noreply.localhost>
Co-authored-by: Renovate Bot <renovate@t00n.de>
Co-committed-by: Renovate Bot <renovate@t00n.de>
2025-12-12 12:58:18 +01:00
6a017eccd1 chore(deps): update actions/checkout digest to 93cb6ef (#26)
All checks were successful
CD / Check changes (push) Successful in 6s
CD / Build and push (amd64) (push) Successful in 30s
CD / Create tag (push) Successful in 35s
CD / Build and push (arm64) (push) Successful in 2m22s
CD / Create manifest (push) Successful in 26s
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [actions/checkout](https://github.com/actions/checkout) | action | digest | `08c6903` -> `93cb6ef` |

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0Mi4xLjMiLCJ1cGRhdGVkSW5WZXIiOiI0Mi4xLjMiLCJ0YXJnZXRCcmFuY2giOiJtYWluIiwibGFiZWxzIjpbImFjdGlvbiIsImRlcHMiXX0=-->

Reviewed-on: #26
Reviewed-by: t.behrendt <t.behrendt@noreply.localhost>
Co-authored-by: Renovate Bot <renovate@t00n.de>
Co-committed-by: Renovate Bot <renovate@t00n.de>
2025-11-22 15:14:17 +01:00
e9b14ec1b2 fix: pull postgresql18-client from edge instead of docker image (#25)
All checks were successful
CD / Check changes (push) Successful in 6s
CD / Create tag (push) Successful in 7s
CD / Build and push (amd64) (push) Successful in 26s
CD / Build and push (arm64) (push) Successful in 1m29s
CD / Create manifest (push) Successful in 8s
Reviewed-on: #25
Co-authored-by: Timo Behrendt <t.behrendt@t00n.de>
Co-committed-by: Timo Behrendt <t.behrendt@t00n.de>
2025-11-14 17:46:26 +01:00
ca022fe596 refactor: pull postgresql client from upstream docker image (#24)
All checks were successful
CD / Check changes (push) Successful in 11s
CD / Create tag (push) Successful in 7s
CD / Build and push (amd64) (push) Successful in 32s
CD / Build and push (arm64) (push) Successful in 1m58s
CD / Create manifest (push) Successful in 20s
Reviewed-on: #24
Co-authored-by: Timo Behrendt <t.behrendt@t00n.de>
Co-committed-by: Timo Behrendt <t.behrendt@t00n.de>
2025-11-14 17:35:04 +01:00
725ef9000b chore(deps): pin dependencies (#21)
All checks were successful
CD / Check changes (push) Successful in 6s
CD / Create tag (push) Successful in 7s
CD / Build and push (amd64) (push) Successful in 25s
CD / Build and push (arm64) (push) Successful in 6m2s
CD / Create manifest (push) Successful in 8s
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [actions/checkout](https://github.com/actions/checkout) | action | pinDigest |  -> `08c6903` |
| alpine | final | pinDigest |  -> `4b7ce07` |
| [docker/build-push-action](https://github.com/docker/build-push-action) | action | pinDigest |  -> `2634353` |
| [docker/login-action](https://github.com/docker/login-action) | action | pinDigest |  -> `5e57cd1` |
| [docker/setup-buildx-action](https://github.com/docker/setup-buildx-action) | action | pinDigest |  -> `e468171` |
| [dorny/paths-filter](https://github.com/dorny/paths-filter) | action | pinDigest |  -> `de90cc6` |

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

👻 **Immortal**: This PR will be recreated if closed unmerged. Get [config help](https://github.com/renovatebot/renovate/discussions) if that's undesired.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0Mi4xLjMiLCJ1cGRhdGVkSW5WZXIiOiI0Mi4xLjMiLCJ0YXJnZXRCcmFuY2giOiJtYWluIiwibGFiZWxzIjpbImFjdGlvbiIsImRlcHMiXX0=-->

Reviewed-on: #21
Reviewed-by: t.behrendt <t.behrendt@noreply.localhost>
Co-authored-by: Renovate Bot <renovate@t00n.de>
Co-committed-by: Renovate Bot <renovate@t00n.de>
2025-11-14 17:07:53 +01:00
5b4b09d150 ci(renovate): switch to shared configs (#20)
Some checks failed
CD / Check changes (push) Successful in 6s
CD / Create tag (push) Successful in 23s
CD / Build and push (amd64) (push) Successful in 40s
CD / Build and push (arm64) (push) Has been cancelled
CD / Create manifest (push) Has been cancelled
Reviewed-on: #20
Co-authored-by: Timo Behrendt <t.behrendt@t00n.de>
Co-committed-by: Timo Behrendt <t.behrendt@t00n.de>
2025-11-14 17:01:09 +01:00
6 changed files with 28 additions and 256 deletions

View File

@@ -16,11 +16,11 @@ jobs:
changes: ${{ steps.filter.outputs.code }} changes: ${{ steps.filter.outputs.code }}
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v5 uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6
- name: Get changed files - name: Get changed files
id: filter id: filter
uses: dorny/paths-filter@v3 uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3
with: with:
filters: | filters: |
code: code:
@@ -42,9 +42,9 @@ jobs:
- ubuntu-latest - ubuntu-latest
- linux_${{ matrix.arch }} - linux_${{ matrix.arch }}
steps: steps:
- uses: actions/checkout@v5 - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6
- uses: docker/setup-buildx-action@v3 - uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3
- uses: docker/login-action@v3 - uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3
with: with:
registry: ${{ env.DOCKER_REGISTRY }} registry: ${{ env.DOCKER_REGISTRY }}
username: ${{ secrets.REGISTRY_USER }} username: ${{ secrets.REGISTRY_USER }}
@@ -53,7 +53,7 @@ jobs:
run: | run: |
echo REPO_NAME=$(echo ${GITHUB_REPOSITORY} | awk -F"/" '{print $2}' | tr '[:upper:]' '[:lower:]') >> $GITHUB_OUTPUT echo REPO_NAME=$(echo ${GITHUB_REPOSITORY} | awk -F"/" '{print $2}' | tr '[:upper:]' '[:lower:]') >> $GITHUB_OUTPUT
echo REPO_VERSION=$(git describe --tags --always | sed 's/^v//') >> $GITHUB_OUTPUT echo REPO_VERSION=$(git describe --tags --always | sed 's/^v//') >> $GITHUB_OUTPUT
- uses: docker/build-push-action@v6 - uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6
with: with:
context: . context: .
file: ./Dockerfile file: ./Dockerfile
@@ -72,7 +72,7 @@ jobs:
outputs: outputs:
tag: ${{ steps.tag.outputs.new-tag }} tag: ${{ steps.tag.outputs.new-tag }}
steps: steps:
- uses: actions/checkout@v5 - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6
with: with:
fetch-depth: 0 fetch-depth: 0
- uses: https://gitea.t000-n.de/t.behrendt/conventional-semantic-git-tag-increment@0.0.2 - uses: https://gitea.t000-n.de/t.behrendt/conventional-semantic-git-tag-increment@0.0.2
@@ -93,12 +93,12 @@ jobs:
- create_tag - create_tag
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v5 - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6
- id: meta - id: meta
run: | run: |
echo REPO_NAME=$(echo ${GITHUB_REPOSITORY} | awk -F"/" '{print $2}' | tr '[:upper:]' '[:lower:]') >> $GITHUB_OUTPUT echo REPO_NAME=$(echo ${GITHUB_REPOSITORY} | awk -F"/" '{print $2}' | tr '[:upper:]' '[:lower:]') >> $GITHUB_OUTPUT
echo REPO_VERSION=$(git describe --tags --always | sed 's/^v//') >> $GITHUB_OUTPUT echo REPO_VERSION=$(git describe --tags --always | sed 's/^v//') >> $GITHUB_OUTPUT
- uses: docker/login-action@v3 - uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3
with: with:
registry: ${{ env.DOCKER_REGISTRY }} registry: ${{ env.DOCKER_REGISTRY }}
username: ${{ secrets.REGISTRY_USER }} username: ${{ secrets.REGISTRY_USER }}

View File

@@ -10,10 +10,10 @@ jobs:
- ubuntu-latest - ubuntu-latest
- linux_amd64 - linux_amd64
steps: steps:
- uses: actions/checkout@v5 - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6
- uses: docker/setup-buildx-action@v3 - uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3
- name: Build image - name: Build image
uses: docker/build-push-action@v6 uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6
with: with:
context: . context: .
file: ./Dockerfile file: ./Dockerfile
@@ -27,7 +27,7 @@ jobs:
name: Check syntax name: Check syntax
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v5 - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6
- name: Check syntax - name: Check syntax
run: | run: |
bash -n src/backup.sh bash -n src/backup.sh

View File

@@ -1,15 +1,15 @@
FROM alpine:3.22 FROM docker.io/alpine:3.23@sha256:51183f2cfa6320055da30872f211093f9ff1d3cf06f39a0bdb212314c5dc7375 AS base
# Add edge repository for postgresql18-client
RUN echo '@edge http://dl-cdn.alpinelinux.org/alpine/edge/main' >> /etc/apk/repositories
RUN apk update && apk add --no-cache \ RUN apk update && apk add --no-cache \
bash \ bash \
curl \ curl \
restic \ restic \
postgresql-client \ jq \
jq postgresql18-client@edge \
libpq@edge
RUN curl -O https://dl.min.io/client/mc/release/linux-amd64/mc \
&& chmod +x mc \
&& mv mc /usr/local/bin/
WORKDIR /app WORKDIR /app

133
README.md
View File

@@ -11,7 +11,7 @@ BackupSidecar is configured through environment variables. Below is a breakdown
These variables apply to both backup and restore operations. These variables apply to both backup and restore operations.
- **`OPERATION_MODE`** _(optional)_ - Defines the operation type (`backup` or `restore`). Defaults to `backup`. - **`OPERATION_MODE`** _(optional)_ - Defines the operation type (`backup` or `restore`). Defaults to `backup`.
- **`BACKUP_MODE`** _(optional)_ - Defines the backup type (`directory`, `postgres`, or `s3`). Defaults to `directory`. - **`BACKUP_MODE`** _(optional)_ - Defines the backup type (`directory` or `postgres`). Defaults to `directory`.
- **`RESTIC_PASSWORD`** _(required)_ - The encryption password for Restic. - **`RESTIC_PASSWORD`** _(required)_ - The encryption password for Restic.
- **`RESTIC_REPOSITORY`** _(required)_ - The URI of the Restic repository (e.g., `rest:http://your-rest-server:8000/backup`). - **`RESTIC_REPOSITORY`** _(required)_ - The URI of the Restic repository (e.g., `rest:http://your-rest-server:8000/backup`).
- **`RESTIC_REST_USERNAME`** _(optional)_ - The username for REST server authentication. - **`RESTIC_REST_USERNAME`** _(optional)_ - The username for REST server authentication.
@@ -55,22 +55,6 @@ For `postgres` mode, the following database-related variables are required:
- **`RESTORE_SNAPSHOT_ID`** _(optional)_ - The specific snapshot ID to restore (defaults to `latest`). - **`RESTORE_SNAPSHOT_ID`** _(optional)_ - The specific snapshot ID to restore (defaults to `latest`).
- **`PSQL_ARGS`** _(optional)_ - Additional flags for `psql` (e.g., `--single-transaction`). - **`PSQL_ARGS`** _(optional)_ - Additional flags for `psql` (e.g., `--single-transaction`).
### S3 Operations
For `s3` mode, the following S3-related variables are required:
**Common Variables:**
- **`S3_BUCKET`** _(required)_ - The name of the S3 bucket to backup/restore.
- **`S3_ENDPOINT`** _(required)_ - The S3 endpoint URL (e.g., `http://minio:9000` for MinIO).
- **`MINIO_ACCESS_KEY`** _(required)_ - The MinIO access key for S3 authentication.
- **`MINIO_SECRET_KEY`** _(required)_ - The MinIO secret key for S3 authentication.
- **`S3_PREFIX`** _(optional)_ - Optional path prefix within the bucket to backup/restore.
**Restore-Specific Variables:**
- **`RESTORE_SNAPSHOT_ID`** _(optional)_ - The specific snapshot ID to restore (defaults to `latest`).
## Dependencies ## Dependencies
Ensure the following commands are available in the container: Ensure the following commands are available in the container:
@@ -80,7 +64,6 @@ Ensure the following commands are available in the container:
- `jq` - `jq`
- `pg_dump` _(only required for PostgreSQL backup operations)_ - `pg_dump` _(only required for PostgreSQL backup operations)_
- `psql` _(only required for PostgreSQL restore operations)_ - `psql` _(only required for PostgreSQL restore operations)_
- `mc` _(only required for S3 operations)_
## Usage ## Usage
@@ -253,120 +236,6 @@ spec:
value: "Database Restore Notification" value: "Database Restore Notification"
``` ```
Example Kubernetes Job manifest for running BackupSidecar to backup an S3 bucket:
```yaml
apiVersion: batch/v1
kind: Job
metadata:
name: backupsidecar-s3-backup
namespace: authentik
spec:
backoffLimit: 3
activeDeadlineSeconds: 600
template:
spec:
restartPolicy: OnFailure
containers:
- name: backupsidecar
image: backupsidecar:latest
env:
- name: OPERATION_MODE
value: "backup"
- name: BACKUP_MODE
value: "s3"
- name: S3_BUCKET
value: "my-bucket"
- name: S3_ENDPOINT
value: "http://minio:9000"
- name: S3_PREFIX
value: "data" # optional
- name: MINIO_ACCESS_KEY
valueFrom:
secretKeyRef:
name: minio-secret
key: access_key
- name: MINIO_SECRET_KEY
valueFrom:
secretKeyRef:
name: minio-secret
key: secret_key
- name: RESTIC_REPOSITORY
value: "rest:http://rest-server:8000/backup"
- name: RESTIC_PASSWORD
valueFrom:
secretKeyRef:
name: backupsidecar-secret
key: restic_password
- name: GOTIFYHOST
value: "http://gotify.example.com"
- name: GOTIFYTOKEN
valueFrom:
secretKeyRef:
name: backupsidecar-secret
key: gotify_token
- name: GOTIFYTOPIC
value: "S3 Backup Notification"
```
Example Kubernetes Job manifest for running BackupSidecar to restore an S3 bucket:
```yaml
apiVersion: batch/v1
kind: Job
metadata:
name: backupsidecar-s3-restore
namespace: authentik
spec:
backoffLimit: 3
activeDeadlineSeconds: 600
template:
spec:
restartPolicy: OnFailure
containers:
- name: backupsidecar
image: backupsidecar:latest
env:
- name: OPERATION_MODE
value: "restore"
- name: BACKUP_MODE
value: "s3"
- name: S3_BUCKET
value: "my-bucket"
- name: S3_ENDPOINT
value: "http://minio:9000"
- name: S3_PREFIX
value: "data" # optional
- name: RESTORE_SNAPSHOT_ID
value: "abc123def456" # optional, defaults to latest
- name: MINIO_ACCESS_KEY
valueFrom:
secretKeyRef:
name: minio-secret
key: access_key
- name: MINIO_SECRET_KEY
valueFrom:
secretKeyRef:
name: minio-secret
key: secret_key
- name: RESTIC_REPOSITORY
value: "rest:http://rest-server:8000/backup"
- name: RESTIC_PASSWORD
valueFrom:
secretKeyRef:
name: backupsidecar-secret
key: restic_password
- name: GOTIFYHOST
value: "http://gotify.example.com"
- name: GOTIFYTOKEN
valueFrom:
secretKeyRef:
name: backupsidecar-secret
key: gotify_token
- name: GOTIFYTOPIC
value: "S3 Restore Notification"
```
## Notifications ## Notifications
The script can send success or failure notifications via Gotify when enabled. To enable notifications, set `ENABLE_GOTIFY=true` and provide the required Gotify configuration variables (`GOTIFYHOST`, `GOTIFYTOKEN`, `GOTIFYTOPIC`). When notifications are disabled, backup status messages are still logged to the console. The script can send success or failure notifications via Gotify when enabled. To enable notifications, set `ENABLE_GOTIFY=true` and provide the required Gotify configuration variables (`GOTIFYHOST`, `GOTIFYTOKEN`, `GOTIFYTOPIC`). When notifications are disabled, backup status messages are still logged to the console.

View File

@@ -1,3 +1,7 @@
{ {
"$schema": "https://docs.renovatebot.com/renovate-schema.json" "$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [
"local>t.behrendt/renovate-configs:common",
"local>t.behrendt/renovate-configs:action"
]
} }

View File

@@ -24,7 +24,7 @@ OPERATION_MODE="${OPERATION_MODE:-backup}"
####################################### #######################################
# Determine backup mode from the environment only. # Determine backup mode from the environment only.
# Valid values: "directory", "postgres", or "s3". # Valid values: "directory" or "postgres".
# Default to "directory" if not provided. # Default to "directory" if not provided.
####################################### #######################################
BACKUP_MODE="${BACKUP_MODE:-directory}" BACKUP_MODE="${BACKUP_MODE:-directory}"
@@ -39,8 +39,6 @@ if [ "$BACKUP_MODE" = "postgres" ]; then
elif [ "$OPERATION_MODE" = "restore" ]; then elif [ "$OPERATION_MODE" = "restore" ]; then
REQUIRED_CMDS+=(psql) REQUIRED_CMDS+=(psql)
fi fi
elif [ "$BACKUP_MODE" = "s3" ]; then
REQUIRED_CMDS+=(mc)
fi fi
for cmd in "${REQUIRED_CMDS[@]}"; do for cmd in "${REQUIRED_CMDS[@]}"; do
@@ -109,16 +107,8 @@ case "$BACKUP_MODE" in
fi fi
fi fi
;; ;;
s3)
: "${S3_BUCKET:?Environment variable S3_BUCKET is not set (required for S3 mode)}"
: "${S3_ENDPOINT:?Environment variable S3_ENDPOINT is not set (required for S3 mode)}"
: "${MINIO_ACCESS_KEY:?Environment variable MINIO_ACCESS_KEY is not set (required for S3 mode)}"
: "${MINIO_SECRET_KEY:?Environment variable MINIO_SECRET_KEY is not set (required for S3 mode)}"
# Optional: S3 path prefix
: "${S3_PREFIX:=}"
;;
*) *)
echo "Error: Unknown backup mode '$BACKUP_MODE'. Valid modes are 'directory', 'postgres', and 's3'." >&2 echo "Error: Unknown backup mode '$BACKUP_MODE'. Valid modes are 'directory' and 'postgres'." >&2
exit 1 exit 1
;; ;;
esac esac
@@ -297,91 +287,6 @@ restore_postgres() {
fi fi
} }
#######################################
# Backup an S3 bucket.
# Syncs the S3 bucket to a temporary directory and then backs it up.
#######################################
backup_s3() {
log "Starting S3 backup for bucket '${S3_BUCKET}' at endpoint '${S3_ENDPOINT}'"
# Create a temporary directory for the S3 sync.
TEMP_BACKUP_DIR=$(mktemp -d)
log "Created temporary directory: ${TEMP_BACKUP_DIR}"
# Configure MinIO Client alias
local alias_name="backupsidecar"
if ! mc alias set "${alias_name}" "${S3_ENDPOINT}" "${MINIO_ACCESS_KEY}" "${MINIO_SECRET_KEY}"; then
local msg="Failed to configure MinIO client alias"
log "$msg"
send_notification "$msg"
exit 1
fi
# Build S3 path
local s3_path="${alias_name}/${S3_BUCKET}"
if [ -n "${S3_PREFIX}" ]; then
s3_path="${s3_path}/${S3_PREFIX}"
fi
log "Syncing S3 bucket from ${s3_path} to ${TEMP_BACKUP_DIR}..."
if mc mirror "${s3_path}" "${TEMP_BACKUP_DIR}" --remove; then
log "S3 sync completed successfully."
else
local exit_code=$?
local msg="S3 sync failed with error code ${exit_code}"
log "$msg"
send_notification "$msg"
exit "$exit_code"
fi
# Back up the directory containing the S3 content.
run_restic_backup "${TEMP_BACKUP_DIR}"
}
#######################################
# Restore an S3 bucket.
# Restores the S3 content from the backup and syncs it back to S3.
#######################################
restore_s3() {
local snapshot_id="${RESTORE_SNAPSHOT_ID:-latest}"
log "Starting S3 restore for bucket '${S3_BUCKET}' at endpoint '${S3_ENDPOINT}'"
# Create a temporary directory for the restore.
TEMP_RESTORE_DIR=$(mktemp -d)
log "Created temporary directory: ${TEMP_RESTORE_DIR}"
# Restore the backup to the temporary directory
run_restic_restore "${TEMP_RESTORE_DIR}" "${snapshot_id}"
# Configure MinIO Client alias
local alias_name="backupsidecar"
if ! mc alias set "${alias_name}" "${S3_ENDPOINT}" "${MINIO_ACCESS_KEY}" "${MINIO_SECRET_KEY}"; then
local msg="Failed to configure MinIO client alias"
log "$msg"
send_notification "$msg"
exit 1
fi
# Build S3 path
local s3_path="${alias_name}/${S3_BUCKET}"
if [ -n "${S3_PREFIX}" ]; then
s3_path="${s3_path}/${S3_PREFIX}"
fi
log "Syncing restored content from ${TEMP_RESTORE_DIR} to ${s3_path}..."
if mc mirror "${TEMP_RESTORE_DIR}" "${s3_path}" --remove; then
local msg="S3 restore completed successfully"
log "$msg"
send_notification "$msg"
else
local exit_code=$?
local msg="S3 restore failed with error code ${exit_code}"
log "$msg"
send_notification "$msg"
exit "$exit_code"
fi
}
####################################### #######################################
# Cleanup temporary resources. # Cleanup temporary resources.
####################################### #######################################
@@ -410,9 +315,6 @@ main() {
postgres) postgres)
backup_postgres backup_postgres
;; ;;
s3)
backup_s3
;;
esac esac
;; ;;
restore) restore)
@@ -423,9 +325,6 @@ main() {
postgres) postgres)
restore_postgres restore_postgres
;; ;;
s3)
restore_s3
;;
esac esac
;; ;;
esac esac