定期删除Azure存储账号下N天之前的数据文件-ARM
######RemoveStorageBlob*DaysOld-ARM#####
<#
.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-arm-new
{
param(
#设置Org ID
[parameter(Mandatory=$true)]
[String]$AzureOrgId="***", #设置Org ID的密码
[Parameter(Mandatory = $true)]
[String]$Password="***", #设置订阅名称
[Parameter(Mandatory = $true)]
[String]$AzureSubscriptionName="***", #设置存储账号所在的资源组
[Parameter(Mandatory = $true)]
[String]$ResourceGroupName="***", #设置存储账号
[Parameter(Mandatory = $true)]
[String]$StorageAccountName="***", #设置Container Name
[Parameter(Mandatory = $true)]
[String]$ContainerName="***", #设置过期时间
[Parameter(Mandatory = $true)]
[Int32]$DaysOld=
) $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-AzureRmAccount -Credential $AzureOrgIdCredential -environmentname "AzureChinaCloud" | Write-Verbose # Set-AzureSubscription -SubscriptionName $AzureSubscriptionName -CurrentStorageAccountName $StorageAccountName Select-AzureRmSubscription -SubscriptionName $AzureSubscriptionName
Set-AzureRmCurrentStorageAccount -ResourceGroupName $ResourceGroupName -StorageAccountName $StorageAccountName # loop through each container and get list of blobs for each container and delete
$blobsremoved =
$containers = Get-AzureStorageContainer -Name $ContainerName -ErrorAction SilentlyContinue #$storage = Get-AzureRmStorageAccount -ResourceGroupName $ResourceGroupName -Name $StorageAccountName
#write-output $storage
#$context = [Microsoft.WindowsAzure.Commands.Common.Storage.AzureStorageContext]$storage.Context;
#Write-Output($storage.Context.gettype());
#$containers = Get-AzureStorageContainer -Name $ContainerName -Context $context -ErrorAction SilentlyContinue
#$containers = $storage | Get-AzureStorageContainer -Name $ContainerName foreach($container in $containers)
{
$blobsremovedincontainer =
Write-Output ("Searching Container: {0}" -f $container.Name)
#$blobs = Get-AzureStorageBlob -Container $ContainerName -Context $context
#$blobs = $storage | Get-AzureStorageBlob -Container $ContainerName
$blobs = Get-AzureStorageBlob -Container $ContainerName 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 +=
$blobsremovedincontainer +=
}
}
}
} 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天之前的数据文件-ARM的更多相关文章
- 定期删除Azure存储账号下N天之前的数据文件-ASM
		
######RemoveStorageBlob*DaysOld##### <# .SYNOPSIS Remove all blob contents from one storage accou ...
 - 通过Azure 存储账号URL鉴别是标准磁盘还是高性能磁盘
		
对于不知道虚拟机磁盘是标准磁盘还是高性能磁盘时,我们可以通过nslookup解析存储账号的URL,来判断存储账号的类型,从而得知虚拟磁盘的类型 1.标准存储账号的解析结果,字母"st&quo ...
 - SQL SERVER大话存储结构(6)_数据库数据文件
		
数据库文件有两大类:数据文件跟日志文件,每一个数据库至少各有一个数据文件或者日志文件,数据文件用来存储数据,日志文件用来存储数据库的事务修改情况,可用于恢复数据库使用. 这里分 ...
 - 在windows下,将mysql离线数据文件导入本地mysql数据库
		
1. 查看mysql路径 SELECT @@basedir AS basePath FROM DUAL 其实mysql5.6 的数据文件在 C:\ProgramData\MySQL\MySQL Ser ...
 - 在没有备份的情况下重新创建丢失的数据文件 (Doc ID 1149946.1)
		
Recreating a missing datafile with no backups (Doc ID 1149946.1) APPLIES TO: Oracle Database - Enter ...
 - 如何Windows下配置Prometheus的监控数据文件为3天
		
如上图,prometheus的data文件夹时间久了会变得很大,听说是保留15天的数据.但是实际上,我只需要保留3天的数据就够了,之前试过用批处理文件清理,但是强行删除会导致peometheus崩溃, ...
 - Linux下Mysql 不能访问新数据文件夹问题
		
新挂载的盘,打算将数据文件夹配置到 /data/mysql,却无法启动mysqld. 除了将目录授权给mysql用户和组以外 chown -R mysql:mysql /data/mysql 太需要将 ...
 - Azure Automation (2) 定期删除存储账号中的文件
		
<Windows Azure Platform 系列文章目录> 本文介绍的是国内由世纪互联运维的Azure China. 本文是对笔者之前的文档Azure Backup (1) 将SQL ...
 - 【Azure 环境】由为存储账号(Storage Account)拒绝分配权限而引出的Azure 蓝图(Blueprint)使用问题
		
问题描述 当打开Azure存储账号(Storage Account)门户页面时,从 "访问控制(标识和访问管理)" 页面中发现有"拒绝分配"的功能,所以就思考, ...
 
随机推荐
- 26.Remove Duplicates from Sorted Array(Array)
			
Given a sorted array, remove the duplicates in place such that each element appear only once and ret ...
 - 如果应用程序正在通过 <identity impersonate="true"/> 模拟,则标识将为匿名用户(通常为 IUSR_MACHINENAME)或经过身份验证的请求用户。
			
在配置文件中添加 <identity impersonate= "true " userName= "Administrator " pass ...
 - CMDB之数据采集
			
一. 四种方式 1. Agent方式 api - URL - 发送数据格式 - 返回值 agent - 采集数据,发送数据 好处: - 简单 - 采集速度快,响应速度快 坏处: - 每台agent装的 ...
 - 12个优秀的国外Material Design网站案例
			
眼看2017年就快完了,你是不是还没完全搞懂Material Design呢?是嫌说明文档太长,还是觉得自己英文不好?都没关系,小编今天给大家整理了一份干货满满的学习笔记,并列举了一些国外的Mater ...
 - iOS Orientation获取
			
[iOS Orientation获取] 1.[[UIDevice sharedInstance] orientation] 必须调用beginGeneratingDeviceOrientationNo ...
 - swift -懒加载创建view
			
// 只有外界访问到headerView的时候才会去执行闭包, 然后将闭包的返回值赋值给headerView // 注意: 一定要记住闭包后面需要写上(), 代表执行闭包 //懒加载 ...
 - 20169221 2016-2017-2《移动平台与android开发》学习总结
			
每周作业连接汇总 第一周<Intellj IDEA 简易教程>学习,码云的基础使用.由于第一次写作业,网络攻防作业占据了我整个周四周五周六的时间这周java时间被挤没了,所以没有完成所有学 ...
 - Android-操作系统拨打电话广播的处理
			
Android操作系统的 packages/apps/phone/AndroidManifest.xml源码阅读 在之前的博客,Android-隐式意图激活操作系统通话界面,讲解了,阅读Android ...
 - Linq使用中的ToList注意事项
			
在使用Linq时,如果查询逻辑太复杂,可以拆分为多个Linq查询,下一个Linq在上一个Linq查询的结果上继续操作,这样逻辑清晰,又不会出错.但在使用ToList的时候需要注意,最常见碰到的错误是: ...
 - 自定义Team Foundation Server (TFS) 与Project Professional的集成字段
			
用户可以象使用Office Excel一样,使用Project Professional连接TFS,将数据下载到本地修改,并且发布到TFS服务器上,如果你习惯使用Project来计划你的项目,那么Pr ...