【问题标题】:How do I create a snapshot based on orphan disk如何基于孤盘创建快照
【发布时间】:2020-01-19 23:49:25
【问题描述】:

我正在尝试为我的资源中的所有孤立磁盘创建快照。首先,我喜欢在资源中找到所有孤立磁盘,然后删除所有孤立磁盘,但在删除它之前,我喜欢创建快照。有人可以帮我解决这个问题。我是 azure powershell 的新手。这将是我的第一个 powershell 脚本。

【问题讨论】:

    标签: azure powershell azure-powershell azure-cli


    【解决方案1】:

    试试这个:

    Login-AzAccount
    
    $rg = '<name of resource group that to store your snapshot , recommand you create a new one>'
    
    $disks = Get-AzDisk 
    
    foreach ($disk in $disks) {
        if(!$disk.ManagedBy){
             $snapconfig = New-AzSnapshotConfig -Location $disk.Location -SourceUri $disk.Id -CreateOption Copy
             #create snapshot
             New-AzSnapshot -ResourceGroupName $rg -SnapshotName $disk.Name  -Snapshot $snapconfig  
    
             #remove disk .it is strongly recommand that make sure your have created snapshot successfully to run this command
             remove-azdisk -ResourceGroupName $disk.ResourceGroupName -DiskName $disk.Name -Force
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2017-07-08
      • 1970-01-01
      • 2018-04-24
      • 2021-11-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-22
      相关资源
      最近更新 更多