Closed jusvit closed 1 month ago
I have a prototype which I got stumped on because there's no region-specific claiming foundations.
Here's one of my server's backup (6GB and growing):
The overworld (under /region) consisting of 532 regions (544,768) chunks, 300 chunks of which are actually required to be backed up (claimed by players).
Pretty nasty overall with raw file manipulating.
Basically we call this every file we "backup":
private static boolean shouldSkipFileBackup(File sourceDirectory, File evaluateFile) {
// Only backup claimed chunks functionality
if (ServerUtilitiesConfig.backups.only_backup_claimed_chunks){
var evaluatePath = evaluateFile.getPath();
// Only care about region file format (e.g. under regions)
if (evaluatePath.endsWith(".mca")){
// Extract region coordinates into 4 parts (2 specifically): r | RegionX | RegionZ | mca
String fileName = evaluateFile.getName();
int firstDot = fileName.indexOf('.');
int secondDot = fileName.indexOf('.', firstDot + 1);
int RegionX = Integer.parseInt(fileName.substring(firstDot + 1, secondDot));
int RegionY = Integer.parseInt(fileName.substring(secondDot + 1, fileName.lastIndexOf('.')));
// Extract dimension
String relativePath = sourceDirectory.toPath().relativize(evaluateFile.toPath()).toString();
int dimension = 0; // Default to overworld
int dimIndex = relativePath.indexOf("DIM");
if (dimIndex != -1) {
int endIndex = relativePath.indexOf(File.separator, dimIndex);
String dimString = relativePath.substring(dimIndex + 3, endIndex == -1 ? relativePath.length() : endIndex);
dimension = Integer.parseInt(dimString);
}
// We either need to check if a region contains a claimed chunk which we keep the entire region or go into the mca which is nasty...
var chunkClaim = ClaimedChunks.instance.getChunk(new ChunkDimPos(chunkX, chunkZ, dimension));
// If chunkClaim is null, we skip backing up this chunk.
return chunkClaim == null;
}
}
// This file will be backed up
return false;
}
Also did a refactor of ThreadBackup.java but It didn't serve anything functionality-wise. It seems #100 already partially refactored it but could be further broken down.
Minecraft already has a way to get an InputStream of a specific chunk from a region file, which is definitely the way to go.
Server world's generally get really big and it would be nice to have some integration that would only backup the chunk MCA's that have been claimed by players so we could keep more backups, more frequently.
In the case that you need a backup, yes you would lose all the chunks which aren't claimed but it's a good compromise.