# S3からEC2サーバーへすべてのファイルを手動で移行する方法は？

**URL:** https://meta.discourse.org/t/how-to-manually-migrate-all-files-from-s3-back-to-ec2-server/164746
**Category:** Support
**Created:** [2020 年 9 月 21 日午後 5:17 UTC](https://meta.discourse.org/t/how-to-manually-migrate-all-files-from-s3-back-to-ec2-server/164746 "2020-09-21T17:17:47Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Pravi](https://avatars.discourse-cdn.com/v4/letter/p/76d3ee/32.png) [@Pravi](https://meta.discourse.org/u/Pravi)
#### Post date: [2020 年 9 月 21 日午後 5:17 UTC](https://meta.discourse.org/t/how-to-manually-migrate-all-files-from-s3-back-to-ec2-server/164746/1 "2020-09-21T17:17:47Z")

</div>

新しいサーバーでサイトを復元した後、すべての画像が壊れています。画像を再ビルドしても壊れたままです。手動で移行することは可能でしょうか？可能であれば、S3 からローカルストレージへすべてのファイルをどのように手動で移行すればよいでしょうか？

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [2020 年 9 月 22 日午前 12:06 UTC](https://meta.discourse.org/t/how-to-manually-migrate-all-files-from-s3-back-to-ec2-server/164746/2 "2020-09-22T00:06:15Z")

</div>

新しいサイトの画像はS3バケットを指していますか？そうであれば、問題なく動作するはずです。

[Migrating uploads from S3 to local - #2 by Stephen](https://meta.discourse.org/t/migrating-uploads-from-s3-to-local/163903/2?u=pfaffman) を確認してみてください。ただし、#howto があるはずだと私は思います。

---

<div class="post-metadata">

### Author: ![Pravi](https://avatars.discourse-cdn.com/v4/letter/p/76d3ee/32.png) [@Pravi](https://meta.discourse.org/u/Pravi)
#### Post date: [2020 年 9 月 22 日午前 10:51 UTC](https://meta.discourse.org/t/how-to-manually-migrate-all-files-from-s3-back-to-ec2-server/164746/3 "2020-09-22T10:51:10Z")

</div>

こんにちは、ご返信ありがとうございます。

> [@pfaffman](#):
>
> [S3 からローカルへのアップロード移行](https://meta.discourse.org/t/migrating-uploads-from-s3-to-local/163903/2) をご覧になるのも一案ですが、#howto というタグがあるはずです。

以前ご教示いただいた手順と同じように試しましたが、何も変化がありませんでした。その結果、画像が破損したサイトになってしまいました。以前のトピックをご覧ください。

> [@Migrate\_from\_s3: You must disable S3 uploads before running that task](https://meta.discourse.org/t/migrate-from-s3-you-must-disable-s3-uploads-before-running-that-task/160633/21):
>
> Honestly, I would: put the original environment variables back (including DISCOURSE\_USE\_S3=false) and rebuild open /var/www/discourse/app/models/global\_setting.rb change the use\_s3? method to always return false (as per below) run the migrate-from-s3 task remove the variables completely and rebuild one more time We have someone scheduled to look into it, but this should tide you over meanwhile. On line 96-ish, change the self.use\_s3? method to look like: def self.use\_s3? false end

S3 から移行されたのは一部のファイルだけで、すべてではありません。

```
root@ubuntu-blr-app:/var/www/discourse# rake uploads:migrate_from_s3
Migrating uploads from S3 to local storage for 'default'...
..Done!

```

そのため、すべてのファイルを手動で移行することを考えているのですが、それが可能かどうか分かりません…

---

<div class="post-metadata">

### Author: ![Pravi](https://avatars.discourse-cdn.com/v4/letter/p/76d3ee/32.png) [@Pravi](https://meta.discourse.org/u/Pravi)
#### Post date: [2020 年 9 月 23 日午前 4:37 UTC](https://meta.discourse.org/t/how-to-manually-migrate-all-files-from-s3-back-to-ec2-server/164746/4 "2020-09-23T04:37:36Z")

</div>

![s3](https://global.discourse-cdn.com/meta/original/3X/8/d/8dd2a8b14b517f47345a5b4c1f5502791950e628.png)

私の S3 バケットには上記の 3 つのフォルダーがあります。これらのフォルダーを S3 からサーバーのどこにコピーすればよいかわかりません。コピーした後、`rake posts:rebake`を実行すれば最終的な処理が完了しますか？

---

<div class="post-metadata">

### Author: ![Pravi](https://avatars.discourse-cdn.com/v4/letter/p/76d3ee/32.png) [@Pravi](https://meta.discourse.org/u/Pravi)
#### Post date: [2020 年 9 月 24 日午前 7:17 UTC](https://meta.discourse.org/t/how-to-manually-migrate-all-files-from-s3-back-to-ec2-server/164746/5 "2020-09-24T07:17:41Z")

</div>

皆さん、この件についてどう思いますか？

---

<div class="post-metadata">

### Author: ![Pravi](https://avatars.discourse-cdn.com/v4/letter/p/76d3ee/32.png) [@Pravi](https://meta.discourse.org/u/Pravi)
#### Post date: [2020 年 9 月 25 日午後 12:06 UTC](https://meta.discourse.org/t/how-to-manually-migrate-all-files-from-s3-back-to-ec2-server/164746/6 "2020-09-25T12:06:47Z")

</div>

ついに、私の問題に対する解決策が見つかったと思います。問題の 95% は解決したと考えていますが、これが最善の方法かどうかは確信が持てません。

```
./launcher enter app
sudo apt install awscli
aws configure

```

S3 の ID とパスワードで AWS を設定しました。その後、

```
cd public/uploads/default/
aws s3 sync s3://mybucketname/

```

このコマンドで、S3 から 3 つのディレクトリとすべてのファイルをダウンロードしました。以前のサーバーで「inventory」という名前のフォルダが見つからなかったため、それを削除しました（このフォルダを削除してよかったのかは確信が持てません）。その後、

```
rake posts:rebake
exit
./launcher rebuild app

```

バム、すべてが正常に動作し始めました。ただし、投稿の 1 つにある画像リンクが壊れていることに気づきました。編集するとエディタで画像が表示されますが、同じ画像をダウンロードして再度アップロードしても、まだ画像が壊れたままです。これは別の問題なのか、それとも現在の問題に関連しているのかはわかりません。

 ![s55](https://global.discourse-cdn.com/meta/original/3X/f/a/fa3f3e4fbcf6686c47f044866cc6720d2b7fb4a3.jpeg)
