apiVersion: cr.kanister.io/v1alpha1 kind: Blueprint metadata: name: mysql-dep-config-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: "{{ .DeploymentConfig.Name }}" namespace: "{{ .DeploymentConfig.Namespace }}" args: image: ghcr.io/kanisterio/mysql-sidecar:0.90.0 namespace: "{{ .DeploymentConfig.Namespace }}" command: - bash - -o - errexit - -o - pipefail - -c - | backup_file_path="dump.sql" root_password="{{ index .Phases.dumpToStore.Secrets.mysqlsecret.Data "database-root-password" | toString }}" dump_cmd="mysqldump --column-statistics=0 -u root --password=${root_password} -h {{ .DeploymentConfig.Name }} --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: "{{ .DeploymentConfig.Name }}" namespace: "{{ .DeploymentConfig.Namespace }}" args: image: ghcr.io/kanisterio/mysql-sidecar:0.90.0 namespace: "{{ .DeploymentConfig.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 "database-root-password" | toString }}" restore_cmd="mysql -u root --password=${root_password} -h {{ .DeploymentConfig.Name }}" 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.90.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}"