This guide explains how to enable a hidden setting in Discourse to include Amazon S3 (Simple Storage Service) uploads in your backups.
Discourse has the ability to store media uploads on Amazon S3 for scalability and reliability. However, these uploads are not included in backups by default.
This guide covers enabling a hidden setting to include S3 uploads in backups, with options to configure it via the Rails console or the app.yml file.
Using Rails Console
To enable S3 uploads to be included in backups via the Rails console, you can follow these steps:
Access your Discourse server via SSH.
Enter the Discourse Docker container by running:
cd /var/discourse
./launcher enter app
Launch the Rails console:
rails c
Enable the setting by executing:
SiteSetting.include_s3_uploads_in_backups = true
Exit the console and container by typing:
exit
exit
This change takes effect immediately. No further action is necessary.
Modifying the app.yml File
You can also make this change by adding modifying the app.yml file in the env: section.
Access the Discourse app container directory:
cd /var/discourse
Open the app.yml file located in containers:
nano containers/app.yml
Under the env: section, add the line:
DISCOURSE_INCLUDE_S3_UPLOADS_IN_BACKUPS: true
Save the file and exit the editor.
Apply the changes by rebuilding the app:
./launcher rebuild app
To have this change take effect, you need to run ./launcher rebuild app command to have the setting applied.
Iâm certain you need to destroy and start to change the env variables applied to the container.
Of course, if they have done upgrades with docker manager, those will be lost when the container is destroyed, which is why the rebuild is the safest recommendation. Maybe itâs best to recommend the rebuild since itâs the most foolproof.
Ok. I didnât know.
But, whatâs the diff between âLocal Uploadsâ and âFiles Stored in S3 âUploadsââ folder?
Also, though I havenât changed the setting in web_only or in rails console as told above YET, but only chose the one setting told here.
But still when I ran the backup, just 10 min ago, it showed as if it downloaded thousands of files, (which I presume could only be on my aws s3 storage bucket, and âDownloadâ word itself means it is downloading from remote S3 bucket folder).
Also it is showing it Failed to download many, So many files. So I presumed if these files were on local cloud server, why would it miss to include those files in the backup? See this screenshot:
If you have configured Configure an S3 compatible object storage provider for uploads and moved your local uploads to S3, then your uploads are there. They arenât backed up because itâs assumed that S3 is backed up and downloading them is expensive and usually unneccesary.
If you need to get them off of S3 (like if youâre hosted on discourse.org and are moving to some other hosting) then you need a backup that includes the files stored on S3.
Why do you want to download your files from S3?
Yes, it looks like itâs failing to download the files from S3. My guess is that it downloaded none of them, though itâs possbible that your disk is full, maybe (Iâd expect a disk full error, but maybe not?).
Mine being a very very small site, paying a few dollars, which are increasing every month with small updates, every month to Aws S3 storage is proving a bit unpractical to me. Iâm going to shift the âUploadsâ (and perhaps âbackupâ folder location also) to some other provider like Google One Drive, iDrive, Hetzner etc cheap alternatives.
I now find that even Awsâs diff types of storage (from the one most active towards arhival type of storage), if I had chosen them wisely in the beginning, would cost me just half for same qty/number of files.
When I chose to store my media âuploadsâ to aws S3 bucket years ago, at that time (as much as Iâm sure) ALSO MOVED all the existing media uploaded by the users to S3.
Moreover, I also checked now in my /var/discourse/shared/web_only/uploads/default/optimized/1X folder, it has only 63 png files and /var/discourse/shared/web_only/uploads/default/original/1X has just 3. (Except 1x no other similar folders exist in the âuploads or defaultâ folder.
Also, Iâve not changed any option in the rails console or in the Yml file YET to include s3 uploads in my backups. So, why is it showing that it has downloaded so many âMedia Uploadsâ FROM S3 !!!
And, failed to download so many Uploaded files? Screenshot here.
Moreover, my uploads folder on S3 is around 3 gb (32k files). whereas the backup logs showed that it downloaded only around 3.2k (10% of total).
Very confusing.
Is there any OTHER rails command to be double sure if that option wasnât toggled on years back, when I shifted to Aws S3?