summaryrefslogtreecommitdiff
path: root/src/main/java/com/keuin/kbackupfabric/operation/RestoreOperation.java
diff options
context:
space:
mode:
authorKeuin <[email protected]>2021-01-13 17:47:20 +0800
committerkeuin <[email protected]>2021-01-13 17:47:20 +0800
commite0c6a21fe9bfb01237fd145064f0af309879a9fb (patch)
tree321955f96030213c2bc8c3ec350961a81b60edee /src/main/java/com/keuin/kbackupfabric/operation/RestoreOperation.java
parent2bc659d8f95a97d0514491e48ed9c66828a4e308 (diff)
Incremental backup now works (tested, but not thoroughly)
Diffstat (limited to 'src/main/java/com/keuin/kbackupfabric/operation/RestoreOperation.java')
-rw-r--r--src/main/java/com/keuin/kbackupfabric/operation/RestoreOperation.java34
1 files changed, 21 insertions, 13 deletions
diff --git a/src/main/java/com/keuin/kbackupfabric/operation/RestoreOperation.java b/src/main/java/com/keuin/kbackupfabric/operation/RestoreOperation.java
index 011d2e2..b870746 100644
--- a/src/main/java/com/keuin/kbackupfabric/operation/RestoreOperation.java
+++ b/src/main/java/com/keuin/kbackupfabric/operation/RestoreOperation.java
@@ -2,37 +2,35 @@ package com.keuin.kbackupfabric.operation;
import com.keuin.kbackupfabric.operation.abstracts.InvokableBlockingOperation;
import com.keuin.kbackupfabric.operation.backup.method.ConfiguredBackupMethod;
-import com.keuin.kbackupfabric.operation.backup.method.ConfiguredPrimitiveBackupMethod;
import com.keuin.kbackupfabric.util.PrintUtil;
import com.mojang.brigadier.context.CommandContext;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.command.ServerCommandSource;
import java.io.IOException;
+import java.util.Objects;
public class RestoreOperation extends InvokableBlockingOperation {
//private static final Logger LOGGER = LogManager.getLogger();
- private final String backupFileName;
private final Thread serverThread;
private final CommandContext<ServerCommandSource> context;
private final MinecraftServer server;
private final ConfiguredBackupMethod configuredBackupMethod;
- public RestoreOperation(CommandContext<ServerCommandSource> context, String backupSavePath, String levelPath, String backupFileName) {
- server = context.getSource().getMinecraftServer();
- this.backupFileName = backupFileName;
- this.serverThread = server.getThread();
- this.context = context;
- this.configuredBackupMethod = new ConfiguredPrimitiveBackupMethod(backupFileName, levelPath, backupSavePath);
+ public RestoreOperation(CommandContext<ServerCommandSource> context, ConfiguredBackupMethod configuredBackupMethod) {
+ server = Objects.requireNonNull(context.getSource().getMinecraftServer());
+ this.serverThread = Objects.requireNonNull(server.getThread());
+ this.context = Objects.requireNonNull(context);
+ this.configuredBackupMethod = Objects.requireNonNull(configuredBackupMethod);
}
@Override
protected boolean blockingContext() {
// do restore to backupName
- PrintUtil.broadcast(String.format("Restoring to backup %s ...", backupFileName));
+ PrintUtil.broadcast(String.format("Restoring to backup %s ...", configuredBackupMethod.getBackupFileName()));
- PrintUtil.debug("Backup file name: " + backupFileName);
+ PrintUtil.debug("Backup file name: " + configuredBackupMethod.getBackupFileName());
PrintUtil.msgInfo(context, "Server will shutdown in a few seconds, depending on world size and disk speed, the progress may take from seconds to minutes.", true);
PrintUtil.msgInfo(context, "Please do not force the server stop, or the level would be broken.", true);
@@ -58,7 +56,7 @@ public class RestoreOperation extends InvokableBlockingOperation {
@Override
public String toString() {
- return String.format("restoration from %s", backupFileName);
+ return String.format("restoration from %s", configuredBackupMethod.getBackupFileName());
}
private class WorkerThread implements Runnable {
@@ -71,7 +69,7 @@ public class RestoreOperation extends InvokableBlockingOperation {
while (serverThread.isAlive()) {
try {
serverThread.join();
- } catch (InterruptedException ignored) {
+ } catch (InterruptedException | RuntimeException ignored) {
}
}
@@ -85,7 +83,15 @@ public class RestoreOperation extends InvokableBlockingOperation {
}while(--cnt > 0);
////////////////////
+ long startTime = System.currentTimeMillis();
if (configuredBackupMethod.restore()) {
+ long endTime = System.currentTimeMillis();
+ PrintUtil.info(String.format(
+ "Restore complete! (%.2fs) Please restart the server manually.",
+ (endTime - startTime) / 1000.0
+ ));
+ PrintUtil.info("If you want to restart automatically after restoring, " +
+ "please check the manual at: https://github.com/keuin/KBackup-Fabric/blob/master/README.md");
//ServerRestartUtil.forkAndRestart();
System.exit(111);
} else {
@@ -94,9 +100,11 @@ public class RestoreOperation extends InvokableBlockingOperation {
} catch (SecurityException e) {
PrintUtil.error("An exception occurred while restoring: " + e.getMessage());
+ e.printStackTrace();
} catch (IOException e) {
PrintUtil.error(e.toString());
- PrintUtil.error("Failed to restore.");
+ PrintUtil.error("Failed to restore due to an unhandled I/O exception.");
+ e.printStackTrace();
}
System.exit(0); // all failed restoration will eventually go here
}