标签:
用户虚拟机硬盘的备份是客户在部署云应用中是一个非常重要的部分。
目前有多种平台的备份方法:
Azure的Snapshot是按照实际使用空间进行计费的。由于Snapshot遵循"写时复制"的方式,如果Base Blob的内容不发生变化,Snapshot里是没有内容的,只有Base Blob发生变化时,Snapshot会把Base Blob中老的内容复制过来。
具体的计费方式如下:
情况一: 如果Snapshot的内容和Base Blob的内容相同,收费只收Base Blob的费用(3个单元)。
情况二:如果Base Blob中的CCC内容发生更新,Snapshot会复制Base Blob中老的CCC部分。收费将收4个单元
情况三:如果Base Blob中的CCC内容删除,增加了DDD,Snapshot中会复制Base Blob中老的CCC部分。收费将收4个单元
情况四:多个blob块出现更改,多个snapshot,按照实际的用量进行计费。图中的计费单元为8个
具体的blob snapshot的实现有三个部分:1.创建;2.删除超过xx天的snapshot;3.恢复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)
{
}
}
}
$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, do not delete"
}
}
}
3.恢复7天前的Snapshot
$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
标签:
原文地址:http://www.cnblogs.com/hengwei/p/5148471.html