-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Backup/Restore SQL Server using Kopia Artifacts (#1188)
* Added mssql blueprint using kopiaSnapshot as output * updating kando command with kopia snapshot * fixing kopia path while restoring * tar/untar using kando streaming * review fixes
- Loading branch information
1 parent
13e0bbe
commit eb2799d
Showing
2 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
apiVersion: cr.kanister.io/v1alpha1 | ||
kind: Blueprint | ||
metadata: | ||
name: mssql-blueprint | ||
actions: | ||
backup: | ||
outputArtifacts: | ||
mssqlCloudDump: | ||
This comment has been minimized.
Sorry, something went wrong. |
||
kopiaSnapshot: "{{ .Phases.dumpToObjectStore.Output.kopiaOutput }}" | ||
phases: | ||
- func: KubeTask | ||
name: dumpToObjectStore | ||
This comment has been minimized.
Sorry, something went wrong.
pavannd1
Contributor
|
||
objects: | ||
mssql: | ||
kind: Secret | ||
name: '{{ index .Object.metadata.labels "app" }}' | ||
namespace: '{{ .Deployment.Namespace }}' | ||
args: | ||
image: ghcr.io/kanisterio/mssql-tools:0.71.0 | ||
command: | ||
- bash | ||
- -o | ||
- errexit | ||
- -o | ||
- pipefail | ||
- -c | ||
- | | ||
kopiaPath="backup.tar.gz" | ||
root_password="{{ index .Phases.dumpToObjectStore.Secrets.mssql.Data "SA_PASSWORD" | toString }}" | ||
root_uname="sa" | ||
mssql_pod="{{ index .Deployment.Namespace }}/{{ index .Deployment.Pods 0 }}" | ||
server_name="{{ index .Deployment.Name }}.{{index .Deployment.Namespace}}.svc.cluster.local" | ||
databases=$(/opt/mssql-tools/bin/sqlcmd -S ${server_name} -U ${root_uname} -P ${root_password} -Q "SET NOCOUNT ON; SELECT name FROM sys.databases WHERE name NOT IN ('master','model','msdb','tempdb')" -b -s "," -h -1) | ||
for database in $databases; do /opt/mssql-tools/bin/sqlcmd -S ${server_name} -U ${root_uname} -P ${root_password} -Q "backup database $database to disk = '/tmp/backup/$database.bak' with format;"; done | ||
This comment has been minimized.
Sorry, something went wrong.
pavannd1
Contributor
|
||
kubectl cp ${mssql_pod}:/tmp/backup /tmp/backup | ||
tar zcvf - -C /tmp/ backup | kando location push --profile '{{ toJson .Profile }}' --path "${kopiaPath}" --output-name "kopiaOutput" - | ||
kubectl exec -it {{ index .Deployment.Pods 0 }} -n {{ index .Deployment.Namespace }} -- rm -r /tmp/backup | ||
This comment has been minimized.
Sorry, something went wrong. |
||
restore: | ||
inputArtifactNames: | ||
- mssqlCloudDump | ||
phases: | ||
- func: KubeTask | ||
name: restoreFromObjectStore | ||
objects: | ||
mssql: | ||
kind: Secret | ||
name: '{{ index .Object.metadata.labels "app" }}' | ||
namespace: '{{ .Deployment.Namespace }}' | ||
args: | ||
image: ghcr.io/kanisterio/mssql-tools:0.71.0 | ||
command: | ||
- bash | ||
- -o | ||
- errexit | ||
- -o | ||
- pipefail | ||
- -c | ||
- | | ||
kopiaPath="backup.tar.gz" | ||
kopia_snap='{{ .ArtifactsIn.mssqlCloudDump.KopiaSnapshot }}' | ||
root_password="{{ index .Phases.restoreFromObjectStore.Secrets.mssql.Data "SA_PASSWORD" | toString }}" | ||
root_uname="sa" | ||
mssql_pod="{{ index .Deployment.Namespace }}/{{ index .Deployment.Pods 0 }}" | ||
server_name="{{ index .Deployment.Name }}.{{ index .Deployment.Namespace }}.svc.cluster.local" | ||
kando location pull --profile '{{ toJson .Profile }}' --path "${kopiaPath}" --kopia-snapshot ${kopia_snap} - | tar zxvf - -C /tmp/ | ||
kubectl cp /tmp/backup ${mssql_pod}:/tmp/backup | ||
backup_files=$(ls /tmp/backup) | ||
for script in $backup_files; do database="$(cut -d'.' -f1 <<<"$script")"; /opt/mssql-tools/bin/sqlcmd -S ${server_name} -U ${root_uname} -P ${root_password} -Q "restore database $database from disk = '/tmp/backup/$script' with replace"; done | ||
kubectl exec -it {{ index .Deployment.Pods 0 }} -n {{ index .Deployment.Namespace }} -- rm -r /tmp/backup | ||
delete: | ||
inputArtifactNames: | ||
- mssqlCloudDump | ||
phases: | ||
- func: KubeTask | ||
name: deleteFromBlobStore | ||
args: | ||
image: ghcr.io/kanisterio/mssql-tools:0.71.0 | ||
command: | ||
- bash | ||
- -o | ||
- errexit | ||
- -o | ||
- pipefail | ||
- -c | ||
- | | ||
kopiaPath="backup.tar.gz" | ||
kopia_snap='{{ .ArtifactsIn.mssqlCloudDump.KopiaSnapshot }}' | ||
kando location delete --profile '{{ toJson .Profile }}' --path ${kopiaPath} --kopia-snapshot "${kopia_snap}" |
This should work with file stores as well which means this is not necessarily a cloud dump.
Would make it something like
snapshotInfo