apiVersion: cr.kanister.io/v1alpha1 kind: Blueprint metadata: name: mysql-blueprint actions: backup: type: StatefulSet outputArtifacts: mysqlCloudDump: keyValue: s3path: "{{ .Phases.dumpToObjectStore.Output.s3path }}" phases: - func: KubeTask name: dumpToObjectStore objects: mysqlSecret: kind: Secret name: '{{ index .Object.metadata.labels "app.kubernetes.io/instance" }}' namespace: '{{ .StatefulSet.Namespace }}' args: image: ghcr.io/kanisterio/mysql-sidecar:0.48.0 namespace: "{{ .StatefulSet.Namespace }}" command: - bash - -o - errexit - -o - pipefail - -c - | s3_path="/mysql-backups/{{ .StatefulSet.Namespace }}/{{ index .Object.metadata.labels "app.kubernetes.io/instance" }}/{{ toDate "2006-01-02T15:04:05.999999999Z07:00" .Time | date "2006-01-02T15-04-05" }}/dump.sql.gz" root_password="{{ index .Phases.dumpToObjectStore.Secrets.mysqlSecret.Data "mysql-root-password" | toString }}" mysqldump --column-statistics=0 -u root --password=${root_password} -h {{ index .Object.metadata.labels "app.kubernetes.io/instance" }} --single-transaction --all-databases | gzip - | kando location push --profile '{{ toJson .Profile }}' --path ${s3_path} - kando output s3path ${s3_path} restore: type: StatefulSet inputArtifactNames: - mysqlCloudDump phases: - func: KubeTask name: restoreFromBlobStore objects: mysqlSecret: kind: Secret name: '{{ index .Object.metadata.labels "app.kubernetes.io/instance" }}' namespace: '{{ .StatefulSet.Namespace }}' args: image: ghcr.io/kanisterio/mysql-sidecar:0.48.0 namespace: "{{ .StatefulSet.Namespace }}" command: - bash - -o - errexit - -o - pipefail - -c - | s3_path="{{ .ArtifactsIn.mysqlCloudDump.KeyValue.s3path }}" root_password="{{ index .Phases.restoreFromBlobStore.Secrets.mysqlSecret.Data "mysql-root-password" | toString }}" kando location pull --profile '{{ toJson .Profile }}' --path ${s3_path} - | gunzip | mysql -u root --password=${root_password} -h {{ index .Object.metadata.labels "app.kubernetes.io/instance" }} delete: type: Namespace inputArtifactNames: - mysqlCloudDump phases: - func: KubeTask name: deleteFromBlobStore args: image: ghcr.io/kanisterio/mysql-sidecar:0.48.0 namespace: "{{ .Namespace.Name }}" command: - bash - -o - errexit - -o - pipefail - -c - | s3_path="{{ .ArtifactsIn.mysqlCloudDump.KeyValue.s3path }}" kando location delete --profile '{{ toJson .Profile }}' --path ${s3_path}