CloudBlob.BeginCreateSnapshot Method (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.

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

Usage

Visual Basic
Dim instance As CloudBlob
Dim callback As AsyncCallback
Dim state As Object
Dim returnValue As IAsyncResult

returnValue = instance.BeginCreateSnapshot(callback, state)

Syntax

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

Parameters

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

Type: System.IAsyncResult

An IAsyncResult that references the asynchronous operation.

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—asynchronously.

C# Copy Code
static void Eg_BeginCreateSnapshot1(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 for holding a snapshot of the first blob.
    CloudBlob snapShotBlob = new CloudBlob(myBlob);

    // Create the snapshot—asynchronously.
    snapShotBlob.BeginCreateSnapshot(Eg_CreateSnapshotCallback, snapShotBlob);
}

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

Remarks

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