Skip to content

Instantly share code, notes, and snippets.

@geralexgr
Created May 19, 2022 12:08
Show Gist options
  • Save geralexgr/e83184a47430befb433c024c5d2ba37b to your computer and use it in GitHub Desktop.
Save geralexgr/e83184a47430befb433c024c5d2ba37b to your computer and use it in GitHub Desktop.
trigger: none
pr: none
pool:
vmImage: windows-latest
parameters:
- name: backupfile
type: string
jobs:
- job: download
displayName: Download DB backup file
steps:
- task: AzureCLI@2
displayName: az cli download backup file from storage account
inputs:
azureSubscription: 'Azure-Service-Connection'
scriptType: 'ps'
scriptLocation: 'inlineScript'
inlineScript: |
$container_name_input = "container_name"
$saccount_name = "storage_account_name"
#$json = az storage blob list --container-name $container_name_input --account-name $saccount_name
az storage blob download --file "R:\files\${{parameters.backupfile}}" --name "${{parameters.backupfile}}" --container-name $container_name_input --account-name $saccount_name --auth-mode login
- job: restore
displayName: Restore SQL backup
dependsOn: download
steps:
- task: PowerShell@2
displayName: sqlcmd restore backup
inputs:
targetType: 'inline'
script: |
sqlcmd -q "RESTORE DATABASE [Database_Name] FROM DISK=N'R:\files\${{parameters.backupfile}}' WITH REPLACE,RECOVERY" -o R:\files\result.txt;
[string]$result = Get-Content R:\files\result.txt
if ($result.contains('successfully')) {
Write-Host "Restore was succesfull..."
}
elseif ($result.contains('terminating')) {
Write-Host "Terminating..."
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment