Book Image

SQL Server 2014 with PowerShell v5 Cookbook

By : Donabel Santos
Book Image

SQL Server 2014 with PowerShell v5 Cookbook

By: Donabel Santos

Overview of this book

Table of Contents (21 chapters)
SQL Server 2014 with PowerShell v5 Cookbook
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Backing up database to Azure Blob storage


In this recipe we will back up a local database to Azure.

Getting ready

Before we can back up our databases to Microsoft Azure Blob storage, there are a few things that need to be in place.

  1. First, your Azure storage needs to be set up.

  2. Second, you need to have a container.

  3. Third, you need to know what your Azure storage access keys are. You can get them from your Azure storage page. The link should be at the bottom of the storage page screen, as shown in the following screenshot:

How to do it...

The steps to back up your database to Azure Blob storage are as follows:

  1. Open PowerShell ISE as administrator.

  2. Import the SQLPS module as follows:

    #import SQL Server module
    Import-Module SQLPS -DisableNameChecking
  3. If one does not already exist, create a credential to use for the remote backup:

    $instanceName = "localhost"
    $AzureStorageAccount = "replaceThisWithAzureStorageAccount"
    $storageKey = "replaceThisWithYourStorageKey"
    $secureString = ConvertTo-SecureString $storageKey...