Please note: This project is currently under active development.
A Kubernetes operator for backing up various databases to different storage providers using gobackup.
GoBackup Operator allows you to define and manage backup operations for your databases in Kubernetes. It supports both immediate and scheduled backups, with configurable retention policies and compression options.
- Support for PostgreSQL databases (more coming soon)
- S3-compatible storage backends
- Scheduled backups with cron syntax
- One-time immediate backups
- Configurable retention policies (keep X most recent backups)
- Pre and post backup scripts
- Compression support
- Kubernetes cluster
- kubectl
- make
The Operator acts on the following Custom Resource Definitions (CRDs):
Backup, which defines a backup operation configuration. It references one or more database resources and storage backends, and can be configured for immediate execution or scheduled backups using cron syntax. Supports compression, retention policies, and pre/post backup scripts.
PostgreSQL, which defines a PostgreSQL database connection configuration. It specifies connection details such as host, port, username, password, database name, and optional table inclusion/exclusion filters.MySQL, which defines a MySQL database connection configuration. It specifies connection details such as host, port, username, password, database name, and optional table inclusion/exclusion filters.MariaDB, which defines a MariaDB database connection configuration. It specifies connection details such as host, port, username, password, and database name.MongoDB, which defines a MongoDB database connection configuration. It specifies connection details such as host, port, username, password, database name, authentication database, and optional oplog backup settings.Redis, which defines a Redis database connection configuration. It specifies connection details such as host, port, and optional password.MSSQL, which defines a Microsoft SQL Server database connection configuration. It specifies connection details such as host, port, username, password, database name, and optional trust server certificate settings.InfluxDB, which defines an InfluxDB database connection configuration. It specifies connection details such as host, token, bucket, organization, and optional verification settings.ETCD, which defines an etcd cluster connection configuration. It specifies endpoints and optional additional backup options.
S3, which defines an S3-compatible storage backend configuration. It specifies bucket, region, credentials, path, and other S3-specific settings for storing backups.Azure, which defines an Azure Blob Storage backend configuration. It specifies account, container, tenant ID, client ID, and client secret for authentication.GCS, which defines a Google Cloud Storage backend configuration. It specifies bucket, path, and credentials (either directly or via a secret reference).WebDAV, which defines a WebDAV storage backend configuration. It specifies root URL, username, and password for authentication.FTP, which defines an FTP storage backend configuration. It specifies host, port, username, password, path, and optional TLS settings.SFTP, which defines an SFTP storage backend configuration. It specifies host, port, username, and authentication via either password or private key with passphrase.SCP, which defines an SCP storage backend configuration. It specifies host, port, username, and authentication via either password or private key with passphrase.
Add the Helm repository and install the chart:
helm install gobackup-operator ./charts/gobackup-operator \
--namespace gobackup-operator-system \
--create-namespaceOr install with custom values:
helm install gobackup-operator ./charts/gobackup-operator \
--namespace gobackup-operator-system \
--create-namespace \
--set image.tag=v0.1.0 \
--set resources.limits.memory=256MiTo upgrade:
helm upgrade gobackup-operator ./charts/gobackup-operator \
--namespace gobackup-operator-systemTo uninstall:
helm uninstall gobackup-operator --namespace gobackup-operator-systemSee charts/gobackup-operator/README.md for all available configuration options.
- Install Custom Resource Definitions (CRDs):
make install- Deploy the operator:
make deployCreate a PostgreSQL database reference:
apiVersion: gobackup.io/v1
kind: PostgreSQL
metadata:
name: my-postgres
namespace: default
spec:
host: "postgres.default.svc.cluster.local"
port: 5432
username: "postgres"
password: "password"
database: "my_database"
# Optional: Specify tables to include
# tables:
# - table1
# - table2
# Optional: Specify tables to exclude
# excludeTables:
# - logs
# - temp_data
# Optional: Additional options for pg_dump
# additionalOptions: "--no-owner --no-acl"Create an S3 storage reference:
apiVersion: gobackup.io/v1
kind: S3
metadata:
name: my-s3
namespace: default
spec:
bucket: "my-backup-bucket"
region: "us-east-1"
# For S3-compatible services, specify the endpoint
# endpoint: "minio.example.com"
accessKeyID: "your-access-key"
secretAccessKey: "your-secret-key"
path: "backups"
# Optional: Use path-style addressing instead of virtual-hosted style
# forcePathStyle: true
# Optional: Specify storage class (e.g., "STANDARD_IA", "GLACIER")
# storageClass: "STANDARD"
# Optional: Number of retry attempts
# maxRetries: 3For an immediate, one-time backup:
apiVersion: gobackup.io/v1
kind: Backup
metadata:
name: my-immediate-backup
namespace: default
spec:
databaseRefs:
- apiGroup: gobackup.io
type: PostgreSQL
name: my-postgres
storageRefs:
- apiGroup: gobackup.io
type: S3
name: my-s3
keep: 5 # Keep last 5 backups
timeout: 300 # Timeout in seconds
compressWith:
type: gzip
# Optional: Scripts to run before/after backup
beforeScript: "echo 'Starting backup...'"
afterScript: "echo 'Backup completed!'"For scheduled backups using cron syntax:
apiVersion: gobackup.io/v1
kind: Backup
metadata:
name: my-scheduled-backup
namespace: default
spec:
databaseRefs:
- apiGroup: gobackup.io
type: PostgreSQL
name: my-postgres
storageRefs:
- apiGroup: gobackup.io
type: S3
name: my-s3
keep: 10 # Keep last 10 backups
timeout: 300 # Timeout in seconds
compressWith:
type: gzip
schedule:
cron: "0 2 * * *" # Run daily at 2am
# Optional: Configure schedule behavior
successfulJobsHistoryLimit: 3 # Keep history of last 3 successful jobs
failedJobsHistoryLimit: 1 # Keep history of last failed job
# suspend: true # Set to true to temporarily pause the scheduleThe operator follows best practices from well-known operators like prometheus-operator and ArgoCD operator, with comprehensive testing at multiple levels.
A test script is provided to quickly test the operator functionality:
./hack/test-operator.shThis script will:
- Deploy the operator
- Create example database and storage CRDs
- Create both immediate and scheduled backup jobs
- Display the status of the created resources
The operator includes a three-tier testing strategy:
Fast unit tests that don't require a Kubernetes API server:
make test-unitIntegration tests using envtest (requires test binaries):
make test-integrationE2E tests that run against a real Kubernetes cluster:
# Using an existing cluster
make test-e2e
# Or using kind (local cluster)
make kind-run
make test-e2eRun all tests including integration tests:
make testGenerate a test coverage report:
make test-coverageThis generates cover.html which you can open in a browser to see coverage details.
The test suite follows operator best practices:
- Isolation: Each test is independent and doesn't rely on other tests
- Cleanup: Resources are properly cleaned up after each test
- Fixtures: Helper functions create test resources consistently
- Coverage: Comprehensive test coverage for critical paths
For more detailed testing information, see test/README.md.
gobackup-operator/
├── .github/ # CI/CD workflows (GitHub Actions)
├── api/ # API definitions (CustomResourceDefinitions)
├── build/ # Build artifacts
├── charts/ # Helm charts
│ └── gobackup-operator/ # Main Helm chart for the operator
├── cmd/ # Entry point for the operator
├── config/
│ ├── crd/ # Custom Resource Definitions (CRDs)
│ ├── default/ # Default manifests (e.g., manager deployment, cluster roles, RBAC)
│ ├── manager/ # Operator deployment manifests (e.g., Deployment.yaml, Service.yaml)
│ ├── rbac/ # RBAC permissions (e.g., ClusterRole.yaml, Role.yaml, RoleBinding.yaml)
│ ├── samples/ # Example custom resources (CRs) to test your operator
├── example.local/ # Example manifests for testing
├── internal/
│ ├──controller/ # Controller logic
├── pkg/ # internal utils
├── Makefile # Automation scripts (build, deploy, test)
├── PROJECT # Operator SDK/Kubebuilder metadata
├── README.md # Documentation
Just create a new branch (feature-{branch-name}) and push.
When you finish your work, please send a PR.
MIT
