Feeds:
Posts
Comments

Posts Tagged ‘restore from URL’

In my earlier articles, I explained, how to RESTORE the backup from URL using T-SQL, SQL Server Management Studio (SSMS)  from windows Azure storage and it was quite simple & easy to understand. In this article, I will explain how to RESTORE the backup from URL using PowerShell.

Pre-Requisite :

  1. Microsoft Azure – How to create storage and container
  2. SQL SERVER 2014 – How to take backup to URL (Windows Azure Storage) – PowerShell

Let me now demonstrate in few easy steps how to RESTORE backup from URL using 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 – RESTORE backup to URL :
Once you created the the Azure account, a storage and container and made sure that your backup is available in the windows Azure storage, you can RESTORE the backup from URL using given below script. In this script, first of all I declared the variables , then created credentials. After that RESTORED 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 Credential
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"

# Restore Database and move files
$newDataFilePath = New-Object Microsoft.SqlServer.Management.Smo.RelocateFile ("AdventureWorks2012_Data","C:\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\DATA\AdventureWorks2012_Data.mdf")
$newLogFilePath = New-Object Microsoft.SqlServer.Management.Smo.RelocateFile("AdventureWorks2012_Log","C:\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\DATA\AdventureWorks2012_log.ldf")
Restore-SqlDatabase -Database "AdventureWorks2012" -SqlCredential $credentialName -BackupFile $backupFile -RelocateFile @($newDataFilePath,$newLogFilePath)

How to RESTORE backup from URL (Windows Azure Storage) - PowerShell.1.1

How to RESTORE backup from URL (Windows Azure Storage) - PowerShell1.2

How to RESTORE backup from URL (Windows Azure Storage) - PowerShell1.3

As you can see, the messages show that your backup has been restored successfully.

Read Full Post »

In my earlier article, I explained, how to RESTORE the backup from URL using T-SQL and it was quite simple & easy to understand. In this article, I will explain how to how to RESTORE the backup from URL using SQL Server Management Studio (SSMS). It would be the same configuration but with the different screens & steps.

Pre-Requisite :

  1. Microsoft Azure – How to create storage and container
  2. SQL SERVER 2014 – How to take backup to URL (Windows Azure Storage) – SSMS

Let me now demonstrate in few easy steps how to RESTORE backup from URL.

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 – Create Credential :
Once you have the details of Azure account, you need to create the credential using given below script. But if you notice, this script requires two parameters namely IDENTITY & SECRET. So how will I get them? Actually IDENTITY is the storage name that we created in the Pre-Requisite article -1 (Step 4) namely ‘raresql‘ and SECRET is the primary access key that we also picked up in the Pre-Requisite article -1 (Step 5). Lets create a credential.

Note: Please skip this step if you have already created the credentials.

USE master
GO
CREATE CREDENTIAL [My_Credential]
WITH IDENTITY ='raresql'
,SECRET = '/ByNUTZqJ6EcJR/VQcNmNj+zSu++iCfbcxlyWye6Ok9uY3L5nw3XkndmAnDjiKn'
GO

Step 3 – Open Windows Azure Storage dialogue box :
Once you created the credentials, the next step is to right click on the particular database you want to restore the back up and select tasks, further you need to select Restore and Database … as shown below.

How to take backup to URL (Windows Azure Storage) - SSMS.1.1

Step 4 – Connect to Windows Azure Storage :
Now, SSMS opened the Connect Windows Azure Storage dialogue box, here you need to enter storage account (Pre-Requisite article -1 (Step 4)), account key (Pre-Requisite article -1 (Step 5)) & select / create the credentials. As we have already created the credentials in the above step, we will just select the credentials and click on Connect button as shown below.

How to take backup to URL (Windows Azure Storage) - SSMS.1.2

Step 5 – RESTORE the backup from URL :
Once you click on the Connect button, it will authenticate your account with Azure, once it will be authenticated, it will open the restore dialogue box and shows your back up. Now, you can select the back and restore it as shown below.

How to take backup to URL (Windows Azure Storage) - SSMS.1.3

How to take backup to URL (Windows Azure Storage) - SSMS.1.4

How to take backup to URL (Windows Azure Storage) - SSMS.1.5

As you can see, the messages show that your backup has been restored successfully.

Read Full Post »

In my earlier articles, I explained, how to take SQL Server backup to URL using T-SQL, SQL Server Management Studio (SSMS) & PowerShell. In this article, I will explain how to RESTORE the backup from URL using T-SQL.

Pre-Requisite :

  1. Microsoft Azure – How to create storage and container
  2. SQL SERVER 2014 – How to take backup to URL (Windows Azure Storage) – TSQL

Let me now demonstrate in few easy steps how to RESTORE backup from URL.

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 – Create Credential :
Once you have the details, you need to create the credential using given below script. But if you notice, this script requires two parameters namely IDENTITY & SECRET. So how will I get them? Actually IDENTITY is the storage name that we created in the Pre-Requisite article -1 (Step 4) namely ‘raresql‘ and SECRET is the primary access key that we also picked up in the Pre-Requisite article -1 (Step 5). Lets create a credential.

Note: Please skip this step if you have already created the credentials.

USE master
GO
CREATE CREDENTIAL [My_Credential]
WITH IDENTITY ='raresql'
,SECRET = '/ByNUTZqJ6EcJR/VQcNmNj+zSu++iCfbcxlyWye6Ok9uY3L5nw3XkndmAnDjiKn'
GO

Step 3 – RESTORE the backup from URL :
Once you created the credential, lets RESTORE the backup on URL using given below script, which requires two parameters, one is credential that we created in the above step and the second is the URL of the backup that we created in the Pre-Requisite article -2 (Step 3).

Note: Before proceeding with the Backup restore, kindly log in to your Azure account and verify the existence of the backup which URL you will mention in the below script.

USE [master]
ALTER DATABASE [AdventureWorks2012] SET SINGLE_USER WITH ROLLBACK IMMEDIATE
RESTORE DATABASE [AdventureWorks2012] FROM  URL = N'https://raresql.blob.core.windows.net/sql-backup/AdventureWorks2012_25_Dec_2014.bak'
WITH  CREDENTIAL = N'My_Credential'
,  FILE = 1,  NOUNLOAD,  STATS = 5
ALTER DATABASE [AdventureWorks2012] SET MULTI_USER
GO
--OUTPUT

How to RESTORE backup from URL (Windows Azure Storage) - TSQL

As you can see, the messages show that your backup has been restored successfully.

Read Full Post »