zoukankan      html  css  js  c++  java
  • 定期删除Azure存储账号下N天之前的数据文件-ASM

    ######RemoveStorageBlob*DaysOld#####
    <#
    .SYNOPSIS
       Remove all blob contents from one storage account that are * days old.
    .DESCRIPTION 
       This script will run through a single Azure storage account and delete all blob contents in 
       all containers, which are * days old.
    
       
    #>
    
    workflow delblob-asm
    {
           param(
                    #设置Org ID
                    [parameter(Mandatory=$true)]
                    [String]$AzureOrgId="***",
              
                    #设置Org ID的密码
                    [Parameter(Mandatory = $true)] 
                    [String]$Password="***",
                    
                    #设置订阅名称
                    [Parameter(Mandatory = $true)] 
                    [String]$AzureSubscriptionName="***",
                    
                    #设置存储账号
                    [Parameter(Mandatory = $true)]
                    [String]$StorageAccountName="***",
                    
                    #设置Container Name
                    [Parameter(Mandatory = $true)]
                    [String]$ContainerName="***",
                
                    #设置过期时间
                    [Parameter(Mandatory = $true)] 
                    [Int32]$DaysOld=10
        )
    
        $ChinaTimeZone = [System.TimeZoneInfo]::FindSystemTimeZoneByID("China Standard Time")
        $Start = [System.TimeZoneInfo]::ConvertTimefromUTC((get-date).ToUniversalTime(),$ChinaTimeZone)
        "Starting: " + $Start.ToString("HH:mm:ss.ffffzzz")
    
    
        $AzurePassword = $Password | ConvertTo-SecureString -AsPlainText -Force
        $AzureOrgIdCredential = New-Object System.Management.Automation.PSCredential($AzureOrgId,$AzurePassword)
    
        Add-AzureAccount -Credential $AzureOrgIdCredential -environment "AzureChinaCloud" | Write-Verbose
        
        Set-AzureSubscription -SubscriptionName $AzureSubscriptionName -CurrentStorageAccountName $StorageAccountName
        Select-AzureSubscription -SubscriptionName $AzureSubscriptionName
    
        
    
        
        # loop through each container and get list of blobs for each container and delete
        $blobsremoved = 0
        $containers = Get-AzureStorageContainer -Name $ContainerName -ErrorAction SilentlyContinue
        
        foreach($container in $containers) 
        { 
            $blobsremovedincontainer = 0       
            Write-Output ("Searching Container: {0}" -f $container.Name)   
            $blobs = Get-AzureStorageBlob -Container $container.Name 
    
            if ($blobs -ne $null)
            {    
                foreach ($blob in $blobs)
                {
                   $lastModified = $blob.LastModified
                   if ($lastModified -ne $null)
                   {
                       $blobDays = ([DateTime]::Now - [DateTime]$lastModified)
                       Write-Output ("Blob {0} in storage for {1} days" -f $blob.Name, $blobDays) 
                   
                       if ($blobDays.Days -ge $DaysOld)
                       {
                            Write-Output ("Removing Blob: {0}" -f $blob.Name)
                            Remove-AzureStorageBlob -Blob $blob.Name -Container $container.Name 
                            $blobsremoved += 1
                            $blobsremovedincontainer += 1
                       }
                    }
                }
            }
            
            Write-Output ("{0} blobs removed from container {1}." -f $blobsremovedincontainer, $container.Name)       
        }
        
        $ChinaTimeZone = [System.TimeZoneInfo]::FindSystemTimeZoneByID("China Standard Time")
        $Finish = [System.TimeZoneInfo]::ConvertTimefromUTC((get-date).ToUniversalTime(),$ChinaTimeZone)
         
        $TotalUsed = $Finish.Subtract($Start).TotalSeconds
       
        Write-Output ("Removed {0} blobs in {1} containers in storage account {2} of subscription {3} in {4} seconds." -f $blobsRemoved, $containersremoved, $StorageAccountName, $AzureConnectionName, $TotalUsed)
        "Finished " + $Finish.ToString("HH:mm:ss.ffffzzz")
    }
  • 相关阅读:
    计算机网络【10】—— Cookie与Session
    计算机网络【9】—— HTTP1.0和HTTP1.1的区别及常见状态码
    计算机网络【8】—— Get和Post请求的区别
    计算机网络【7】—— TCP的精髓
    数据库事务的四大特性以及事务的隔离级别
    JavaWeb基础【1】—— Tomcat
    Get current time and date on Android
    Converting Storyboard from iPhone to iPad
    iPhone OS 开发
    (译)iOS Code Signing: 解惑
  • 原文地址:https://www.cnblogs.com/stonehe/p/9300297.html
Copyright © 2011-2022 走看看