I'm looking into storing Zend Framework on Microsoft Azures Blob Storage. Azure Blob storage has a flat file system where as Zend Framework has a deeply nested structure.
I want to create a folder containing all Zend Framework files using the following naming convention / method.
eg: The Zend_Log_Writter class i开发者_C百科s stored at:
library/Zend/Log/Writer.php
In the new flat output folder the file would be named:
Zend.Log.Writter.php
I'll use any tool that will accomplish the job linux or windows. I could write a PHP script that would do this but I'm guessing there is a piece of Linux Foo out there that could accomplish what I'm after with a few linked commands.
If I'm reading this question correctly, it sounds like you're trying to map a file system to individual blobs in Windows Azure Storage. You'd need some type of in-between tier to map requested files to individual blobs (and php has a very robust SDK you can use for accessing blobs). One correction about blobs: it's not exactly flat: The URI would be https://mystorageaccount/containername/blobname. You have one native directory (container), and you can then simulate further levels with the technique Pekka provided a link to.
However: To me, this mapping sounds like it may have performance implications, as well as transaction implications.
As an alternative, why not mount an NTFS-formatted Cloud Drive in a Windows Azure page blob? Your drive can be up to 1TB, accessible via drive-letter. It's durable (meaning triple-replicated within the data center), and would let you then install pretty much anything to it (such as the file directory structure for Zend). Pretty easy to set up - maybe a dozen lines of code.
The one caveat to Cloud Drives: only one writer. You'd have to keep that in mind when scaling your web app to multiple instances. There are workarounds (such as having one Cloud Drive per instance), and taking advantage of caching (such as the new AppFabric Cache which recently went into production).
EDIT: Here's a great Cloud Drive sample by Maarten Balliauw, demonstrating the steps needed for creating/allocating/mounting a Cloud Drive.
I know how to do this in python. Here is an example. Test it on some dummy directory first just to make sure you're using it right.
import os
import shutil
directory = '/path/to/your/directory/'
for root, folder, files in os.walk(directory):
for file in files:
print(directory+'renamed/'+root.replace('/', '.')[1:]+'.'+file)
shutil.copy(root+'/'+file, directory+'renamed/'+root.replace('/', '.')[1:]+'.'+file)
Edit as to why I used python: I did try using the find command and the -exec option in Linux initially....but much cleaner and easier to understand this way. I'm guessing you could go with one uber awesome line at the bash shell. However not sure the extra time needed to try and figure that out is worth it being as this is basically only 4 lines of relevant code.
Try this code. It makes use of StorageClient library from Microsoft.
namespace RenameBlobs { class Program {
static void Main(string[] args)
{
CloudStorageAccount csa = CloudStorageAccount.DevelopmentStorageAccount;
string blobContainerName = "png1";
string oldDelimiter = "/";
string newDelimiter = ".";
CloudBlobClient blobClient = csa.CreateCloudBlobClient();
var blobContainer = blobClient.GetContainerReference(blobContainerName);
string blobContainerUriString = blobContainer.Uri.AbsoluteUri;
BlobRequestOptions blobRequestOptions = new BlobRequestOptions()
{
UseFlatBlobListing = true,
};
var blobsList = blobContainer.ListBlobs(blobRequestOptions);
foreach (var blob in blobsList)
{
var blockBlob = (CloudBlockBlob) blob;
var abc = blockBlob.Metadata;
blockBlob.FetchAttributes();
string blobName = blockBlob.Uri.AbsoluteUri;
blobName = blobName.Replace(blobContainerUriString, string.Empty);
if (blobName.StartsWith(oldDelimiter))
{
blobName = blobName.Substring(1);
}
if (blobName.Contains(oldDelimiter))
{
blobName = blobName.Replace(oldDelimiter, newDelimiter);
string newBlobUriString = string.Format("{0}/{1}", blobContainerUriString, blobName);
var cloudBlob = blobContainer.GetBlobReference(newBlobUriString);
cloudBlob.CopyFromBlob(blockBlob);
}
}
}
}
}
Let me know if you have any questions about this code.
Hope this helps.
Thanks
精彩评论