Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 45 additions & 1 deletion helm/vitess/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,58 @@ topology:

### Enable backup/restore using Google Cloud Storage

Enabling backups creates a cron job per shard that defaults to executing once per day at midnight.
This can be overridden on a per shard level so you can stagger when backups occur.

```
topology:
cells:
...
- name: "zone1"
...
keyspaces:
- name: "unsharded_dbname"
shards:
- name: "0"
backup:
cron:
schedule: "0 1 * * *"
suspend: false
tablets:
- type: "replica"
vttablet:
replicas: 2
- name: "sharded_db"
shards:
- name: "-80"
backup:
cron:
schedule: "0 2 * * *"
suspend: false
tablets:
- type: "replica"
vttablet:
replicas: 2
- name: "80-"
backup:
cron:
schedule: "0 3 * * *"
suspend: false
tablets:
- type: "replica"
vttablet:
replicas: 2

config:
backup:
enabled: true

cron:
# the default schedule runs daily at midnight unless overridden by the individual shard
schedule: "0 0 * * *"

# if this is set to true, the cron jobs are created, but never execute
suspend: false

backup_storage_implementation: gcs

# Google Cloud Storage bucket to use for backups
Expand Down
77 changes: 77 additions & 0 deletions helm/vitess/templates/_jobs.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
###################################
# backup cron
###################################
{{ define "vttablet-backup-cron" -}}
# set tuple values to more recognizable variables
{{- $cellClean := index . 0 -}}
{{- $keyspaceClean := index . 1 -}}
{{- $shardClean := index . 2 -}}
{{- $shardName := index . 3 -}}
{{- $keyspace := index . 4 -}}
{{- $shard := index . 5 -}}
{{- $vitessTag := index . 6 -}}
{{- $backup := index . 7 -}}
{{- $namespace := index . 8 -}}
{{- $defaultVtctlclient := index . 9 }}

{{ if $backup.enabled }}
# create cron job for current shard
---
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: {{ $shardName }}-backup
labels:
app: vitess
component: vttablet
cell: {{ $cellClean | quote }}
keyspace: {{ $keyspaceClean | quote }}
shard: {{ $shardClean | quote }}

spec:
schedule: {{ $shard.backup.cron.schedule | default $backup.cron.schedule | quote }}
concurrencyPolicy: Forbid
suspend: {{ $shard.backup.cron.suspend | default $backup.cron.suspend }}
successfulJobsHistoryLimit: 3
failedJobsHistoryLimit: 20

jobTemplate:
spec:
template:
metadata:
labels:
app: vitess
component: vttablet
cell: {{ $cellClean | quote }}
keyspace: {{ $keyspaceClean | quote }}
shard: {{ $shardClean | quote }}
# pod spec
spec:
restartPolicy: Never
{{ include "pod-security" . | indent 10 }}

containers:
- name: backup
image: "vitess/vtctlclient:{{$vitessTag}}"
volumeMounts:
{{ include "user-secret-volumeMounts" $defaultVtctlclient.secrets | indent 14 }}

command: ["bash"]
args:
- "-c"
- |
set -ex

VTCTLD_SVC=vtctld.{{ $namespace }}:15999
VTCTL_EXTRA_FLAGS=({{ include "format-flags-inline" $defaultVtctlclient.extraFlags }})

vtctlclient ${VTCTL_EXTRA_FLAGS[@]} -server $VTCTLD_SVC BackupShard {{ $keyspace.name }}/{{ $shard.name }}

resources:
requests:
cpu: 10m
memory: 20Mi

{{ end }}

{{- end -}}
3 changes: 3 additions & 0 deletions helm/vitess/templates/_vttablet.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ spec:
shard: {{ $shardClean | quote }}
type: {{ $tablet.type | quote }}

# conditionally add cron job
{{ include "vttablet-backup-cron" (tuple $cellClean $keyspaceClean $shardClean $shardName $keyspace $shard $vitessTag $config.backup $namespace $defaultVtctlclient) }}

{{ if eq $tablet.type "replica" }}
---
###################################
Expand Down
9 changes: 9 additions & 0 deletions helm/vitess/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ config:

enabled: false

# this creates 1 cron job per shard that will execute a backup using vtctlclient
# on this schedule. The job itself uses almost no resources.
cron:
# the default schedule runs daily at midnight unless overridden by the individual shard
schedule: "0 0 * * *"

# if this is set to true, the cron jobs are created, but never execute
suspend: false

# choose a backup service - valid values are gcs/s3
# TODO: add file and ceph support
# backup_storage_implementation: gcs
Expand Down