######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")
}

定期删除Azure存储账号下N天之前的数据文件-ASM的更多相关文章

  1. 定期删除Azure存储账号下N天之前的数据文件-ARM

    ######RemoveStorageBlob*DaysOld-ARM##### <# .SYNOPSIS Remove all blob contents from one storage a ...

  2. 通过Azure 存储账号URL鉴别是标准磁盘还是高性能磁盘

    对于不知道虚拟机磁盘是标准磁盘还是高性能磁盘时,我们可以通过nslookup解析存储账号的URL,来判断存储账号的类型,从而得知虚拟磁盘的类型 1.标准存储账号的解析结果,字母"st&quo ...

  3. SQL SERVER大话存储结构(6)_数据库数据文件

            数据库文件有两大类:数据文件跟日志文件,每一个数据库至少各有一个数据文件或者日志文件,数据文件用来存储数据,日志文件用来存储数据库的事务修改情况,可用于恢复数据库使用.     这里分 ...

  4. 在windows下,将mysql离线数据文件导入本地mysql数据库

    1. 查看mysql路径 SELECT @@basedir AS basePath FROM DUAL 其实mysql5.6 的数据文件在 C:\ProgramData\MySQL\MySQL Ser ...

  5. 在没有备份的情况下重新创建丢失的数据文件 (Doc ID 1149946.1)

    Recreating a missing datafile with no backups (Doc ID 1149946.1) APPLIES TO: Oracle Database - Enter ...

  6. 如何Windows下配置Prometheus的监控数据文件为3天

    如上图,prometheus的data文件夹时间久了会变得很大,听说是保留15天的数据.但是实际上,我只需要保留3天的数据就够了,之前试过用批处理文件清理,但是强行删除会导致peometheus崩溃, ...

  7. Linux下Mysql 不能访问新数据文件夹问题

    新挂载的盘,打算将数据文件夹配置到 /data/mysql,却无法启动mysqld. 除了将目录授权给mysql用户和组以外 chown -R mysql:mysql /data/mysql 太需要将 ...

  8. Azure Automation (2) 定期删除存储账号中的文件

    <Windows Azure Platform 系列文章目录> 本文介绍的是国内由世纪互联运维的Azure China. 本文是对笔者之前的文档Azure Backup (1) 将SQL ...

  9. 【Azure 环境】由为存储账号(Storage Account)拒绝分配权限而引出的Azure 蓝图(Blueprint)使用问题

    问题描述 当打开Azure存储账号(Storage Account)门户页面时,从 "访问控制(标识和访问管理)" 页面中发现有"拒绝分配"的功能,所以就思考, ...

随机推荐

  1. linux shell脚本编程笔记(五): 重定向

    I/O重定向 简述: 默认情况下始终有3个"文件"处于打开状态, stdin (键盘), stdout (屏幕), and stderr (错误消息输出到屏幕上). 这3个文件和其 ...

  2. 九度oj-1533 最长上升子序列 (LIS)

    http://ac.jobdu.com/problem.php?pid=1533 题目描述: 给定一个整型数组, 求这个数组的最长严格递增子序列的长度. 譬如序列1 2 2 4 3 的最长严格递增子序 ...

  3. 🔸RU大神手册上要再“做”的题🔸

  4. php闭包bindTo方法用法

    从手册知道,Closure::bindTo — 复制当前闭包对象,绑定指定的$this对象和类作用域. 创建并返回一个 匿名函数, 它与当前对象的函数体相同.绑定了同样变量,但可以绑定不同的对象,也可 ...

  5. sql查询磁盘空间并发预警邮件

    检测磁盘空间,如果低于设置的预警值则发出一封预警邮件,这样的事情可以用SQL server的作业可以做,关键SQL语句如下例子所示: DECLARE @TableText NVARCHAR(MAX)= ...

  6. asp.net 自定义节配置 (configSections下的section)

    <configuration> <configSections> <!--.自定义一个节 CustomSection --> <section name=&q ...

  7. Hadoop中Writable类之二

    1.ASCII.Unicode.UFT-8 在看Text类型的时候,里面出现了上面三种编码,先看看这三种编码: ASCII是基于拉丁字母的一套电脑编码系统.它主要用于显示现代英语和其他西欧语言.它是现 ...

  8. linux nkf 日文编码转换命令[转载]

    对于日语的编码 windows : Shift-JIS Linux : 2.4内核使用EUC编码,2.6内核中使用UTF8编码 检查文件编码  nkf -g filename 通常处理字符编码都使用i ...

  9. Deep learning for visual understanding: A review

    https://www.sciencedirect.com/science/article/pii/S0924271618301291?dgcid=raven_sd_recommender_email ...

  10. javascript 深度克隆

    关键词 :递归 主要分为 数组 .对象.以及基本类型 function clone(Obj) {           var buf;           if (Obj instanceof Arr ...