Faizan
Faizan

Reputation: 105

How to resume data copy from blob using a stored continuation token?

I have been trying to copy data from blobs in multiple batches referring the below code in powershell.

    $MaxReturn = 10000
    $ContainerName = "abc"
    $Total = 0
    $Token=New-Object -TypeName 'Microsoft.WindowsAzure.Storage.Blob.BlobContinuationToken'
    $Token.NextMarker='last stored token value'
    do
     {
         $Blobs = Get-AzureStorageBlob -Container $ContainerName -MaxCount $MaxReturn  -ContinuationToken $Token
         $Total += $Blobs.Count
         if($Blobs.Length -le 0) { Break;}
         $Token = $Blobs[$blobs.Count -1].ContinuationToken;
     }
     While ($Token -ne $Null)
    Echo "Total $Total blobs in container $ContainerName"

I am saving the value of $Token after each batch in a file.I want to restart copying data from the continuation token which was last saved in the file.

To achieve this, i am manually replacing the line $Token=null with $Token="last saved token" and it throws me an error

"Cannot bind parameter 'ContinuationToken'. Cannot convert the value of type "System.String" to type "Microsoft.WindowsAzure.Storage.Blob.BlobContinuationToken".

How can i pass the value of last saved token to ContinuationToken parameter of Get-AzureStorageBlob ?

I have tried using

$Token=New-Object -TypeName Microsoft.WindowsAzure.Storage.Blob.BlobContinuationToken -NextMarker "Token value"

but it again throws an error

Cannot find type [Microsoft.WindowsAzure.Storage.Blob.BlobContinuationToken]: verify that the assembly containing this type is loaded.

Below is the powershell command to check for the same.

PS C:\Users\F\Documents> [Microsoft.WindowsAzure.Storage.Blob.BlobContinuationToken]

enter image description here

Upvotes: 0

Views: 426

Answers (2)

Faizan
Faizan

Reputation: 105

Import-Module -Name AzureRM
$MaxReturn = 10000
    $ContainerName = "abc"
    $Total = 0
    $Token=New-Object -TypeName 'Microsoft.WindowsAzure.Storage.Blob.BlobContinuationToken'
    $Token.NextMarker='last stored token value'
    do
     {
         $Blobs = Get-AzureStorageBlob -Container $ContainerName -MaxCount $MaxReturn  -ContinuationToken $Token
         $Total += $Blobs.Count
         if($Blobs.Length -le 0) { Break;}
         $Token = $Blobs[$blobs.Count -1].ContinuationToken;
     }
     While ($Token -ne $Null)
    Echo "Total $Total blobs in container $ContainerName"

I needed to serialize the continuation token and import the AzureRM module to get the copy process start from the last value of continuation token. Thanks for all the help.

Upvotes: 1

Vad
Vad

Reputation: 743

This parameter is used for batches as i can find in documentation. So you can't convert it from any type to [Microsoft.WindowsAzure.Storage.Blob.BlobContinuationToken] May be you find some help in link below, but i find that object have methods to write and read from xml file,so it's chanse to convert a serializable continuation token into its XML representation and then read it. link1

Upvotes: 0

Related Questions