-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
16 changed files
with
179 additions
and
13 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 |
---|---|---|
|
@@ -4,9 +4,6 @@ on: | |
push: | ||
branches: | ||
- 'main' | ||
# - 'staging' | ||
# - 'dev' | ||
# - 'hotfix/**' | ||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
@@ -43,3 +40,48 @@ jobs: | |
file: Dockerfile | ||
push: true | ||
tags: quay.io/denbicloud/cron-backup:${{ steps.tag.outputs.TAG }} | ||
|
||
special_builds: | ||
runs-on: ubuntu-latest | ||
needs: build | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
type: [ postgresql, mysql, mongodb ] | ||
steps: | ||
|
||
- name: Workflow run cleanup action | ||
uses: rokroskar/[email protected] | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
- uses: actions/checkout@master | ||
- name: Extract branch name | ||
shell: bash | ||
run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})" | ||
id: extract_branch | ||
|
||
- name: Set tag | ||
run: sed 's/\//-/g' <<< "::set-output name=TAG::${{ steps.extract_branch.outputs.branch }}" | ||
id: tag | ||
- name: Get tag | ||
run: echo "The selected tag is ${{ steps.tag.outputs.TAG }}" | ||
|
||
- | ||
name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
- name: Login to Quay.io | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: quay.io | ||
username: ${{ secrets.QUAY_USERNAME }} | ||
password: ${{ secrets.QUAY_TOKEN }} | ||
- name: Build and publish image to Quay | ||
uses: docker/build-push-action@v5 | ||
env: | ||
BASE_TAG: ${{ steps.tag.outputs.TAG }} | ||
with: | ||
file: ${{matrix.type}}/Dockerfile | ||
context: ${{matrix.type}} | ||
push: true | ||
build-args: BASE_TAG | ||
tags: quay.io/denbicloud/cron-backup:${{matrix.type}}-${{ steps.tag.outputs.TAG }} |
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
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
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 @@ | ||
#!/bin/bash | ||
|
||
# Set KUMA_STATUS_ENDPOINT variable from environment or default to empty string | ||
KUMA_STATUS_ENDPOINT=${KUMA_STATUS_ENDPOINT:-} | ||
|
||
if [ -z "$KUMA_STATUS_ENDPOINT" ]; then | ||
echo "INFO: KUMA_STATUS_ENDPOINT is not set. Skipping." | ||
else | ||
# Use curl to make a GET request to the status endpoint | ||
response=$(curl -s -X GET "$KUMA_STATUS_ENDPOINT") | ||
|
||
# Check if the request was successful | ||
if [ $? -eq 0 ]; then | ||
echo "Status endpoint responded successfully: $response" | ||
else | ||
echo "Error: Failed to push status from $KUMA_STATUS_ENDPOINT. Status code: $?" | ||
fi | ||
fi |
Empty file.
Empty file.
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
Empty file.
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
Empty file.
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 |
---|---|---|
@@ -1,18 +1,62 @@ | ||
#!/bin/sh | ||
|
||
# Define a logging function | ||
log() { | ||
echo "[$(date +"%Y-%m-%d %H:%M:%S")] - $1" | ||
} | ||
|
||
touch ~/.pgpass | ||
log "Creating ~/.pgpass file" | ||
echo ${POSTGRES_HOST}:${POSTGRES_PORT}:${POSTGRES_DB}:${POSTGRES_USER}:${POSTGRES_PASSWORD} > ~/.pgpass | ||
chmod 600 ~/.pgpass | ||
# Set up an error trap to exit the script on any error | ||
trap 'log "Error occurred, exiting script"; exit 1' ERR | ||
|
||
# Create the ~/.pgpass file if it doesn't exist | ||
if [ ! -f "~/.pgpass" ]; then | ||
touch ~/.pgpass | ||
log "Created ~/.pgpass file" | ||
fi | ||
|
||
# Set the PostgreSQL connection details as environment variables | ||
POSTGRES_HOST=${POSTGRES_HOST:-} | ||
POSTGRES_PORT=${POSTGRES_PORT:-5432} # default to 5432 if not set | ||
POSTGRES_DB=${POSTGRES_DB:-} | ||
POSTGRES_USER=${POSTGRES_USER:-} | ||
POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-} | ||
|
||
# Check that all required environment variables are set | ||
if [ -z "$POSTGRES_HOST" ] || [ -z "$POSTGRES_DB" ] || [ -z "$POSTGRES_USER" ] || [ -z "$POSTGRES_PASSWORD" ]; then | ||
log "Error: Missing PostgreSQL connection details, exiting script" | ||
exit 1 | ||
fi | ||
|
||
# Set the PGPASSFILE environment variable to point to the ~/.pgpass file | ||
export PGPASSFILE='/root/.pgpass' | ||
|
||
# Write the PostgreSQL connection details to the ~/.pgpass file | ||
echo "${POSTGRES_HOST}:${POSTGRES_PORT}:${POSTGRES_DB}:${POSTGRES_USER}:${POSTGRES_PASSWORD}" > ~/.pgpass | ||
|
||
# Set permissions on the ~/.pgpass file | ||
chmod 600 ~/.pgpass | ||
|
||
# Create a timestamp for the backup file name | ||
NOW=$(date '+%y-%m-%d-%H%M') | ||
FILE=/etc/backup/${POSTGRES_DB}-${NOW}.dump.gz | ||
log "Create Backup $FILE" | ||
|
||
pg_dump -h ${POSTGRES_HOST} -U ${POSTGRES_USER} ${POSTGRES_DB} -Z 9 > $FILE | ||
# Define the backup file path and name | ||
FILE="/etc/backup/${POSTGRES_DB}-${NOW}.dump.gz" | ||
|
||
log "Creating Backup $FILE" | ||
|
||
# Perform the PostgreSQL database dump | ||
pg_dump -h "${POSTGRES_HOST}" -U "${POSTGRES_USER}" "${POSTGRES_DB}" -Z 9 > "$FILE" | ||
|
||
# Check if the backup file is not empty and has a reasonable size | ||
MIN_SIZE=$((1024 * 10)) # 10KB minimum size | ||
if [ ! -s "$FILE" ] || [ $(stat -c%s "$FILE") -lt $MIN_SIZE ]; then | ||
log "Backup file $FILE is too small (${MIN_SIZE}B required), aborting script" | ||
exit 1 | ||
fi | ||
|
||
# Send a notification using the notify_uptime_kuma.sh script | ||
if ! /notify_uptime_kuma.sh; then | ||
log "Failed to send notification" | ||
fi | ||
|
||
log "Backup completed successfully" |
Empty file.
Empty file.
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
Empty file.
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,19 @@ | ||
#!/bin/bash | ||
|
||
# Set S3_KUMA_STATUS_ENDPOINT variable from environment or default to empty string | ||
S3_KUMA_STATUS_ENDPOINT=${S3_KUMA_STATUS_ENDPOINT:-} | ||
|
||
if [ -z "$S3_KUMA_STATUS_ENDPOINT" ]; then | ||
echo "INFO: S3_KUMA_STATUS_ENDPOINT is not set. Skipping." | ||
else | ||
# Use curl to make a POST request to the status endpoint | ||
response=$(curl -s -X POST \\ | ||
"$S3_KUMA_STATUS_ENDPOINT") | ||
|
||
# Check if the request was successful | ||
if [ $? -eq 0 ]; then | ||
echo "Status endpoint responded successfully: $response" | ||
else | ||
echo "Error: Failed to send status update to $S3_KUMA_STATUS_ENDPOINT. Status code: $?" | ||
fi | ||
fi |