Code Monkey home page Code Monkey logo

backup-mariadb's Introduction

kubernetes-s3-mysql-backup

kubernetes-s3-mysql-backup is a container image based on Debian Bookworm. This container is designed to run in Kubernetes as a cronjob to perform automatic backups of MariaDB databases to Amazon S3.

All changes are captured in the changelog, which adheres to Semantic Versioning.

Environment Variables

The below table lists all the Environment Variables that are configurable for kubernetes-s3-mysql-backup.

Environment Variable Purpose
AWS_ACCESS_KEY_ID (Required) AWS IAM Access Key ID.
AWS_SECRET_ACCESS_KEY (Required) AWS IAM Secret Access Key. Should have very limited IAM permissions (see below for example) and should be configured using a Secret in Kubernetes.
AWS_DEFAULT_REGION (Required) Region of the S3 Bucket (e.g. eu-west-2).
BUCKET_NAME (Required) The name of the S3 bucket.
BACKUP_PREFIX (Required) Path the backup file should be saved to in S3. E.g. /database/myblog/backups. Do not put a trailing / or specify the filename.
DB_HOST (Required) Hostname or IP address of the MySQL Host.
DB_USER (Required) Username to authenticate to the database with.
DB_PASSWORD (Required) Password to authenticate to the database with. Should be configured using a Secret in Kubernetes.

Configuring the S3 Bucket & AWS IAM User

kubernetes-s3-mysql-backup performs a backup to the same path, with the same filename each time it runs. It therefore assumes that you have Versioning enabled on your S3 Bucket. A typical setup would involve S3 Versioning, with a Lifecycle Policy.

An IAM Users should be created, with API Credentials. An example Policy to attach to the IAM User (for a minimal permissions set) is as follows:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "VisualEditor0",
            "Effect": "Allow",
            "Action": "s3:ListBucket",
            "Resource": "arn:aws:s3:::<BUCKET NAME>"
        },
        {
            "Sid": "VisualEditor1",
            "Effect": "Allow",
            "Action": [
                "s3:PutObject"
            ],
            "Resource": "arn:aws:s3:::<BUCKET NAME>/*"
        }
    ]
}

Example Kubernetes Cronjob

An example of how to schedule this container in Kubernetes as a cronjob is below. This would configure a database backup to run hourly. The AWS Secret Access Key, and Target Database Password are stored in secrets.

---
apiVersion: batch/v1
kind: CronJob
metadata:
  name: database-backup-hourly
  labels:
    app.kubernetes.io/name: maria-db-operations
spec:
  successfulJobsHistoryLimit: 3
  failedJobsHistoryLimit: 3
  concurrencyPolicy: Forbid
  jobTemplate:
    spec:
      backoffLimit: 3
      template:
        spec:
          restartPolicy: Never
          containers:
            - name: mariabd-dumper
              image: 'ghcr.io/kosh30/backup-mariadb:1.0.0'
              imagePullPolicy: IfNotPresent
              env:
                - name: DB_USER
                  valueFrom:
                    secretKeyRef:
                      name: db-cluster-secret
                      key: DB_USER
                - name: DB_PASSWORD
                  valueFrom:
                    secretKeyRef:
                      name: db-cluster-secret
                      key: DB_PASSWORD
                - name: DB_HOST
                  valueFrom:
                    configMapKeyRef:
                      key: db_address
                      name: db-cluster-config
                - name: DB_PORT
                  valueFrom:
                    configMapKeyRef:
                      key: db_port
                      name: db-cluster-config
                - name: BUCKET_NAME
                  valueFrom:
                    configMapKeyRef:
                      key: AWS_BACKUP_BUCKET_NAME
                      name: aws-backup-bucket
                - name: BACKUP_PREFIX
                  value: "mariadb"
                - name: AWS_REGION
                  valueFrom:
                    configMapKeyRef:
                      key: AWS_BACKUP_BUCKET_REGION
                      name: aws-backup-bucket
                - name: AWS_ACCESS_KEY_ID
                  valueFrom:
                    secretKeyRef:
                      key: AWS_ACCESS_KEY_ID
                      name: aws-backup-user
                - name: AWS_SECRET_ACCESS_KEY
                  valueFrom:
                    secretKeyRef:
                      key: AWS_SECRET_ACCESS_KEY
                      name: aws-backup-user
  schedule: "5 * * * *"

backup-mariadb's People

Contributors

wpoluschin avatar

Watchers

KOsh avatar

backup-mariadb's Issues

The automated release is failing 🚨

🚨 The automated release from the main branch failed. 🚨

I recommend you give this issue a high priority, so other packages depending on you can benefit from your bug fixes and new features again.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can fix this πŸ’ͺ.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the main branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here are some links that can help you:

If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


Cannot push to the Git repository.

semantic-release cannot push the version tag to the branch main on the remote Git repository with URL https://x-access-token:[secure]@github.com/kosh30/backup-mariadb.

This can be caused by:


Good luck with your project ✨

Your semantic-release bot πŸ“¦πŸš€

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Pending Approval

These branches will be created by Renovate only once you click their checkbox below.

  • chore(deps): update docker/build-push-action action to v6

Detected dependencies

dockerfile
Dockerfile
  • debian bookworm
github-actions
.github/workflows/release.yaml
  • actions/checkout v4
  • docker/setup-qemu-action v3
  • docker/setup-buildx-action v3
  • docker/metadata-action v5
  • docker/build-push-action v5
  • actions/upload-artifact v4
  • actions/checkout v4
  • actions/download-artifact v4
  • open-sauced/release v2

  • Check this box to trigger a request for Renovate to run again on this repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.