从本地回形针存储迁移到 S3 [英] Migrating from local paperclip storage to S3

查看:33
本文介绍了从本地回形针存储迁移到 S3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们最近迁移到了一个提供有限存储空间的新虚拟主机,因此我们正在尝试将通过 Paperclip gem 上传的所有用户上传内容(头像、文件等)移动到 Amazon S3.我有数百个文件,它们都对应于我现在正在尝试批量迁移的不同模型.

我发现这篇文档,介绍了一个漂亮的回形针耙任务:>

耙回形针:refresh:missing_styles

这个命令为我做了一些工作,但是,我注意到它只是设置文件结构而不发送任何数据 - 此外它没有设置任何使用 :styles 哈希定义的缩略图在 has_attached_file 调用中.即,我在我的一个模型上设置了以下回形针:

class User {:thumb =>"100x100#",:小 =>"150x150>",:中 =>200x200"}结尾

这是运行命令后的一些示例输出:

$ rake paperclip:refresh:missing_styles重新生成用户 ->头像 ->[拇指,:小,:中]再生水星::图像 ->图像 ->[:中,:拇指]重新生成配置文件 ->图像 ->[:home_feature, :large, :medium, :thumb]重新生成页面 ->预览 ->[:文件夹]再生类别 ->default_image ->[:home_feature, :large, :medium, :thumb]

导航到我的 S3 存储桶,我可以看到所有目录和每个附件都已正确设置,但仅限于原始图像文件,并且它们都是 0 字节.我误解了这个命令的用法吗?我找不到任何其他工具可以将整个文件目录批量上传到 S3,如果有一个安全的工具已经涵盖了这一点而无需付款,那么我会敞开心扉.我已经尝试构建一个 ruby​​ 脚本来插入他们的 SDK 并手动上传这些文件,但他们的 Ruby 文档不是很好.

解决方案

看起来我需要在这个问题上超越 ruby​​,s3cmd似乎是最适合这种工作的工具.就我而言,sync 命令起到了作用:

s3cmd 同步 my-app/public/system/s3://mybucket

We've recently moved to a new webhost that offers limited storage space so we're trying to move all of our user uploads (Avatars, Files, etc.) uploaded via the Paperclip gem to Amazon S3. I have several hundred files all corresponding to different models that I'm now trying to migrate en masse.

I found this document that introduces a nifty paperclip rake task:

rake paperclip:refresh:missing_styles

This command does some of the work for me, however, I noticed it's only setting up the files structure without sending any data - in addition it's not setting up any thumbnails defined using the :styles hash in the has_attached_file call. I.e., I have the following paperclip setup on one of my models:

class User < ActiveRecord::Base
  has_attached_file :avatar,
    :styles => {
      :thumb => "100x100#",
      :small  => "150x150>",
      :medium => "200x200" }
end

Here's some sample output after running the command:

$ rake paperclip:refresh:missing_styles
Regenerating User -> avatar -> [thumb, :small, :medium]
Regenerating Mercury::Image -> image -> [:medium, :thumb]
Regenerating Profile -> image -> [:home_feature, :large, :medium, :thumb]
Regenerating Page -> preview -> [:portfolio]
Regenerating Category -> default_image -> [:home_feature, :large, :medium, :thumb]

Navigating to my S3 Bucket I can see all the directories are correctly setup and for each attachment, but only for original image files and they're all 0 bytes. Am I misunderstanding the usage of this command? I couldn't find any other tool for uploading entire directories of files in bulk to S3, if there's a safe tool out there that already covers this without requiring payment then I'm open ears. I've tried building a ruby script to plug into their SDK and upload these files manually, but their Ruby documentation isn't great.

解决方案

Looks like I needed to go beyond ruby on this one, s3cmd seemed to be the most appropriate tool for this sort of job. In my case, the sync command did the trick:

s3cmd sync my-app/public/system/ s3://mybucket 

这篇关于从本地回形针存储迁移到 S3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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