如何通过 Azure Automation 使用调度程序设置文件共享快照的保留期?

How to set the retain period of Files Share snapshot with scheduler by Azure Automation?

我想通过 Azure Automation 设置文件共享快照的保留期。 1,我可以在一个runbook上设置创建和删除快照的时间表吗? (比如今天创建一个快照,一个月后删除)。 2、我想按天、周、月获取一些快照,我可以决定保留时间吗? (比如保持每日快照 15 天,每周快照 35 天,每月快照 13 个月)。
3,如果这么难,我可以决定我要删除的快照吗,就像前面的10。如果你对此有所了解,请在下面发表评论,非常感谢。

一些信息供您参考。

试试下面的命令来创建快照,对于它的运行频率,你可以create a schedule for the runbook

$connectionName = "AzureRunAsConnection"
try
{
    # Get the connection "AzureRunAsConnection "
    $servicePrincipalConnection=Get-AutomationConnection -Name $connectionName         

    "Logging in to Azure..."
    Add-AzureRmAccount `
        -ServicePrincipal `
        -TenantId $servicePrincipalConnection.TenantId `
        -ApplicationId $servicePrincipalConnection.ApplicationId `
        -CertificateThumbprint $servicePrincipalConnection.CertificateThumbprint 
}
catch {
    if (!$servicePrincipalConnection)
    {
        $ErrorMessage = "Connection $connectionName not found."
        throw $ErrorMessage
    } else{
        Write-Error -Message $_.Exception
        throw $_.Exception
    }
}

$SAResourceGroupName="joywebapp"
$StorageAccountName="joystoragev2"
$StorageAccountKey = (Get-AzureRmStorageAccountKey -ResourceGroupName $SAResourceGroupName -AccountName $StorageAccountName).Value[1]
$context=New-AzureStorageContext -StorageAccountName $StorageAccountName -StorageAccountKey $StorageAccountKey

$share = Get-AzureStorageShare -Context $context -Name "111"
$snapshot = $share.Snapshot()

删除一个月前创建的快照:

$allsnapshots = Get-AzureStorageShare -Context $context | Where-Object { $_.Name -eq "111" -and $_.IsSnapshot -eq $true }


foreach($snapshot in $allsnapshots){
    if($snapshot.SnapshotTime -lt (get-date).AddMonths(-1)){
        $snapshot.Delete()
    }
}