SQL Server backup to URL is a new feature shipped with SQL Server 2014. I explained how to take backup via SSMS (SQL Server Management Studio) in my earlier article. Today, I will demonstrate how to take SQL Server backup to URL via PowerShell.
Let me now demonstrate in few easy steps how to take backup to URL via PowerShell.
Step 1 – Create Account, storage & container :
First of all, you need to create a windows Azure account, a storage and a container as explained in this article.
Step 2 – Take backup to URL :
Once you created the the Azure account, a storage and container, you can take a backup on URL using given below script. In this script, first of all I declared the variables , then created credentials. After that take the backup as shown below. Rest of the script is self explanatory. Make sure that you have downloaded PowerShell Extensions for SQL Server in case you are using Windows PowerShell ISE instead of Windows PowerShell.
#Import sql module Import-Module sqlps #Create & set variables $serverPath = "SQLSERVER:\SQL\WIN-KK48BQM9IS0\DEFAULT" $storageAccount = "raresql" $storageKey = "/ByNUTZqJ6EcJR/VQcNmNj+zSu++iCfbcxlyWye6Ok9uhsd5jsd62sjhsd7ksdh7sksdsdlhsd4bsdhsd52ksd==" $secureString = convertto-securestring $storageKey -asplaintext -force $credentialName = "My_Credential" # Create Credentials New-sqlcredential -Name $credentialName -Identity $storageAccount -Secret $secureString # Set SQL Server instance Path CD $serverPath # Set the backup file name $backupFile = "https://raresql.blob.core.windows.net/sql-backup/AdventureWorks2012_25_Dec_2014.bak" # Take Backup Database to URL Backup-SqlDatabase -Database "AdventureWorks2012" -backupFile $backupFile -SqlCredential $credentialName -CompressionOption On
Step 3 – Verify backup to URL :
Lets go to the container inside the storage and check if the backup is available there or NOT because we saw the confirmation report in the above step.
Now, you can see above that your backup is available on Azure, what you have taken in the above step.