Esporta (0) Stampa
Espandi tutto

Metodo CloudDrive.Snapshot

Creates a snapshot of the page blob associated with this Windows Azure drive.

Spazio dei nomi: Microsoft.WindowsAzure.StorageClient
Assembly: Microsoft.WindowsAzure.CloudDrive (in microsoft.windowsazure.clouddrive.dll)

'Utilizzo
Dim instance As CloudDrive
Dim returnValue As Uri

returnValue = instance.Snapshot

public:
Uri^ Snapshot ()
public Uri Snapshot ()
public function Snapshot () : Uri

Valore restituito

Returns a URI to the newly created snapshot.

The following code example creates a writable drive and writes some data to it, then takes a snapshot of the drive and mounts the snapshot as a read-only drive.

public void MountDriveAndSnapshot()
{
    // Get a reference to the local resource.
    LocalResource localResource = RoleEnvironment.GetLocalResource("LocalDriveCache");

    // Initialize the drive cache.
    CloudDrive.InitializeCache(localResource.RootPath, localResource.MaximumSizeInMegabytes);

    // Use the storage emulator.
    CloudStorageAccount storageAccount = CloudStorageAccount.DevelopmentStorageAccount;

    // Create the Blob service client.
    CloudBlobClient client = storageAccount.CreateCloudBlobClient();

    // Create the container for the drive if it does not already exist.
    CloudBlobContainer container = new CloudBlobContainer("mydrives", client);
    container.CreateIfNotExist();

    // Create and mount a drive, allocating some cache space.
    CloudDrive drive1 = new CloudDrive(container.GetPageBlobReference("myvhd" + Path.GetRandomFileName()).Uri, storageAccount.Credentials);
    drive1.Create(50);
    string driveLetter = drive1.Mount((int)Math.Round((double)localResource.MaximumSizeInMegabytes / 2), DriveMountOptions.None);

    // Write to the drive.
    for (int i = 0; i < 1000; i++)
    {
        System.IO.File.WriteAllText(driveLetter + "\\" + i.ToString() + ".txt", "Test");
    }

    // Snapshot the drive.
    Uri snapshotUri = drive1.Snapshot();

    // Mount a drive using the snapshot.
    CloudDrive drive2 = new CloudDrive(snapshotUri, storageAccount.Credentials);
    driveLetter = drive2.Mount((int)Math.Round((double)localResource.MaximumSizeInMegabytes / 2), DriveMountOptions.None);

    // List each drive letter and associated page blob.
    foreach (var item in CloudDrive.GetMountedDrives())
    {
        System.Diagnostics.Debug.WriteLine("Drive letter: " + item.Key);
        System.Diagnostics.Debug.WriteLine("Page blob URI: " + item.Value);
    }
}

A snapshot is a read-only copy of a blob taken at a given point in time. Taking a snapshot of the page blob that backs a Windows Azure drive is a useful way to back up the drive.

A snapshot of a blob has the same name as the base blob from which the snapshot is taken, with a DateTime value appended to indicate the time at which the snapshot was taken. For example, if the page blob URI is http://storagesample.core.blob.windows.net/mydrives/myvhd, the snapshot URI will be similar to http://storagesample.core.blob.windows.net/mydrives/myvhd?snapshot=!2011-03-09T01:42:34.9360000Z.

You can use a snapshot to create and mount a read-only drive.

Each time you call the Snapshot method, a new snapshot is created. Snapshots persist unless they are explicitly deleted.

ImportantImportante
Note that when you create a snapshot of a page blob, you are not charged for pages in the snapshot as long as the base page blob and the snapshot remain the same. When a page in the base blob is updated, that page diverges from the page that exists in the snapshot, and you are subsequently charged for both unique pages. To avoid unexpected charges, delete unnecessary snapshots after updating the base blob.


Tutti i membri statici pubblici (Shared in Visual Basic) di questo tipo sono thread-safe. I membri di istanza non sono garantiti come thread-safe.

Piattaforme di sviluppo

Windows XP Home Edition, Windows XP Professional, Windows Server 2003, Windows Server 2008 e Windows 2000

Piattaforme di destinazione

Aggiunte alla community

Microsoft sta conducendo un sondaggio in linea per comprendere l'opinione degli utenti in merito al sito Web di MSDN. Se si sceglie di partecipare, quando si lascia il sito Web di MSDN verrà visualizzato il sondaggio in linea.

Si desidera partecipare?
Mostra:
© 2014 Microsoft