linux怎么查看本机内存大小
336
2022-10-05
使用PowerShell对磁盘做快照并复制到存储账户
以下 PowerShell 脚本先对指定的托管磁盘创建快照,再将快照导出成 VHD 文件,保存在指定的存储账户中
Connect-AzAccount -Environment AzureChinaCloud $SubscriptionId = "xxxxxxxx" Select-AzSubscription -Subscription $SubscriptionId #磁盘所在资源组的名称 $ResourceGroupName ="oldrg" #磁盘名称 $DiskName = "hademo_OsDisk_1_2f5ee787fc8e4c6faaa01e88b3369504" #根据磁盘制作的快照名称 $SnapshotName = "oldrgwinos" #导出时间 $sasExpiryDuration = "3600" #导出到目标存储账号的名称 $StorageAccountName = "myresourcegroup54248" #导出到目标存储账号的容器名称 $StorageContainerName = "vhds" #存储账户的密钥 $StorageAccountKey = '1zz2xxxxxxxxxxxx' #导出到目标存储账户容器的vhd名称 $DestinationVHDFileName = "newwinos.vhd" #快照所在的区域 $Location = "chinanorth2" #获取磁盘信息 $Disk = Get-AzDisk -ResourceGroupName $ResourceGroupName -DiskName $DiskName #根据磁盘创建快照 $Snapshot = New-AzSnapshotConfig -SourceUri $Disk.Id -CreateOption Copy -Location $Location New-AzSnapshot -Snapshot $Snapshot -SnapshotName $SnapshotName -ResourceGroupName $ResourceGroupName #获取快照的SAS $sas = Grant-AzSnapshotAccess -ResourceGroupName $ResourceGroupName -SnapshotName $SnapshotName -DurationInSecond $sasExpiryDuration -Access Read #获取目标存储账户的凭据信息 $destinationContext = New-AzStorageContext -StorageAccountName $StorageAccountName -StorageAccountKey $StorageAccountKey #开始拷贝 Start-AzStorageBlobCopy -AbsoluteUri $sas.AccessSAS -DestContainer $StorageContainerName -DestContext $destinationContext -DestBlob $DestinationVHDFileName #查看拷贝进度 Get-AzStorageBlobCopyState -Blob $DestinationVHDFileName -Container $StorageContainerName -Context $destinationContext -WaitForComplete #回收快照的SAS Revoke-AzSnapshotAccess -ResourceGroupName $ResourceGroupName -SnapshotName $SnapshotName #删除快照 Remove-AzSnapshot -ResourceGroupName $ResourceGroupName -SnapshotName $SnapshotName -Force
参考:
Get-AzStorageBlobCopyState
AzCopy
推荐使用7.3.0
快照SAS如下:
azcopy /source:/SourceSAS:"?sv=2017-04-17&sr=b&si=b8ff2e37-deb9-4e7f-9578-eee4f728fccb&sk=system-1&sig=MA88lxbyk0ExdIn17aj25vhSCciMmEDfQrbd4Hxjh3g%3D" /dest:f:\test\abcd.vhd
#提供订阅 ID $SubscriptionId = "yourSubscriptionId" #提供资源组名 $ResourceGroupName ="yourResourceGroupName" #提供想要复制的托管磁盘名 $DiskName = "yourDiskName" #提供想要创建的快照名 $SnapshotName = "yourSnapshotName" #快照 SAS 的过期时间,3600 秒 = 1 小时 $sasExpiryDuration = "3600" #提供目标存储账户名 $StorageAccountName = "yourstorageaccountName" #提供目标存储账户容器名 $StorageContainerName = "yourstoragecontainername" #提供目标存储账户密钥 $StorageAccountKey = 'yourStorageAccountKey' #提供目标 VHD 文件名 $DestinationVHDFileName = "yourVHDfilename" #提供地区信息,chinaeast 或 chinanorth $Location = "resourcelocation" #获取想要复制的托管磁盘 $Disk = Get-AzureRmDisk -ResourceGroupName $ResourceGroupName -DiskName $DiskName #创建快照配置 $Snapshot = New-AzureRmSnapshotConfig -SourceUri $Disk.Id -CreateOption Copy -Location $Location #拍摄快照 New-AzureRmSnapshot -Snapshot $Snapshot -SnapshotName $SnapshotName -ResourceGroupName $ResourceGroupName #创建快照的 SAS Uri $sas = Grant-AzureRmSnapshotAccess -ResourceGroupName $ResourceGroupName -SnapshotName $SnapshotName -DurationInSecond $sasExpiryDuration -Access Read #创建目标存储账户上下文 $destinationContext = New-AzureStorageContext -StorageAccountName $StorageAccountName -StorageAccountKey $StorageAccountKey #将快照的基础 VHD 复制到存储账户 Start-AzureStorageBlobCopy -AbsoluteUri $sas.AccessSAS -DestContainer $StorageContainerName -DestContext $destinationContext -DestBlob $DestinationVHDFileName Eample: $SubscriptionId = "5d666915-fc5f-4ee8-b26a-d98e0566cf34" $ResourceGroupName ="jackrg" $DiskName = "win16_OsDisk_1_674e1c4fedb34956ae5310e5fd6f7b71" $SnapshotName = "win16osss" $sasExpiryDuration = "3600" $StorageAccountName = "jackrgdiag" $StorageContainerName = "copydisk" $StorageAccountKey = 'lmY5PTQQ5ROgZIreK2P+8ASL0cb4NESaws2XW3k81loPu1kzKCyR4e8/4aLxlm3L9XfIKUj17CC1eLUOQaLpRQ==' $DestinationVHDFileName = "win16osdisk" $Location = "chinanorth2" $Disk = Get-AzDisk -ResourceGroupName $ResourceGroupName -DiskName $DiskName $Snapshot = New-AzSnapshotConfig -SourceUri $Disk.Id -CreateOption Copy -Location $Location New-AzSnapshot -Snapshot $Snapshot -SnapshotName $SnapshotName -ResourceGroupName $ResourceGroupName $sas = Grant-AzSnapshotAccess -ResourceGroupName $ResourceGroupName -SnapshotName $SnapshotName -DurationInSecond $sasExpiryDuration -Access Read $destinationContext = New-AzStorageContext -StorageAccountName $StorageAccountName -StorageAccountKey $StorageAccountKey Start-AzStorageBlobCopy -AbsoluteUri $sas.AccessSAS -DestContainer $StorageContainerName -DestContext $destinationContext -DestBlob $DestinationVHDFileName Get-AzStorageBlobCopyState -Blob $DestinationVHDFileName -Container $StorageContainerName -Context $destinationContext -WaitForComplete Revoke-AzSnapshotAccess -ResourceGroupName $ResourceGroupName -SnapshotName $SnapshotName Remove-AzSnapshot -ResourceGroupName $ResourceGroupName -SnapshotName $SnapshotName -Force; ### 制作托管磁盘快照到指定资源组中, 获取SAS到指定存储账户的容器中 $StorageContainerName = "xxx" #存储账号密钥 $StorageAccountKey = 'xxx' #下载后的VHD名称 $DestinationVHDFileName = "xxx" #快照所属地区 $Location = "chinanorth2" #获取要做快照的磁盘名称 $Disk = Get-AzDisk -ResourceGroupName NOC_Classic -DiskName $DiskName $Snapshot = New-AzSnapshotConfig -SourceUri $Disk.Id -CreateOption Copy -Location $Location #制作快照 New-AzSnapshot -Snapshot $Snapshot -SnapshotName $SnapshotName -ResourceGroupName $ResourceGroupName #获取访问权限 $sas = Grant-AzSnapshotAccess -ResourceGroupName $ResourceGroupName -SnapshotName $SnapshotName -DurationInSecond $sasExpiryDuration -Access Read #获取目标存储账号信息 $destinationContext = New-AzStorageContext -StorageAccountName $StorageAccountName -StorageAccountKey $StorageAccountKey #开始复制 Start-AzStorageBlobCopy -AbsoluteUri $sas.AccessSAS -DestContainer $StorageContainerName -DestContext $destinationContext -DestBlob $DestinationVHDFileName #查看复制进度 Get-AzStorageBlobCopyState -Blob $DestinationVHDFileName -Container $StorageContainerName -Context $destinationContext -WaitForComplete #回收权限 Revoke-AzSnapshotAccess -ResourceGroupName $ResourceGroupName -SnapshotName $SnapshotName #删除快照 Remove-AzSnapshot -ResourceGroupName $ResourceGroupName -SnapshotName $SnapshotName -Force;
Azure CLI 以下 Azure CLI 脚本仅对指定快照生成 SAS Uri,并将快照导出成 VHD 文件至指定存储账户
#Provide the subscription Id where snapshot is created subscriptionId=mySubscriptionId #Provide the name of your resource group where snapshot is created resourceGroupName=myResourceGroupName #Provide the snapshot name snapshotName=mySnapshotName #Provide Shared Access Signature (SAS) expiry duration in seconds e.g. 3600. #Know more about SAS here: https://docs.microsoft.com/en-us/azure/storage/storage-dotnet-shared-access-signature-part-1 sasExpiryDuration=3600 #Provide storage account name where you want to copy the snapshot. storageAccountName=mystorageaccountname #Name of the storage container where the downloaded snapshot will be stored storageContainerName=mystoragecontainername #Provide the key of the storage account where you want to copy snapshot. storageAccountKey=mystorageaccountkey #Provide the name of the VHD file to which snapshot will be copied. destinationVHDFileName=myvhdfilename az account set --subscription $subscriptionId sas=$(az snapshot grant-access --resource-group $resourceGroupName --name $snapshotName --duration-in-seconds $sasExpiryDuration --query [accessSas] -o tsv) az storage blob copy start --destination-blob $destinationVHDFileName --destination-container $storageContainerName --account-name $storageAccountName --account-key $storageAccountKey --source-uri $sas
AZCopy
# Sign-in the Azure China Cloud Connect-AzAccount -Environment AzureChinaCloud #Provide the subscription Id of the subscription where managed disk is created $subscriptionId = "yourSubscriptionId" #Provide the name of your resource group where managed is created $resourceGroupName ="yourResourceGroupName" #Provide the managed disk name $diskName = "yourDiskName" #Provide Shared Access Signature (SAS) expiry duration in seconds e.g. 3600. #Know more about SAS here: https://docs.azure.cn/storage/storage-dotnet-shared-access-signature-part-1 $sasExpiryDuration = "3600" #Provide storage account name where you want to copy the underlying VHD of the managed disk. $storageAccountName = "yourstorageaccountName" #Name of the storage container where the downloaded VHD will be stored $storageContainerName = "yourstoragecontainername" #Provide the key of the storage account where you want to copy the VHD of the managed disk. $storageAccountKey = 'yourStorageAccountKey' #Provide the name of the destination VHD file to which the VHD of the managed disk will be copied. $destinationVHDFileName = "yourvhdfilename" #Set the value to 1 to use AzCopy tool to download the data. This is the recommended option for faster copy. #Download AzCopy v10 from the link here: https://docs.azure.cn/storage/common/storage-use-azcopy-v10 #Ensure that AzCopy is downloaded in the same folder as this file #If you set the value to 0 then Start-AzStorageBlobCopy will be used. Azure storage will asynchronously copy the data. $useAzCopy = 1 # Set the context to the subscription Id where managed disk is created Select-AzSubscription -SubscriptionId $SubscriptionId #Generate the SAS for the managed disk $sas = Grant-AzDiskAccess -ResourceGroupName $ResourceGroupName -DiskName $diskName -DurationInSecond $sasExpiryDuration -Access Read #Create the context of the storage account where the underlying VHD of the managed disk will be copied $destinationContext = New-AzStorageContext -StorageAccountName $storageAccountName -StorageAccountKey $storageAccountKey #Copy the VHD of the managed disk to the storage account if($useAzCopy -eq 1) { $containerSASURI = New-AzStorageContainerSASToken -Context $destinationContext -ExpiryTime(get-date).AddSeconds($sasExpiryDuration) -FullUri -Name $storageContainerName -Permission rw .\azcopy copy $sas.AccessSAS $containerSASURI }else{ Start-AzStorageBlobCopy -AbsoluteUri $sas.AccessSAS -DestContainer $storageContainerName -DestContext $destinationContext -DestBlob $destinationVHDFileName }
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~