Azure and Citrix MCS Snapshot Script

Various conversations on twitter have triggered this blogpost.

For those of you working in Azure and using MCS to provision servers, this will come in handy.

So; MCS in azure will give you an option to rollback to your previous image and you can also use snapshots with managed disks; its not always the solution though.

Earlier version of CVAD didn’t support managed disks, so in this scenario rollback to anything prior to your last MCS update isn’t easy.

I wrote a script a while back to handle this and wanted to share it.

The script will copy the vhd file from your master VM into a different storage container in the same storage account and give it a date and time suffix. Using this format you have full rollback opportunities between any previous versions of the image.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#Azure Subscription ID
$subID = ""

#Storage Account Name
$storAccount = ""

#Storage Access Key
$accessKey = ""

#Blob Container Name with Source VHD
$storContainer = ""

#Destination Container , Same Storage Account
$destContainer = ""

#Master Image VHD Name
$vhdName = ""

#MCS Disk Name Prefix
$MCSPrefix = ""

#Destination VHD Name
$formattedDate = Get-Date -Format "yyyyMMdd-HHmm"
$destVhdName = ($vhdName -replace $vhdName, "") + $MCSPrefix + $formattedDate + ".vhd"

Login-AzureRmAccount

Select-AzureRmSubscription -SubscriptionId $subID

# VHD blob to copy #
$blobName = $vhdName

# Source Storage Account Information
$sourceStorageAccountName = $storAccount
$sourceKey = $accessKey
$sourceContext = New-AzureStorageContext –StorageAccountName $sourceStorageAccountName -StorageAccountKey $sourceKey
$sourceContainer = $storContainer

# Destination Storage Account Information
$destinationStorageAccountName = $storAccount
$destinationKey = $accessKey
$destinationContext = New-AzureStorageContext –StorageAccountName $destinationStorageAccountName -StorageAccountKey $destinationKey

# Create the destination container
$destinationContainerName = $destContainer
New-AzureStorageContainer -Name $destContainer -Context $destinationContext

# Copy the blob
$blobCopy = Start-AzureStorageBlobCopy -DestContainer $destinationContainerName -DestContext $destinationContext -DestBlob $destVhdName -SrcBlob $vhdName -Context $sourceContext -SrcContainer $sourceContainer

# Retrieve the current status of the copy operation
$status = $blobCopy | Get-AzureStorageBlobCopyState

# Print out status
$status

# Loop until copy complete
While($status.Status -eq "Pending"){
$status = $blobCopy | Get-AzureStorageBlobCopyState
Start-Sleep 10

# Print out status
$status }

Leave a Reply

Your email address will not be published. Required fields are marked *