Skip to content

Added option to compress file backups#8396

Open
Pesekjak wants to merge 4 commits intoSkriptLang:dev/featurefrom
Pesekjak:feature/compress-backups
Open

Added option to compress file backups#8396
Pesekjak wants to merge 4 commits intoSkriptLang:dev/featurefrom
Pesekjak:feature/compress-backups

Conversation

@Pesekjak
Copy link
Contributor

Problem

Backups of variables.csv can take up a lot of space for some users.

Solution

There is now an option in config to turn on automatic compression of those files. This also applies to other file backups (lang and config). I also refactored the backup method to replace the legacy code.

Testing Completed

I tested this manually, I believe we don't need automated test for this.


Completes: #8083
Related: none
AI assistance: none

@Pesekjak Pesekjak requested a review from a team as a code owner January 22, 2026 16:54
@Pesekjak Pesekjak requested review from Absolutionism and TheMug06 and removed request for a team January 22, 2026 16:54
@skriptlang-automation skriptlang-automation bot added the needs reviews A PR that needs additional reviews label Jan 22, 2026
@3add
Copy link
Contributor

3add commented Jan 22, 2026

iirc Skript's contribution requirements requires that all {} are placed after if, else, for, etc

Edit: just for for appearantly

@sovdeeth
Copy link
Member

iirc Skript's contribution requirements requires that all {} are placed after if, else, for, etc

They can be omitted for single line ifs without elses

@sovdeeth sovdeeth added the enhancement Feature request, an issue about something that could be improved, or a PR improving something. label Jan 22, 2026
String newFileName = name + "_" + getBackupSuffix() + ext;
boolean compress = SkriptConfig.compressBackups.value();
if (compress)
newFileName += ".gz";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.zip is more accessible, why pick gz?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are they not both equally accessible?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with fusezion, also gzip is better suited for compression of single files

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mojang uses .gz for the log files

# Whether Skript should log the usage of effect commands.
# They will be logged as [INFORMATION] in this format: '<player> issued effect command: <command>'

compress backups: false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what are the downsides of setting this to true by default?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

none (except you don't have to decompress to access) but I mainly wanted to keep the default behaviour the same as before. would you change it to true by default?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would change it true by default, if you're trying to access and/or modify the variables file you'd have to know what you're doing in which case unzipping the file isn't an issue.

@skriptlang-automation skriptlang-automation bot removed the needs reviews A PR that needs additional reviews label Jan 23, 2026
Co-authored-by: Efnilite <35348263+Efnilite@users.noreply.github.com>
@Pesekjak Pesekjak requested a review from Efnilite January 23, 2026 15:16
@TheLimeGlass
Copy link
Contributor

TheLimeGlass commented Feb 1, 2026

I recommend throwing some compression onto the GZip because the default compression isn't going to do much.

private static class GZIPOutputStreamWithLevel extends GZIPOutputStream {
	public GZIPOutputStreamWithLevel(OutputStream out, int level) throws IOException {
		super(out);
		this.def.setLevel(level);
	}
}
try (OutputStream os = Files.newOutputStream(backup); GZIPOutputStreamWithLevel gzipOs = new GZIPOutputStreamWithLevel(os, Deflater.BEST_COMPRESSION)) {
	Files.copy(source, gzipOs);
}

You can also use Apache's GzipCompressorOutputStream or TarArchiveOutputStream

Mojang uses the TarArchiveOutputStream for large files

@Pesekjak Pesekjak requested a review from TheLimeGlass February 3, 2026 10:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Feature request, an issue about something that could be improved, or a PR improving something.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants