定期删除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)门户页面时,从 "访问控制(标识和访问管理)" 页面中发现有"拒绝分配"的功能,所以就思考, ...
随机推荐
- 96. Unique Binary Search Trees (Tree; DP)
Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For examp ...
- maven项目 实现 spring mybatis 两个框架整合
1.maven项目 src main java java源文件 resources 配置文件 beans.xml spring配置文件 <?xml version="1.0" ...
- 未能加载文件或程序集"xxxxxx"或它的某一个依赖项
错误:未能加载文件或程序集“xxx”或它的某一个依赖项.试图加载格式不正确的程序. 原因分析:操作系统是64位的,但发布的程序引用了一些32位的ddl,所以出现了兼容性的问题. 解决方案:IIS——应 ...
- python全栈考试
1.执行 Python 脚本的两种方式 shell直接调用python脚本 python run.py 调用解释器来调用脚本 2.2.简述位.字节的关系 每8个位bit,组成一个字节byte. 一个 ...
- DART: a fast and accurate RNA-seq mapper with a partitioning strategy DART:使用分区策略的快速准确的RNA-seq映射器
DART: a fast and accurate RNA-seq mapper with a partitioning strategyDART:使用分区策略的快速准确的RNA-seq映射器 Abs ...
- Spring boot——logback.xml 配置详解(四)<filter>
阅读目录 1 filter的使用 2 常用的过滤器 文章转载自:http://aub.iteye.com/blog/1101260,在此对作者的辛苦表示感谢! 回到顶部 1 filter的使用 < ...
- JavaScript 语法总结
1. 不能为基本类型变量添加属性和方法. 如果添加了,那么也是undefined的. var str = "a string"; str.attr = "attr&quo ...
- java类的泛型DAO
@Transactional public abstract class DAOSupport<T> implements DAO<T> { protected Class&l ...
- 编译驱动的Makefile解析
一个典型的编译驱动模块的Makefile文件如下所示: KERN_DIR = /root/driver/kernel obj-m += module_test.o all: make -C $(KER ...
- HTTP 499 状态码 nginx下 499错误
日志记录中HTTP状态码出现499错误有多种情况,我遇到的一种情况是nginx反代到一个永远打不开的后端,就这样了,日志状态记录是499.发送字节数是0. 老是有用户反映网站系统时好时坏,因为线上的产 ...