Monday, September 19, 2011

How to migrate Azure Storage data after upgrade to Azure SDK 1.5

After Azure SDK 1.5 installation complete you will see that all your data disappeared from Storage. This is because installation will create new database in your SQL Express instance. But all your data still there.

Microsoft SQL Server Management Studio

As you can see I had previous database created 2009-09-19.

So you need to move your data into new database. To do it open new query editing window and copy/paste/run the script below (double-click to Select all).

And don't forget to change names of the databases!
BEGIN TRANSACTION
GO

INSERT INTO [DevelopmentStorageDb20110816].[dbo].[BlobContainer]
 ([AccountName]
 ,[ContainerName]
 ,[LastModificationTime]
 ,[ServiceMetadata]
 ,[Metadata])
SELECT [AccountName]
      ,[ContainerName]
      ,[LastModificationTime]
      ,[ServiceMetadata]
      ,[Metadata]
  FROM [DevelopmentStorageDb20090919].[dbo].[BlobContainer]
GO

INSERT INTO [DevelopmentStorageDb20110816].[dbo].[BlockData]
 ([AccountName]
 ,[ContainerName]
 ,[BlobName]
 ,[VersionTimestamp]
 ,[IsCommitted]
 ,[BlockId]
 ,[Length]
 ,[Data])
SELECT [AccountName]
      ,[ContainerName]
      ,[BlobName]
      ,[VersionTimestamp]
      ,[IsCommitted]
      ,[BlockId]
      ,[Length]
      ,[Data]
  FROM [DevelopmentStorageDb20090919].[dbo].[BlockData]
GO

INSERT INTO [DevelopmentStorageDb20110816].[dbo].[Blob]
 ([AccountName]
 ,[ContainerName]
 ,[BlobName]
 ,[VersionTimestamp]
 ,[BlobType]
 ,[CreationTime]
 ,[LastModificationTime]
 ,[ContentLength]
 ,[ContentType]
 ,[ContentMD5]
 ,[ServiceMetadata]
 ,[Metadata]
 ,[LeaseId]
 ,[LeaseTypeInt]
 ,[LeaseDuration]
 ,[LeaseEndTime]
 ,[SequenceNumber]
 ,[IsCommitted]
 ,[HasBlock]
 ,[UncommittedBlockIdLength]
 ,[MaxSize]
 ,[FileName])
SELECT [AccountName]
      ,[ContainerName]
      ,[BlobName]
      ,[VersionTimestamp]
      ,[BlobType]
      ,[CreationTime]
      ,[LastModificationTime]
      ,[ContentLength]
      ,[ContentType]
      ,[ContentMD5]
      ,[ServiceMetadata]
      ,[Metadata]
      ,[LeaseId]
      ,[LeaseTypeInt]
      ,[LeaseDuration]
      ,[LeaseEndTime]
      ,[SequenceNumber]
      ,[IsCommitted]
      ,[HasBlock]
      ,[UncommittedBlockIdLength]
      ,[MaxSize]
      ,[FileName]
  FROM [DevelopmentStorageDb20090919].[dbo].[Blob]
GO

INSERT INTO [DevelopmentStorageDb20110816].[dbo].[CommittedBlock] 
 ([AccountName]
 ,[ContainerName]
 ,[BlobName]
 ,[VersionTimestamp]
 ,[Offset]
 ,[BlockId]
 ,[Length]
 ,[BlockVersion])
SELECT [AccountName]
      ,[ContainerName]
      ,[BlobName]
      ,[VersionTimestamp]
      ,[Offset]
      ,[BlockId]
      ,[Length]
      ,[BlockVersion]
  FROM [DevelopmentStorageDb20090919].[dbo].[CommittedBlock]
GO

INSERT INTO [DevelopmentStorageDb20110816].[dbo].[Page]  
 ([AccountName]
      ,[ContainerName]
      ,[BlobName]
      ,[VersionTimestamp]
      ,[StartOffset]
      ,[EndOffset]
      ,[FileOffset])
SELECT [AccountName]
      ,[ContainerName]
      ,[BlobName]
      ,[VersionTimestamp]
      ,[StartOffset]
      ,[EndOffset]
      ,[FileOffset]
  FROM [DevelopmentStorageDb20090919].[dbo].[Page]
GO

INSERT INTO [DevelopmentStorageDb20110816].[dbo].[CurrentPage]  
 ([AccountName]
 ,[ContainerName]
 ,[BlobName]
 ,[VersionTimestamp]
 ,[StartOffset]
 ,[EndOffset])
SELECT [AccountName]
      ,[ContainerName]
      ,[BlobName]
      ,[VersionTimestamp]
      ,[StartOffset]
      ,[EndOffset]
  FROM [DevelopmentStorageDb20090919].[dbo].[CurrentPage]
GO

INSERT INTO [DevelopmentStorageDb20110816].[dbo].[QueueContainer]
 ([AccountName]
 ,[QueueName]
 ,[LastModificationTime]
 ,[ServiceMetadata]
 ,[Metadata])
SELECT [AccountName]
      ,[QueueName]
      ,[LastModificationTime]
      ,[ServiceMetadata]
      ,[Metadata]
  FROM [DevelopmentStorageDb20090919].[dbo].[QueueContainer]
GO

INSERT INTO [DevelopmentStorageDb20110816].[dbo].[QueueMessage]  
 ([AccountName]
 ,[QueueName]
 ,[VisibilityStartTime]
 ,[MessageId]
 ,[ExpiryTime]
 ,[InsertionTime]
 ,[DequeueCount]
 ,[Data])
SELECT [AccountName]
      ,[QueueName]
      ,[VisibilityStartTime]
      ,[MessageId]
      ,[ExpiryTime]
      ,[InsertionTime]
      ,[DequeueCount]
      ,[Data]
  FROM [DevelopmentStorageDb20090919].[dbo].[QueueMessage]
GO

INSERT INTO [DevelopmentStorageDb20110816].[dbo].[TableContainer]
 ([AccountName]
 ,[TableName]
 ,[LastModificationTime]
 ,[ServiceMetadata]
 ,[Metadata]
 ,[SchemaXml])
SELECT [AccountName]
      ,[TableName]
      ,[LastModificationTime]
      ,[ServiceMetadata]
      ,[Metadata]
      ,[SchemaXml]
  FROM [DevelopmentStorageDb20090919].[dbo].[TableContainer]
GO

INSERT INTO [DevelopmentStorageDb20110816].[dbo].[TableRow]  
 ([AccountName]
 ,[TableName]
 ,[PartitionKey]
 ,[RowKey]
 ,[Timestamp]
 ,[Data])
SELECT [AccountName]
      ,[TableName]
      ,[PartitionKey]
      ,[RowKey]
      ,[Timestamp]
      ,[Data]
  FROM [DevelopmentStorageDb20090919].[dbo].[TableRow]
GO

COMMIT TRANSACTION
GO