Refactor backup system and migrate from submodule to shadow dependencies
- Remove s3-lite submodule and replace with AWS SDK and shadow plugin - Implement comprehensive backup commands with list, delete, create, restore, and suspend functionality - Add bundle format with compression support using Zstd and gunzip optimization - Implement local and S3 backup strategies with configurable options - Add backup tracking system with JSON persistence - Improve world directory handling and file exclusion logic - Add standalone bundler tool for bundle creation/extraction - Update Gradle configuration with shadow jar support and dependency management - Enhance configuration system with additional options for compression and temporary directories
This commit is contained in:
1 parent
6a2642ab93
commit
fb42be8155
21 files changed
+746
-183
No files matched your search
@@ -1,27 +1,34 @@
|
||||
package io.ib67.sfcraft;
|
||||
|
||||
import io.ib67.sfcraft.bundler.Bundle;
|
||||
import io.ib67.sfcraft.config.JustBackupConfig;
|
||||
import io.ib67.sfcraft.mixin.LevelStorageAccessor;
|
||||
import io.ib67.sfcraft.strategy.BackupStrategy;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import static io.ib67.sfcraft.JustBackupMod.PERFORMING_BACKUP;
|
||||
|
||||
@Log4j2
|
||||
public record BackupWorker(
|
||||
MinecraftServer server,
|
||||
BackupManager manager
|
||||
) implements Runnable {
|
||||
BackupStrategy strategy,
|
||||
JustBackupConfig config
|
||||
) implements Supplier<Backup> {
|
||||
|
||||
@Override
|
||||
@SneakyThrows
|
||||
public void run() {
|
||||
public Backup get() {
|
||||
if (server == null) {
|
||||
log.warn("MinecraftServer is not initialized yet, not doing backup");
|
||||
return;
|
||||
throw new IllegalStateException("MinecraftServer is not initialized yet, not doing backup");
|
||||
}
|
||||
int i = 0;
|
||||
while (!PERFORMING_BACKUP.compareAndSet(false, true)) {
|
||||
@@ -36,8 +43,20 @@ public record BackupWorker(
|
||||
}
|
||||
var session = ((LevelStorageAccessor) server).getSession();
|
||||
var path = session.getDirectory().getRootPath();
|
||||
manager.performBackup();
|
||||
strategy.createBackup(new WorldDir(Path.of(path)));
|
||||
var backupName = "Backup_" + DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(LocalDateTime.now());
|
||||
var backupParentRoot = Path.of(config.temporaryBackupDir());
|
||||
if (Files.notExists(backupParentRoot)) Files.createDirectories(backupParentRoot);
|
||||
var backupFile = backupParentRoot.resolve(backupName + ".jpack");
|
||||
log.info("Creating bundle {}", backupName);
|
||||
//todo diff
|
||||
Path worldDir = Path.of(path);
|
||||
new Bundle(new WorldDir(worldDir))
|
||||
.compress(config.compress())
|
||||
.allowGunzip(config.allowGunzip())
|
||||
.buildBundle(backupFile);
|
||||
var backup = strategy.createBackup(worldDir, backupFile);
|
||||
Files.deleteIfExists(backupFile);
|
||||
return backup;
|
||||
} finally {
|
||||
PERFORMING_BACKUP.set(false);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user