Azure blob Storage Snapshot

Source: Internet
Author: User

A backup of a user's virtual machine hard disk is a very important part of the customer's deployment of cloud applications.

There are multiple platforms for backup methods:

    1. Capture Image: The virtual machine system disk and data disk can be captured in capture mode (PowerShell command for Save-azurevmimage). However, this approach takes up too much space and the number of image capture is limited. So it is not the preferred scheme.
    2. Copy the hard disk VHD file: Azcopy The VM's VHD to the container of the partial blob. This approach is also very space-intensive. Not suitable for large-scale backup, only suitable for use during disaster recovery.
    3. VHD file for blob snapshot: Blob snapshot for VHD files of VMs via BLOB snapshot feature. This saves space, is easy to operate, and is a very good way for a virtual machine to be backed up.

Azure's snapshot is billed based on the actual usage space. Because snapshot follows the "copy-on-write" approach, if the content of the base blob does not change, there is no content in snapshot, and only the base BLOB changes, snapshot will copy the old content from the base blob.

The specific billing methods are as follows:

Case one: If the content of the snapshot is the same as the content of the base blob, it charges only the base BLOB (3 units).

Scenario Two: If the CCC content in the base blob is updated, snapshot copies the old CCC portion of the base blob. Charge will be 4 units

Scenario Three: If the CCC content in the base blob is removed, the old CCC portion of the base blob is duplicated in the ddd,snapshot. Charge will be 4 units

Situation four: Multiple blob blocks are changed, multiple snapshot are billed according to actual usage. The billing unit in the figure is 8

The implementation of the specific BLOB snapshot has three parts: 1. Create; 2. Delete the snapshot;3 that is more than XX days. Restore snapshot. This article describes the script for these three features:

    1. Create snapshot:

$storageaccounts = Get-azurestorageaccount

foreach ($storageaccount in $storageaccounts)

{

Set-azuresubscription-subscriptionname xxxx-currentstorageaccountname $storageaccount. Storageaccountname

$pageblobs = Get-azurestorageblob-container VHDs | Where-object {$_. Name-match ". vhd"}

foreach ($blob in $pageblobs)

{

if (! $blob. Icloudblob.issnapshot)

{

}

}

}

    1. Delete Snapshot for more than 14 days

$storageaccounts = Get-azurestorageaccount

foreach ($storageaccount in $storageaccounts)

{

$pageblobs = Get-azurestorageblob-container VHDs | Where-object {$_. Name-match ". vhd"}

$now = Get-date

foreach ($pageblob in $pageblobs)

{

$diff = [Datetime]::frombinary ($now. ticks-$pageblob. Snapshottime.ticks)

if ($pageblob. Icloudblob.issnapshot)

{

if ($diff. Dayofyear-ge 14)

{

Write-host "The snapshot is" $diff. DayOfYear ' Days '

Write-host "Delete"

$pageblob. Icloudblob.delete ()

}else

{

Write-host "The snapshot is" $diff. DayOfYear ' Days '

Write-host "Not delete snapshot"

}

}else

{

Write-host "is not snapshot, does not delete"

}

}

}

3. Restore the snapshot 7 days ago

$StorageAccount = "XXXX"

$StorageKey = "xxx=="

$CTR = New-azurestoragecontext-storageaccountname $StorageAccount-storageaccountkey $StorageKey

$SrcContainer = "Container1"

$DestContainer = "Container2"

$blobname = "Xxx.vhd"

$Date =date

$DestBlob = "R" + $Date. dayofyear+ $blobname

$DayOfYear = 7

$times = Get-azurestorageblob-container $SrcContainer | Where-object {$_. Name-match "Xxx.vhd"} | Select-expandproperty Snapshottime

foreach ($time in $times)

{

if ($time. Dayofyear-eq $DayOfYear)

{

$snaptime = $time

}

Else

{

Continue

}

}

$srcsnap = Get-azurestorageblob-container $SrcContainer | Where-object {$_. Snapshottime-eq $snaptime}

Start-azurestorageblobcopy-cloudblob $srcsnap. Icloudblob-destcontainer $DestContainer-destblob $DestBlob

Azure blob Storage Snapshot

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.