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")
    }
  • 相关阅读:
    在cmd命令行中弹出Windows对话框
    Windows远程桌面连接如何直接使用剪贴板功能
    升级Windows10后Apache服务器启动失败的解决方法
    Windows下尝试PHP7提示丢失VCRUNTIME140.DLL的问题解决
    手动构建Servlet项目的流程
    更改Apache默认网站根目录
    windows下安装Appserv等php套件之后无法进入数据库管理的问题
    Java web项目的字符集问题
    五谷-小米:白小米
    五谷-小米:黑小米
  • 原文地址:https://www.cnblogs.com/stonehe/p/9300297.html
Copyright © 2011-2022 走看看