从Amazon S3迁移到Azure Storage(Django网络应用程序) [英] Migrating from Amazon S3 to Azure Storage (Django web app)

查看:313
本文介绍了从Amazon S3迁移到Azure Storage(Django网络应用程序)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我维护这个Django网络应用程序,用户会聚在一起并彼此聊天。他们也可以张贴图片,如果他们想要。我处理这些照片(即优化其大小)并将其存储在Amazon S3存储区(如Azure Storage中的容器)中。为了做到这一点,我在Amazon上设置了一个bucket,并在我的 settings.py 中包含了以下配置代码:

 code> DEFAULT_FILE_STORAGE ='storages.backends.s3boto.S3BotoStorage'
AWS_S3_FORCE_HTTP_URL = True
AWS_QUERYSTRING_AUTH = False
AWS_SECRET_ACCESS_KEY = os.environ.get('awssecretkey')
AWS_ACCESS_KEY_ID = os.environ.get('awsaccesskeyid')
AWS_S3_CALLING_FORMAT ='boto.s3.connection.OrdinaryCallingFormat'
AWS_STORAGE_BUCKET_NAME ='damadam.in'
/ pre>

另外 Boto 2.38.0 django-storages 1.1.8 安装在我的虚拟环境中。 Boto 是一个向Amazon Web Services提供接口的Python包,而 django-storages 是Django的自定义存储后端的集合。



我现在想停止使用Amazon S3,而是迁移到 Azure存储。即我需要将所有现有的文件从S3迁移到Azure Storage,接下来我需要配置我的Django应用程序,以便在Azure Storage上保存所有新的静态资源。



我无法找到我正在尝试实现的精确文档。虽然我知道 django-storages



在Azure上门户:


I maintain this Django web app where users congregate and chat with one another. They can post pictures too if they want. I process these photos (i.e. optimize their size) and store them on an Amazon S3 bucket (like a 'container' in Azure Storage). To do that, I set up the bucket on Amazon, and included the following configuration code in my settings.py:

DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
AWS_S3_FORCE_HTTP_URL = True
AWS_QUERYSTRING_AUTH = False
AWS_SECRET_ACCESS_KEY = os.environ.get('awssecretkey')
AWS_ACCESS_KEY_ID = os.environ.get('awsaccesskeyid')
AWS_S3_CALLING_FORMAT='boto.s3.connection.OrdinaryCallingFormat'
AWS_STORAGE_BUCKET_NAME = 'damadam.in'

Additionally Boto 2.38.0 and django-storages 1.1.8 are installed in my virtual environment. Boto is a Python package that provides interfaces to Amazon Web Services, whereas django-storages is a collection of custom storage backends for Django.

I now want to stop using Amazon S3 and instead migrate to Azure Storage. I.e. I need to migrate all existing files from S3 to Azure Storage, and next I need to configure my Django app to save all new static assets on Azure Storage.

I can't find precise documentation on what I'm trying to achieve. Though I do know django-storages support Azure. Has anyone done this kind of a migration before, and can point out where I need to begin, what steps to follow to get everything up and running?

Note: Ask me for more information if you need it.

解决方案

Per my experience, you can do the two steps for migrating from Amazon S3 to Azure Storage for Django web app.

The first step is moving all files from S3 to Azure Blob Storage. There are two ways you can try.

  1. Using the tools for S3 and Azure Storage to move files from S3 to local directory to Azure Blob Storage.

These tools below for S3 can help moving files to local directory.

For moving local files to Azure Blob Storage, you can use AzCopy Command-Line Utility for high-performance uploading, downloading, and copying data to and from Microsoft Azure Blob, File, and Table storage, please refer to the document https://azure.microsoft.com/en-us/documentation/articles/storage-use-azcopy/.

Example: AzCopy /Source:C:\myfolder /Dest:https://myaccount.blob.core.windows.net/mycontainer

  1. Migrating by programming with Amazon S3 and Azure Blob Storage APIs in your familiar language like Python, Java, etc. Please refer to their API usage docs https://azure.microsoft.com/en-us/documentation/articles/storage-python-how-to-use-blob-storage/ and http://docs.aws.amazon.com/AmazonS3/latest/API/APIRest.html.

The second step is following the document http://django-storages.readthedocs.org/en/latest/backends/azure.html to re-configure Django settings.py file. Django-storages would allow any uploads you do to be automatically stored in your storage container.

DEFAULT_FILE_STORAGE='storages.backends.azure_storage.AzureStorage'
AZURE_ACCOUNT_NAME='myaccount'
AZURE_ACCOUNT_KEY='account_key'
AZURE_CONTAINER='mycontainer'

You can find these settings on Azure Portal as @neolursa said.


Edit: On Azure old portal:

On Azure new portal:

这篇关于从Amazon S3迁移到Azure Storage(Django网络应用程序)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆