Permalink
Browse files

Added the -recursive argument, delete all files in blob storage hiera…

…rchy
  • Loading branch information...
nwoolls committed Jul 11, 2013
1 parent 0c5b200 commit a83b4b99e240969bfde6aa2c04ee8619a7af3379
Showing with 12 additions and 3 deletions.
  1. +6 −1 AzureStorageCleanup/Program.cs
  2. +4 −2 AzureStorageCleanup/StorageCleaner.cs
  3. +2 −0 README.md
@@ -12,6 +12,7 @@ static class CommandLineArgument
internal const string StorageKey = "-storagekey";
internal const string Container = "-container";
internal const string MinDaysOld = "-mindaysold";
internal const string Recursive = "-recursive";
}
static void Main(string[] args)
@@ -38,8 +39,10 @@ static void Main(string[] args)
Console.WriteLine(string.Format("Please supply a valid \"{0}\" argument", CommandLineArgument.MinDaysOld));
return;
}
bool recursive = args.Contains(CommandLineArgument.Recursive);
StorageCleaner storageCleaner = new StorageCleaner(storageAccountName, storageAccessKey, containerName, minDaysOld);
StorageCleaner storageCleaner = new StorageCleaner(storageAccountName, storageAccessKey, containerName, minDaysOld, recursive);
storageCleaner.Cleanup();
}
@@ -56,6 +59,7 @@ private static void WriteHelpToConsole()
-storagekey [Blob Storage account key]
-container [Blob Storage container to use]
-mindaysold [Minimum age of files to delete]
-recursive [Optional - delete all files in virtual hierarchy]
Example usage:
@@ -64,6 +68,7 @@ private static void WriteHelpToConsole()
-storagekey dmASdd1mg/qPeOgGmCkO333L26cNcnUA1uMcSSOFM...
-container sqlbackup
-mindaysold 60
-recursive
");
}
@@ -12,13 +12,15 @@ class StorageCleaner
private readonly string storageAccessKey;
private readonly string containerName;
private readonly int minDaysOld;
private readonly bool recursive;
public StorageCleaner(string storageAccountName, string storageAccessKey, string containerName, int minDaysOld)
public StorageCleaner(string storageAccountName, string storageAccessKey, string containerName, int minDaysOld, bool recursive)
{
this.storageAccountName = storageAccountName;
this.storageAccessKey = storageAccessKey;
this.containerName = containerName;
this.minDaysOld = minDaysOld;
this.recursive = recursive;
}
public void Cleanup()
@@ -33,7 +35,7 @@ public void Cleanup()
Console.WriteLine("Deleting blob storage files in {0}\\{1} older than {2} days", storageAccountName, containerName, minDaysOld);
DateTime referenceDate = DateTime.UtcNow;
var blobQuery = from b in container.ListBlobs().OfType<CloudBlockBlob>()
var blobQuery = from b in container.ListBlobs(null, recursive).OfType<CloudBlockBlob>()
where b.Properties.LastModified <= referenceDate.AddDays(-minDaysOld)
select b;
View
@@ -12,6 +12,7 @@ Please supply for following command line arguments:
-storagekey [Blob Storage account key]
-container [Blob Storage container to use]
-mindaysold [Minimum age of files to delete]
-recursive [Optional - delete all files in virtual hierarchy]
```
Example usage:
@@ -22,6 +23,7 @@ AzureStorageCleanup.exe
-storagekey dmASdd1mg/qPeOgGmCkO333L26cNcnUA1uMcSSOFM...
-container sqlbackup
-mindaysold 60
-recursive
```
### How it works

0 comments on commit a83b4b9

Please sign in to comment.