CloudBlob.BeginCreateSnapshot Method (NameValueCollection, BlobRequestOptions, AsyncCallback, Object)

Storage Client Library NET API

[This topic is part of the Microsoft Azure Storage Client Library 1.7, which has been deprecated. See Storage Client Library for the latest version.]

Begins an asynchronous operation to create a snapshot of the blob, adding metadata to it that you specify, and using a conditional request based on the BlobRequestOptions that you specify.

Namespace: Microsoft.WindowsAzure.StorageClient
Assembly: Microsoft.WindowsAzure.StorageClient (in Microsoft.WindowsAzure.StorageClient.dll)

Usage

Visual Basic
Dim instance As CloudBlob
Dim metadata As NameValueCollection
Dim options As BlobRequestOptions
Dim callback As AsyncCallback
Dim state As Object
Dim returnValue As IAsyncResult

returnValue = instance.BeginCreateSnapshot(metadata, options, callback, state)

Syntax

Visual Basic
Public Function BeginCreateSnapshot ( _
	metadata As NameValueCollection, _
	options As BlobRequestOptions, _
	callback As AsyncCallback, _
	state As Object _
) As IAsyncResult
C#
public IAsyncResult BeginCreateSnapshot (
	NameValueCollection metadata,
	BlobRequestOptions options,
	AsyncCallback callback,
	Object state
)
C++
public:
IAsyncResult^ BeginCreateSnapshot (
	NameValueCollection^ metadata, 
	BlobRequestOptions^ options, 
	AsyncCallback^ callback, 
	Object^ state
)
J#
JScript

Parameters

metadata

Metadata associated with the blob.

options

Type: Microsoft.WindowsAzure.StorageClient.BlobRequestOptions

An object that specifies any additional options for the request.

callback

Type: System.AsyncCallback

The callback delegate that will receive notification when the asynchronous operation completes.

state

Type: System.Object

A user-defined object that will be passed to the callback delegate.

Return Value

Returns IAsyncResult.

Example

The following code example creates a blob reference, then instantiates it in the cloud by uploading the contents of a local text file to it, and finally creates a snapshot of it, supplying specified metadata—using a conditional, asynchronous request.

C# Copy Code
private void Eg_BeginCreateSnapshot3(Uri blobEndpoint, string accountName, string accountKey)
{
    // Create a service client for credentialed access to the Blob service.
    CloudBlobClient blobClient =
        new CloudBlobClient(blobEndpoint,
            new StorageCredentialsAccountAndKey(accountName, accountKey));

    // Create a blob reference.
    CloudBlob myBlob = blobClient.GetBlobReference("mycontainer/myblob.txt");

    // Use the blob reference to create and initialize an actual blob in the cloud.
    myBlob.UploadFile("C:\\somefile.txt");

    // Create another blob reference; this one to hold a snapshot of the blob.
    CloudBlob snapShotBlob = new CloudBlob(myBlob);

    // Set metadata values for the snapshot.
    // Create a collection of three Name/Value pairs.
    NameValueCollection ssMData = new NameValueCollection(3);

    ssMData.Add("Member", "No");
    ssMData.Add("System", "Abstract");
    ssMData.Add("Status", "Published");

    // Set options for the request.
    // E.g., Create a snapshot only if the blob has changed during the past week.
    System.TimeSpan interval = new TimeSpan(7, 0, 0, 0);
    BlobRequestOptions options = new BlobRequestOptions();
    options.CopySourceAccessCondition = AccessCondition.IfModifiedSince(DateTime.UtcNow.Subtract(interval));

    snapShotBlob.BeginCreateSnapshot(ssMData, options, Eg_CreateSnapshotCallback, snapShotBlob);
}

private void Eg_CreateSnapshotCallback(IAsyncResult result)
{
    CloudBlob blobSnapShot = (CloudBlob)result.AsyncState;
    blobSnapShot.EndCreateSnapshot(result);                 //End the operation.
}

Remarks

The metadata parameter specifies a name-value pair associated with the blob. The snapshot is created with the specified metadata, and the base blob’s metadata is not copied.

Snapshots provide read-only versions of blobs. Once a snapshot has been created, it can be read, copied, or deleted, but not modified.

A snapshot is itself a blob, and can be represented by a CloudBlob object or one of its derived objects.

When you create a snapshot, the blob's Snapshot property returns a DateTime value that uniquely identifies the snapshot relative to its base blob. You can use this value to perform further operations on the snapshot.

You can use a snapshot to restore a blob to an earlier version by copying over a base blob with its snapshot.

Copying Blob Properties and Metadata

When you create a snapshot of a blob, the following system properties are copied to the snapshot with the same values:

The base blob's committed block list is also copied to the snapshot, if the blob is a block blob. Any uncommitted blocks are not copied.

The metadata associated with the base blob is copied to the snapshot.

Specifying an Access Condition

You can specify an access condition so that the snapshot is created only if a condition is met. To specify an access condition, use the AccessCondition property. If the specified condition is not met, the snapshot is not created, and the Blob service returns status code HTTPStatusCode.PreconditionFailed.

Copying Snapshots

When a base blob is copied, any snapshots of the base blob are not copied to the destination blob. When a destination blob is overwritten with a copy, any snapshots associated with the destination blob stay intact under its name.

You can copy a snapshot blob over its base blob to restore an earlier version of a blob. The snapshot remains, but the base blob is overwritten with a copy that can be both read and written.


Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Platforms

Development Platforms

Windows Vista, Windows 7, Windows Server 2008, Windows 8.1, Windows Server 2012 R2, Windows 8 and Windows Server 2012

Change History

See Also