我怎样才能CarrierWave文件迁移到新的存储机制? [英] How can I migrate CarrierWave files to a new storage mechanism?

查看:147
本文介绍了我怎样才能CarrierWave文件迁移到新的存储机制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Ruby on Rails的网站使用CarrierWave用于文件处理,目前使用本地存储模型。我想开始使用云存储,我需要现有的本地文件迁移到云中。我想知道如果任何人都可以点出了一种这样做呢?

I have a Ruby on Rails site with models using CarrierWave for file handling, currently using local storage. I want to start using cloud storage and I need to migrate existing local files to the cloud. I am wondering if anyone can point out a method for doing this?

积分为使用一个模型属性,让我做这行由行的背景,而不会中断我的网站,延长停机时间(换句话说,某些型号的行还是会有,而其他使用云存储本地存储)。

Bonus points for using a model attribute that would allow me to do this row-by-row in the background without interrupting my site for extended downtime (in other words, some model rows would still have local storage while others used cloud storage).

我的第一反应是创建一个使用云存储的每个模型的新上传,所以我有两个上传者对每一个模型,然后从一个到另一个传输文件,设置一个属性来指示哪个文件应该被使用,直到他们全部转移,然后删除旧上传。这似乎有点过分。

My first instinct is to create a new uploader for each model that uses cloud storage, so I have two uploaders on each model, then transferring the files from one to the other, setting an attribute to indicate which file should be used until they are all transferred, then removing the old uploader. That seems a little excessive.

推荐答案

最小为可能为零Donwtime程序

在我看来,以完成最简单和最快的方式你想要什么,几乎没有停机时间是这样的:(我会假设你将使用AWS的云,但类似的方法适用于所有云服务)

In my opinion, the easiest and fastest way to accomplish what you want with almost no downtime is this: (I will assume that you will use AWS cloud, but similar procedure is applicable to any cloud service)

  1. 找出和设置您的资产水桶,水桶等政策为使资产向公众开放。
  2. 使用 s3cmd (命令行工具与S3交互)或GUI应用程序,复制整个资产的文件夹的文件系统在S3中相应的文件夹。
  3. 在您的应用程序,设置carrierwave和更新您的模型/上传者为:雾存储
  4. 不要重新启动您的应用程序呢。相反,带来了铁轨控制台和你的模型,检查按计划,新资产的网址是正确的和可访问的。例如,对于与图片资产的视频模式,可以通过这个方式:

  1. Figure out and setup your assets bucket, bucket policies etc for making the assets publicly accessible.
  2. Using s3cmd (command line tool for interacting with S3) or a GUI app, copy entire assets folder from file system to the appropriate folder in S3.
  3. In your app, setup carrierwave and update your models/uploaders for :fog storage.
  4. Do not restart your application yet. Instead bring up rails console and for your models, check that the new assets URL is correct and accessible as planned. For example, for a video model with picture asset, you can check this way:

Video.first.picture.url

这会给你的基础上更新设置一个完整的云的URL。复制此URL,并粘贴到浏览器中,以确保你能得到它的罚款。

This will give you a full cloud URL based on the updated settings. Copy the URL and paste in a browser to make sure that you can get to it fine.

如果这个工程的每个模型具有资产至少一个实例,你是好重新启动应用程序。

If this works for at least one instance of each model that has assets, you are good to restart your application.

在重新启动时,所有资产正从云服务,而且你也没必要在你的模型的任何迁移或多个上传者。

Upon restart, all your assets are being served from cloud, and you didn't need any migrations or multiple uploaders in your models.

(根据由@Frederick祥评论):使用 s3cmd (或类似的东西)的rsync 同步,从文件系统到S3资产的文件夹占步骤2和5之间上载的资产(如有)。

(Based on comment by @Frederick Cheung): Using s3cmd (or something similar) rsync or sync the assets folder from the filesystem to S3 to account for assets that were uploaded between steps 2 and 5, if any.

PS:如果您需要帮助建立carrierwave云存储,让我知道。

PS: If you need help setting up carrierwave for cloud storage, let me know.

这篇关于我怎样才能CarrierWave文件迁移到新的存储机制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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