Reduce local disk space needs by not (redundantly) gzipping backups

AI-generated summary

The discussion addresses excessive disk space usage during Discourse backups, specifically when uploads are already compressed. Ed_S points out that the current process creates a .tar file and then gzips it, resulting in redundant compression and requiring nearly double the disk space for the backup operation. gerhard initially announced work on a new format to remove this double compression, but later clarified that the feature was paused due to roadmap priorities.

The community explored potential fixes. Isambard proposed disabling gzip to save CPU, but Ed_S corrected that this wouldn’t solve the disk space issue unless the compression was streamed. RGJ and Ed_S identified that using tar’s built-in --gzip or --auto-compress flags would stream data directly to compression, preventing the intermediate uncompressed tar file from hitting the disk. Ed_S also suggested zstd for better speed and compression ratios.

Despite the apparent simplicity of the fix, progress stalled due to the critical nature of backup reliability. CT075 expressed frustration over repeated backup failures caused by space limits, noting the fix had been known for over a year. pfaffman marked the issue as #pr-welcome, encouraging community contributions while acknowledging the risks of breaking restore functionality.

Ultimately, david announced a merged solution via pull request #44908. This update eliminates the 2x disk space requirement by streaming compression and spreads out CPU usage. While the team considered dropping the wrapper .gz entirely, they proceeded with caution to maintain format compatibility. david confirmed the change has been stable for some time, inviting users to open new topics if issues arise.

The backup process creates a tar file and then applies gzip to it. There are two types of things in the tar file: an already gzipped sql dump and the contents of uploads (if requested.) In my case every upload file is already compressed: gz, gzip, gif, jpeg, png, zip. So the final gzipping gains only 1% of size.

I believe it would be better to demand less free space.

A previous topic from 2016 mentions disabling backup compression, but it looks like the sql dump was at that time not compressed, which shifted the tradeoffs.

Add option to disable backup compression

12 Likes

I’m already working on a new backup format that removes the double compression. My hope is that it will be ready within a month or two.

14 Likes

Sounds great @gerhard!

2 Likes

Any update on this? Thanks

1 Like

Not to bug you too much, but how is this progressing?

Development of that feature is currently paused and it isn’t on our current roadmap. I hope we will get to it in 2024.

5 Likes

If I wrote a patch to accept a 0 in the compression rate to disable gzip, would that be something that you would accept?

1 Like

(I’m guessing that you’d save CPU time that way, but not space, because the gzipped tar file would still be created.)

I’m aiming to save cpu time. Actually, I was thinking of using the 0 as a flag that would change the code path so that it doesn’t gzip (sadly, zero is not a valid compression level supported across all gzip versions, afaik).

Hmm that wouldn’t help me at all! (Likewise others who’ve had the same problem with limited disk space.)

If tar were being used, it could be used with z or j options. If a subshell were being used, the output of tar could be piped into gzip. But I think in fact some higher level ruby functions may be in use.

1 Like

cough

3 Likes

Maybe it shouldn’t be too difficult… I appreciate that making changes to backup and restore must be made with great care, but I think just inlining the compression would save a lot of space requirement without any compatibility question.

From tar --help

-a, --auto-compress use archive suffix to determine the compression
-z, --gzip, --gunzip, --ungzip filter the archive through gzip

1 Like

Does -z actually do an in-place compression? I always assumed that it just ran gzip after the tar file is completed.

Unwisely, in this case! The bytes which represent the uncompressed tar file never hit the disk.

2 Likes

Are you saying we can simply add
"--gzip",

And it will stop requiring fully double the actually space used used the data?

2 Likes

Yes, that’s the change to the tar command.

1 Like

Looks like an even better choice is --zstd but then we’d also need ‘zstd’ package installed in the docker image.

3 Likes

Possibly a better approach which might simplify things - being able to deal with existing backups which might be *.gz or *.zst - is to use tar’s automatic detection:

tar --auto-compress -c -f ../file.tar.gz .
tar --auto-compress -c -f ../file.tar.zst .

More important for the unpacking, of course, where we might not know what we’re going to see.

Presently the ruby code seems to do lots of things which tar itself can do. Hopefully this can be simplified, rather than becoming more complex.

3 Likes

zstd is also a great deal quicker - which makes it less problematic that we spend time compressing the near-incompressible.

(If zstd were also used for the sql dump, in my case that comes out 10% smaller.)

3 Likes

Hi, is there any news on this? From this reply it seems like we’ve known that this is a one line fix for over a year, so it’s quite frustrating to continue to wake up to backup failed DMs despite having almost 30G free on the server.

I would make the PR myself if signing the CLA didn’t require me to enter a physical mailing address.

3 Likes