From 8ad94fb5fd25a79f5a84b45e534e8cb525e6cc70 Mon Sep 17 00:00:00 2001 From: Angelo Fausti Date: Tue, 10 Dec 2024 14:13:54 -0700 Subject: [PATCH 1/2] Build docker image with backup tools --- .github/workflows/ci.yaml | 32 ++++++++++++++++++++++++++++++++ Dockerfile | 30 ++++++++++++++++++++++++++++++ backup/backup.sh | 1 + 3 files changed, 63 insertions(+) create mode 100644 .github/workflows/ci.yaml create mode 100644 Dockerfile create mode 100644 backup/backup.sh diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..751488d --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,32 @@ +name: CI + +"on": + merge_group: {} + pull_request: {} + push: + tags: + - "*" + +jobs: + + build: + runs-on: ubuntu-latest + + # Only do Docker builds of tagged releases and pull requests from ticket + # branches. + if: > + startsWith(github.ref, 'refs/tags/') + || startsWith(github.head_ref, 'tickets/') + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - uses: lsst-sqre/build-and-push-to-ghcr@v1 + id: build + with: + image: ${{ github.repository }} + github_token: ${{ secrets.GITHUB_TOKEN }} + + - run: echo Pushed ghcr.io/${{ github.repository }}:${{ steps.build.outputs.tag }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..dd3c09c --- /dev/null +++ b/Dockerfile @@ -0,0 +1,30 @@ +# Start from the InfluxDB Enterprise Meta image +# This provides the InfluxDB Enterprise influxd-ctl command +FROM influxdb:1.11.8-meta + +# Install pipx and use it to install gsutil which is required for the backup script +# to upload the backup files to Google Cloud Storage +RUN apt-get update && \ + apt-get install -y python3 python3-pip pipx && \ + pipx install gsutil && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + +# Add pipx bin directory to PATH +ENV PATH="/root/.local/bin:$PATH" + +# Verify gsutil installation +RUN gsutil --version + +# Add the backup script +COPY backup/backup.sh /usr/local/bin/backup.sh +RUN chmod +x /usr/local/bin/backup.sh + +# Create a new user to run the backup script +RUN useradd --create-home sasquatch + +# Switch to the non-root user. +USER sasquatch + +# Set the default command for the container +CMD ["/usr/local/bin/backup.sh"] diff --git a/backup/backup.sh b/backup/backup.sh new file mode 100644 index 0000000..6be9545 --- /dev/null +++ b/backup/backup.sh @@ -0,0 +1 @@ +echo "backup" From dfd2ed26b27c570c47a8927b9070814d7ff01287 Mon Sep 17 00:00:00 2001 From: Angelo Fausti Date: Thu, 12 Dec 2024 13:12:36 -0700 Subject: [PATCH 2/2] Add backup.sh script --- backup/backup.sh | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/backup/backup.sh b/backup/backup.sh index 6be9545..7cb7a80 100644 --- a/backup/backup.sh +++ b/backup/backup.sh @@ -1 +1,23 @@ -echo "backup" +#!/bin/bash + +set -e + +# Configuration +BACKUP_DIR="/backup/sasquatch-influxdb-enterprise-backup" +GCS_BUCKET="gs://your-gcs-bucket" + +# Ensure the backup directory exists +mkdir -p "$BACKUP_DIR" + +echo "Starting InfluxDB Enterprise backup..." + +influxd-ctl -bind sasquatch-influxdb-enterprise-meta.sasquatch:8091 backup -strategy incremental "$BACKUP_DIR" + +if [ $? -eq 0 ]; then + echo "Backup completed successfully at $BACKUP_DIR." +else + echo "Backup failed!" >&2 + exit 1 +fi + +