illuin-tech / ovh-db-backup

Backup OVH Web Cloud Databases
MIT License
3 stars 0 forks source link

OVH Database Backup

Minimal script to trigger the dump of a OVH Web Cloud Database, then wait for its availability. This script does NOT work with a Public Cloud Database).

This script is meant for usage as a Kubernetes Job triggered before deployment using Helm or Argo hooks (see example below).

Config

You need :

screenshot of OVH Manager

Credentials

You need credentials with the following authorizations :

You can create an OVH app and credentials with those permissions using following URL (adapt for API endpoints other than ovh-eu): https://eu.api.ovh.com/createToken/?GET=/hosting/privateDatabase/*/database/*/dump&GET=/hosting/privateDatabase/*/database/*/dump/*&POST=/hosting/privateDatabase/*/database/*/dump

Usage

Python

Tested with Python 3.9, 3.10 and 3.11

# optional venv
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt
export BACKUP_SERVICE_NAME=... 
export BACKUP_DATABASE_NAME=... 
export OVH_APPLICATION_KEY=... 
export OVH_APPLICATION_SECRET=... 
export OVH_CONSUMER_KEY=...
python -m ovh_db_backup

Docker

docker run --rm \
 -e BACKUP_SERVICE_NAME=... \
 -e BACKUP_DATABASE_NAME=... \
 -e OVH_APPLICATION_KEY=... \
 -e OVH_APPLICATION_SECRET=... \ 
 -e OVH_CONSUMER_KEY=... \
 ghcr.io/illuin-tech/ovh-db-backup

Kubernetes

Example job (and secret holding env vars):

---
apiVersion: v1
kind: Secret
metadata:
  name: ovh-db-backup
type: Opaque
stringData:
  BACKUP_SERVICE_NAME: ...
  BACKUP_DATABASE_NAME: ...
  OVH_APPLICATION_KEY: ...
  OVH_APPLICATION_SECRET: ...
  OVH_CONSUMER_KEY: ...
---
apiVersion: batch/v1
kind: Job
metadata:
  generateName: ovh-db-backup-
  annotations:
    # For Helm
    helm.sh/hook: post-install
    helm.sh/hook-delete-policy: before-hook-creation
    # For ArgoCD
    argocd.argoproj.io/hook: PreSync
    argocd.argoproj.io/hook-delete-policy: BeforeHookCreation
spec:
  template:
    spec:
      containers:
        - name: ovh-db-backup
          image: ghcr.io/illuin-tech/ovh-db-backup
          envFrom:
            - secretRef:
                name: ovh-db-backup
      restartPolicy: Never