apiVersion: cr.kanister.io/v1alpha1 kind: Blueprint metadata: name: mysql-blueprint actions: backup: outputArtifacts: mysqlBackup: # Capture the kopia snapshot information for subsequent actions # The information includes the kopia snapshot ID which is essential for restore and delete to succeed # `kopiaOutput` is the name provided to kando using `--output-name` flag kopiaSnapshot: "{{ .Phases.dumpToStore.Output.kopiaOutput }}" phases: - func: KubeTask name: dumpToStore objects: mysqlSecret: kind: Secret name: '{{ index .Object.metadata.labels "app.kubernetes.io/instance" }}' namespace: '{{ .StatefulSet.Namespace }}' args: image: ghcr.io/kanisterio/mysql-sidecar:0.108.0 namespace: "{{ .StatefulSet.Namespace }}" command: - bash - -o - errexit - -o - pipefail - -c - | backup_file_path="dump.sql" root_password="{{ index .Phases.dumpToStore.Secrets.mysqlSecret.Data "mysql-root-password" | toString }}" dump_cmd="mysqldump --column-statistics=0 -u root --password=${root_password} -h {{ index .Object.metadata.labels "app.kubernetes.io/instance" }} --single-transaction --all-databases" ${dump_cmd} | kando location push --profile '{{ toJson .Profile }}' --path "${backup_file_path}" --output-name "kopiaOutput" - restore: inputArtifactNames: # The kopia snapshot info created in backup phase can be used here # Use the `--kopia-snapshot` flag in kando to pass in `mysqlBackup.KopiaSnapshot` - mysqlBackup phases: - func: KubeTask name: restoreFromStore objects: mysqlSecret: kind: Secret name: '{{ index .Object.metadata.labels "app.kubernetes.io/instance" }}' namespace: '{{ .StatefulSet.Namespace }}' args: image: ghcr.io/kanisterio/mysql-sidecar:0.108.0 namespace: "{{ .StatefulSet.Namespace }}" command: - bash - -o - errexit - -o - pipefail - -c - | backup_file_path="dump.sql" kopia_snap='{{ .ArtifactsIn.mysqlBackup.KopiaSnapshot }}' root_password="{{ index .Phases.restoreFromStore.Secrets.mysqlSecret.Data "mysql-root-password" | toString }}" restore_cmd="mysql -u root --password=${root_password} -h {{ index .Object.metadata.labels "app.kubernetes.io/instance" }}" kando location pull --profile '{{ toJson .Profile }}' --path "${backup_file_path}" --kopia-snapshot "${kopia_snap}" - | ${restore_cmd} delete: inputArtifactNames: # The kopia snapshot info created in backup phase can be used here # Use the `--kopia-snapshot` flag in kando to pass in `mysqlBackup.KopiaSnapshot` - mysqlBackup phases: - func: KubeTask name: deleteFromStore args: image: ghcr.io/kanisterio/mysql-sidecar:0.108.0 namespace: "{{ .Namespace.Name }}" command: - bash - -o - errexit - -o - pipefail - -c - | backup_file_path="dump.sql" kopia_snap='{{ .ArtifactsIn.mysqlBackup.KopiaSnapshot }}' kando location delete --profile '{{ toJson .Profile }}' --path "${backup_file_path}" --kopia-snapshot "${kopia_snap}"