summaryrefslogtreecommitdiff
path: root/src/main/java/com/keuin/kbackupfabric/operation/BackupOperation.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/keuin/kbackupfabric/operation/BackupOperation.java')
-rw-r--r--src/main/java/com/keuin/kbackupfabric/operation/BackupOperation.java44
1 files changed, 15 insertions, 29 deletions
diff --git a/src/main/java/com/keuin/kbackupfabric/operation/BackupOperation.java b/src/main/java/com/keuin/kbackupfabric/operation/BackupOperation.java
index d03c347..b38921d 100644
--- a/src/main/java/com/keuin/kbackupfabric/operation/BackupOperation.java
+++ b/src/main/java/com/keuin/kbackupfabric/operation/BackupOperation.java
@@ -1,39 +1,32 @@
package com.keuin.kbackupfabric.operation;
-import com.keuin.kbackupfabric.exception.ZipUtilException;
-import com.keuin.kbackupfabric.metadata.BackupMetadata;
import com.keuin.kbackupfabric.operation.abstracts.InvokableAsyncBlockingOperation;
-import com.keuin.kbackupfabric.operation.backup.BackupMethod;
+import com.keuin.kbackupfabric.operation.backup.feedback.BackupFeedback;
+import com.keuin.kbackupfabric.operation.backup.method.ConfiguredBackupMethod;
import com.keuin.kbackupfabric.util.PrintUtil;
-import com.keuin.kbackupfabric.util.backup.builder.BackupFileNameBuilder;
-import com.keuin.kbackupfabric.util.backup.formatter.BackupFileNameFormatter;
import com.mojang.brigadier.context.CommandContext;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.world.World;
-import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
-import static com.keuin.kbackupfabric.util.backup.BackupFilesystemUtil.*;
import static com.keuin.kbackupfabric.util.PrintUtil.msgInfo;
public class BackupOperation extends InvokableAsyncBlockingOperation {
private final CommandContext<ServerCommandSource> context;
- private final String backupName;
private final Map<World, Boolean> oldWorldsSavingDisabled = new HashMap<>();
- private final BackupMethod backupMethod;
+ private final ConfiguredBackupMethod configuredBackupMethod;
private long startTime;
- public BackupOperation(CommandContext<ServerCommandSource> context, String backupName, BackupMethod backupMethod) {
+ public BackupOperation(CommandContext<ServerCommandSource> context, ConfiguredBackupMethod configuredBackupMethod) {
super("BackupWorker");
this.context = context;
- this.backupName = backupName;
- this.backupMethod = backupMethod;
+ this.configuredBackupMethod = configuredBackupMethod;
}
@Override
@@ -44,27 +37,20 @@ public class BackupOperation extends InvokableAsyncBlockingOperation {
//// Do our main backup logic
// Create backup saving directory
- File backupSaveDirectoryFile = getBackupSaveDirectory(server);
- backupSaveDirectory = backupSaveDirectoryFile.getName();
- if (!backupSaveDirectoryFile.isDirectory() && !backupSaveDirectoryFile.mkdir()) {
- msgInfo(context, String.format("Failed to create backup saving directory: %s. Failed to backup.", backupSaveDirectory));
+ if (!configuredBackupMethod.touch()) {
+ PrintUtil.msgErr(context, "Failed to create backup save directory. Cannot backup.");
return;
}
- // Make zip
- String levelPath = getLevelPath(server);
- String backupFileName = getBackupFileName(backupName);
-
- BackupMethod.BackupResult result = backupMethod.backup(backupName,levelPath,backupSaveDirectory);
- if(result.isSuccess()) {
- // Restore old autosave switch stat
+ // Backup
+ BackupFeedback result = configuredBackupMethod.backup();
+ if (result.isSuccess()) {
+ // Restore old auto-save switch stat
server.getWorlds().forEach(world -> world.savingDisabled = oldWorldsSavingDisabled.getOrDefault(world, true));
// Print finish message: time elapsed and file size
long timeElapsedMillis = System.currentTimeMillis() - startTime;
- String msgText = String.format("Backup finished. Time elapsed: %.2fs.", timeElapsedMillis / 1000.0);
- File backupZipFile = new File(backupSaveDirectory, backupFileName);
- msgText += String.format(" File size: %s.", humanFileSize(result.getBackupSizeBytes()));
+ String msgText = String.format("Backup finished. Time elapsed: %.2fs. ", timeElapsedMillis / 1000.0) + result.getFeedback();
PrintUtil.msgInfo(context, msgText, true);
} else {
// failed
@@ -79,14 +65,14 @@ public class BackupOperation extends InvokableAsyncBlockingOperation {
@Override
protected boolean sync() {
- //// Save world, save old autosave configs
+ //// Save world, save old auto-save configs
- PrintUtil.broadcast(String.format("Making backup %s, please wait ...", backupName));
+ PrintUtil.broadcast("Making backup, please wait ...");
// Get server
MinecraftServer server = context.getSource().getMinecraftServer();
- // Save old autosave switch stat temporally
+ // Save old auto-save switch state for restoration after finished
oldWorldsSavingDisabled.clear();
server.getWorlds().forEach(world -> {
oldWorldsSavingDisabled.put(world, world.savingDisabled);