将数据从 EC2 迁移到 S3?
我正在使用 Paperclip 运行一个 Rails 应用程序来处理文件附件和图像大小调整等。该应用程序当前托管在 EngineYard 云上,所有附件都存储在其 EBS 中。考虑使用 S3 处理所有回形针附件。
有谁知道这种迁移的良好且安全的方法?非常感谢!
I am running a Rails app using Paperclip to take care of file attachments and image resizing, etc. The app is currently hosted on EngineYard cloud, and all attachments are stored in their EBS. Thinking about using S3 to handle all Paperclip attachments.
Does anyone know of a good and safe way for this migration? many thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以执行一个 rake 任务来迭代您的附件并将每个附件推送到 S3。我不久前用过这个与attachment_fu——不会有太大不同。这使用了 aws-s3 gem。
基本上这个过程是:
1.从数据库中选择需要移动的文件
2.将它们推送到S3
3. 更新数据库以反映该文件不再存储在本地(这样您可以批量执行这些操作,并且无需担心将同一文件推送两次)。
You could work up a rake task that iterates over your attachments and pushes each to S3. I used this one awhile back with attachment_fu -- wouldn't be too different. This uses the aws-s3 gem.
Basically the process is:
1. Select files from the database that need to be moved
2. Push them to S3
3. Update database to reflect that the file is no longer stored locally (this way you can do them in batches and don't need to worry about pushing the same file twice).
我发现自己处于同样的情况,并采用了 bensie 的代码并使其适合自己 - 这就是我想到的:
当然,如果您有多个模型,您将需要根据需要进行调整......
I found myself in the same situation and took bensie's code and made it work for myself - this is what I came up with:
Of course, if you have multiple models you will need to adjust as necessary...