# Migrating uploads from S3 to local

**URL:** https://meta.discourse.org/t/migrating-uploads-from-s3-to-local/163903
**Category:** Self-hosting
**Tags:** s3
**Created:** [September 13, 2020, 10:41pm UTC](https://meta.discourse.org/t/migrating-uploads-from-s3-to-local/163903 "2020-09-13T22:41:36Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![hosna](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/hosna/32/99969_2.png) [@hosna](https://meta.discourse.org/u/hosna)
#### Post date: [September 13, 2020, 10:41pm UTC](https://meta.discourse.org/t/migrating-uploads-from-s3-to-local/163903/1 "2020-09-13T22:41:36Z")

</div>

I want to migrate my files from s3 back to local. I’m manually transferring all files from s3 to uploads folder. Then should be changing the base url of upload links, back to forum base url, sufficient to do the job done?

---

<div class="post-metadata">

### Author: ![Stephen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/stephen/32/95011_2.png) [@Stephen](https://meta.discourse.org/u/Stephen)
#### Post date: [September 13, 2020, 10:58pm UTC](https://meta.discourse.org/t/migrating-uploads-from-s3-to-local/163903/2 "2020-09-13T22:58:27Z")

</div>

Why aren’t you using the built-in rake task? afaik it’s called uploads:migrate\_from\_s3

```plaintext
cd /var/discourse
./launcher enter app
rake uploads:migrate_from_s3

```

Then disable the `enable s3 uploads` site setting:

And finally rebake:

```
rake posts:rebake

```

---

<div class="post-metadata">

### Author: ![hosna](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/hosna/32/99969_2.png) [@hosna](https://meta.discourse.org/u/hosna)
#### Post date: [September 14, 2020, 4:36am UTC](https://meta.discourse.org/t/migrating-uploads-from-s3-to-local/163903/3 "2020-09-14T04:36:21Z")

</div>

> [@Stephen](#):
>
> Why aren’t you using the built-in rake task? afaik it’s called uploads:migrate\_from\_s3

Because my s3 is minio and I’m not sure if this function is compatible with it or not.

---

<div class="post-metadata">

### Author: ![hosna](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/hosna/32/99969_2.png) [@hosna](https://meta.discourse.org/u/hosna)
#### Post date: [September 20, 2020, 9:16pm UTC](https://meta.discourse.org/t/migrating-uploads-from-s3-to-local/163903/4 "2020-09-20T21:16:42Z")

</div>

> [@Stephen](#):
>
> `rake uploads:migrate_from_s3`

I tried this and after it was done, I didnt see any change in uploads. Still uploads are served from s3. btw the rake task was wierd to me. It ended so fast while I have thousnds of s3 uploads. It shouldve taked a while.

---

<div class="post-metadata">

### Author: ![hosna](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/hosna/32/99969_2.png) [@hosna](https://meta.discourse.org/u/hosna)
#### Post date: [September 21, 2020, 5:29am UTC](https://meta.discourse.org/t/migrating-uploads-from-s3-to-local/163903/5 "2020-09-21T05:29:38Z")

</div>

I have all my uploads transferred to local manually. Is there something that I can do to change all of the links in database and posts directly? I don’t need to use this rake task.

---

<div class="post-metadata">

### Author: ![RBoy](https://avatars.discourse-cdn.com/v4/letter/r/2bfe46/32.png) [@RBoy](https://meta.discourse.org/u/RBoy)
#### Post date: [May 3, 2021, 4:16pm UTC](https://meta.discourse.org/t/migrating-uploads-from-s3-to-local/163903/6 "2021-05-03T16:16:46Z")

</div>

Did you figure this out? I’m also looking to migrate all assets (everything except backups) from S3 back to the local. Is there an easy way to do this?

---

<div class="post-metadata">

### Author: ![Bathinda](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bathinda/32/135888_2.png) [@Bathinda](https://meta.discourse.org/u/Bathinda)
#### Post date: [May 9, 2021, 12:03pm UTC](https://meta.discourse.org/t/migrating-uploads-from-s3-to-local/163903/7 "2021-05-09T12:03:26Z")

</div>

I too am looking for similar option. But I read somewhere on this very site, that for this to work correctly, some big problems are to be sorted first. So, for the time being, they recommend not to shift S3 to local.

Though I’m also anxiously waiting for the solution to this problem.

---

<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: [May 9, 2021, 12:16pm UTC](https://meta.discourse.org/t/migrating-uploads-from-s3-to-local/163903/8 "2021-05-09T12:16:28Z")

</div>

There is a hidden site setting called something like “download S3 uploads to local on backup”. I think you can use that and restore to another server (or maybe your server if you change settings with shadowed site settings in environment variables). This is what cdck does when you close an account and I’ve never had trouble restoring one of their backups.

---

<div class="post-metadata">

### Author: ![Bathinda](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bathinda/32/135888_2.png) [@Bathinda](https://meta.discourse.org/u/Bathinda)
#### Post date: [May 9, 2021, 12:19pm UTC](https://meta.discourse.org/t/migrating-uploads-from-s3-to-local/163903/9 "2021-05-09T12:19:24Z")

</div>

> [@pfaffman](#):
>
> There is a hidden site setting called something like “download S3 uploads to local on backup”.

I did commanded that setting in Rails console `SiteSetting.include_s3_uploads_in_backups = true`. But it still didn’t (seem to) have any effect. The backup still was the same size (approx 375 MB, even when my uploads are around 700 MB to 1GB).

> [@pfaffman](#):
>
> shadowed site settings in environment variables

If by ‘Shadowed site settings’ you mean all the S3 site settings in Disco Web UI, then I do have all those settings filled in those fields.

---

<div class="post-metadata">

### Author: ![vrrrmmmm](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vrrrmmmm/32/222426_2.png) [@vrrrmmmm](https://meta.discourse.org/u/vrrrmmmm)
#### Post date: [May 29, 2021, 7:20pm UTC](https://meta.discourse.org/t/migrating-uploads-from-s3-to-local/163903/10 "2021-05-29T19:20:57Z")

</div>

I’m also looking to migrate my uploads from S3 to local (separate VPS). Is there a documented procedure for this?

---

<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: [May 29, 2021, 8:13pm UTC](https://meta.discourse.org/t/migrating-uploads-from-s3-to-local/163903/11 "2021-05-29T20:13:45Z")

</div>

Not really. I’d try using the setting I described above

---

<div class="post-metadata">

### Author: ![RBoy](https://avatars.discourse-cdn.com/v4/letter/r/2bfe46/32.png) [@RBoy](https://meta.discourse.org/u/RBoy)
#### Post date: [October 21, 2021, 3:51pm UTC](https://meta.discourse.org/t/migrating-uploads-from-s3-to-local/163903/12 "2021-10-21T15:51:47Z")

</div>

Is there a way to find these hidden settings?

---

<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: [October 21, 2021, 7:40pm UTC](https://meta.discourse.org/t/migrating-uploads-from-s3-to-local/163903/13 "2021-10-21T19:40:43Z")

</div>

The one that you might need in context of this discussion is mentioned above. You can see them all in site\_settings.yml in the Discourse source.

---

<div class="post-metadata">

### Author: ![RBoy](https://avatars.discourse-cdn.com/v4/letter/r/2bfe46/32.png) [@RBoy](https://meta.discourse.org/u/RBoy)
#### Post date: [August 9, 2022, 2:44pm UTC](https://meta.discourse.org/t/migrating-uploads-from-s3-to-local/163903/14 "2022-08-09T14:44:49Z")

</div>

> [@Stephen](#):
>
> rake uploads:migrate\_from\_s3

This rake task is no longer available in 2.9.0 BETA 8

Anyone have an ideas how to migrate from S3 to local?

---

<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: [August 14, 2022, 10:55am UTC](https://meta.discourse.org/t/migrating-uploads-from-s3-to-local/163903/15 "2022-08-14T10:55:56Z")

</div>

You can turn on the hidden site setting that’s called something like download\_s3\_with\_backups (that’s not quite right but I can’t find it on my phone right now) and then restore that backup. That’s what happens when you leave cdck hosting, and it works. You might need to restore to a different server (and u would anyway to test).

Edit: thanks @Benjamin_D! it’s `include_s3_uploads_in_backups`

---

<div class="post-metadata">

### Author: ![Benjamin\_D](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/benjamin_d/32/277831_2.png) [@Benjamin\_D](https://meta.discourse.org/u/Benjamin_D)
#### Post date: [August 14, 2022, 6:52pm UTC](https://meta.discourse.org/t/migrating-uploads-from-s3-to-local/163903/16 "2022-08-14T18:52:42Z")

</div>

I think this is it:

> <https://github.com/discourse/discourse/blob/f25e77922684fc780d7b050ffb808b3374206dc3/config/site_settings.yml#L2066-L2068>

---

<div class="post-metadata">

### Author: ![RBoy](https://avatars.discourse-cdn.com/v4/letter/r/2bfe46/32.png) [@RBoy](https://meta.discourse.org/u/RBoy)
#### Post date: [August 15, 2022, 2:12pm UTC](https://meta.discourse.org/t/migrating-uploads-from-s3-to-local/163903/17 "2022-08-15T14:12:39Z")

</div>

Isn’t that option is available on the Settings page in the Admin website controls `Backup` Settings page? Also isn’t this the opposite of downloading the S3 files?

 ![image](https://global.discourse-cdn.com/meta/original/4X/1/3/8/138db99d6bf6d51a102a534cd14b576c0b2ed88b.jpeg)

---

<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: [August 15, 2022, 2:22pm UTC](https://meta.discourse.org/t/migrating-uploads-from-s3-to-local/163903/18 "2022-08-15T14:22:57Z")

</div>

> [@RBoy](#):
>
> Isn’t that option is available on the Settings page in the Admin website controls `Backup` Settings page?

No.

`backup_with_uploads` is not the same as `include_s3_uploads_in_backups`. One includes local files in the backup. The other downloads every single file from s3 every time you make a backup. And the whole point of s3 is that you don’t need to make backups of it.

---

<div class="post-metadata">

### Author: ![RBoy](https://avatars.discourse-cdn.com/v4/letter/r/2bfe46/32.png) [@RBoy](https://meta.discourse.org/u/RBoy)
#### Post date: [August 25, 2022, 6:46pm UTC](https://meta.discourse.org/t/migrating-uploads-from-s3-to-local/163903/19 "2022-08-25T18:46:47Z")

</div>

> [@pfaffman](#):
>
> backup\_with\_uploads

So this includes local files when backing up to the S3

> [@pfaffman](#):
>
> include\_s3\_uploads\_in\_backups

This downloads files from the S3 store to include in the backup (which could be local or on the S3)

* * *

I’m trying to understand the right steps here, the goal is to migrate all files from S3 to local, so if I understand what you’re saying:

1. Enable `backup_with_uploads` from the rails console
2. Create a backup (either local or on S3)
3. Restore using the backup
4. Disable `backup_with_uploads` from the rails console

Is that correct?

---

<div class="post-metadata">

### Author: ![satonotdead](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/satonotdead/32/447830_2.png) [@satonotdead](https://meta.discourse.org/u/satonotdead)
#### Post date: [May 17, 2023, 1:54pm UTC](https://meta.discourse.org/t/migrating-uploads-from-s3-to-local/163903/20 "2023-05-17T13:54:20Z")

</div>

So, what’s the actual best approach to move from S3 to local? 🙂

- Manually moving the files (_optimized/original_ folders) and make a post-rebake after disabling the S3 option from Discourse?
- Use the shadowed `download_s3_with_backups` admin option, download and unzip those files?
- `rake uploads:migrate_from_s3`?

[Next page](https://meta.discourse.org/t/migrating-uploads-from-s3-to-local/163903.md?page=2)
