Migrating uploads from S3 to local

Nothing worked for me 100% unfortunately. What did you finally do?

1 Like

Any clue on how this may work in today’s 3.x versions? I still have a bunch of images on the S3 that I need to find a way to get back to local. Open to suggestions. (the rake uploads:migrate_from_s3 no longer exists)

I’ve set everything to work from local (only backup are on S3). Find many posts are still pointing to S3 with links like:

<img src="//x.amazonaws.com/original/1X/afda2721f64341ca46576020acae7aaee92bd9d3.PNG" width="308" height="206">

which points to

https://xxx.amazonaws.com/original/1X/afda2721f64341ca46576020acae7aaee92bd9d3.PNG

1 Like

Do you have any suggestions on this matter? I’m really tired of having problems with every update or change :slight_smile:

Not resolved. Would be nice if discourse had a solution

1 Like

Oh. If it’s your site and you have your stuff on S3, then you should be able to turn on S3, enable the hidden setting described in Enable hidden setting to include S3 uploads in the backups, make a backup, change the config to local images and restore the backup.

2 Likes

Would love to know if someone was able to make this work.

It works for every site the migrates from Discourse.org hosting to self-hosting (and has had that setting turned on before they got their backup).

It’s a little tricky since you have to have the S3 settings all set (in your YML file) when you create the backup and then turn them all back off (everywhere, including the database if you ever set them there) before you do the restore.

1 Like

It is a very logical method, but it does not work for those using cloudflare R2. Or this problem is only with me. When I made a backup, I also turned on the hidden setting. Unfortunately, it does not include the files in R2 in the backup. It gives the error here: Uploads in cloudflare R2 are not added to the backup: Failed to download ******* because Aws::S3::Errors::Http501Error

1 Like

The documentation and your experience suggest that R2 is not supported, so you will need to resolve the problem some other way.

I thought that it was working for me, but didnt’ test very carefully and haven’t used it beyond a trivial smoke test.

If the backup wont’ download the files from R2 then you’ll need to use some other tool to retreive the files from R2 and then push them to your new bucket and then update the database by hand (you can search for topics using the remap rake task, I think).

This is a complex process, so you’ll need to understand a good deal about R2, S3, and Discourse’s Uploads. It’ll likely be difficult to explain your exact issues with enough specificity that you can get a solution on a forum.

3 Likes

I manually download the files and upload them to the server. For those asking how to do this, you can connect to S3 accounts with the winscp program. Afterwards, you can easily import the files to your computer. Afterwards, I uploaded it to local and re-created the topics, it showed 0 posts. He did not take action. I changed it sometime and it didn’t find anything either. Maybe I missed a point, I don’t want to say it without testing again, maybe it was my fault. If I try again, I will write the results. Thanks.

1 Like

Getting the files to your server is just (the easy) part of the problem.

You can look at the uploads with

cd /var/discourse
./launcher enter app
rails c
Upload.pluck(:url)

That’ll show you the URLs of your uploads. Then you need to modify all of those uploads so that they have the new path to your new bucket. You can try searching for the remap command. I think it might work

I’m not sure what this means.

1 Like

Can you tell me how to do this part, do you mean just turn the include s3 upload in backups setting to false or something else?

1 Like

Configure an S3 compatible object storage provider for uploads describes how to configure S3 by adding to your app.yml. If you didn’t do it that way, then un-set all of the stuff having to do with S3 in the site settings and then do it that way.

If you did it that way, then just comment out those settings (or maybe just the use_s3 and upload bucket.

1 Like