From 021959233f38d1bbcfe6fbcac4c64ab524a70eac Mon Sep 17 00:00:00 2001 From: Keuin Date: Fri, 8 May 2020 15:44:24 +0800 Subject: Added script-based auto reboot support (after restoring). --- .../com/keuin/kbackupfabric/operation/BackupOperation.java | 3 ++- .../com/keuin/kbackupfabric/operation/RestoreOperation.java | 12 +++++++++++- .../operation/abstracts/AbstractBlockingOperation.java | 4 ++-- 3 files changed, 15 insertions(+), 4 deletions(-) (limited to 'src/main/java/com/keuin/kbackupfabric/operation') diff --git a/src/main/java/com/keuin/kbackupfabric/operation/BackupOperation.java b/src/main/java/com/keuin/kbackupfabric/operation/BackupOperation.java index bceca40..53b05b8 100644 --- a/src/main/java/com/keuin/kbackupfabric/operation/BackupOperation.java +++ b/src/main/java/com/keuin/kbackupfabric/operation/BackupOperation.java @@ -1,10 +1,10 @@ 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.util.PrintUtil; import com.keuin.kbackupfabric.util.ZipUtil; -import com.keuin.kbackupfabric.exception.ZipUtilException; import com.mojang.brigadier.context.CommandContext; import net.minecraft.server.MinecraftServer; import net.minecraft.server.command.ServerCommandSource; @@ -53,6 +53,7 @@ public class BackupOperation extends InvokableAsyncBlockingOperation { String levelPath = getLevelPath(server); String backupFileName = getBackupFileName(backupName); PrintUtil.info(String.format("zip(srcPath=%s, destPath=%s)", levelPath, backupSaveDirectoryFile.toString())); + msgInfo(context, "Compressing worlds ..."); PrintUtil.info("Compressing level ..."); ZipUtil.makeBackupZip(levelPath, backupSaveDirectoryFile.toString(), backupFileName, backupMetadata); File backupZipFile = new File(backupSaveDirectoryFile, backupFileName); diff --git a/src/main/java/com/keuin/kbackupfabric/operation/RestoreOperation.java b/src/main/java/com/keuin/kbackupfabric/operation/RestoreOperation.java index 42003db..6754393 100644 --- a/src/main/java/com/keuin/kbackupfabric/operation/RestoreOperation.java +++ b/src/main/java/com/keuin/kbackupfabric/operation/RestoreOperation.java @@ -1,9 +1,9 @@ package com.keuin.kbackupfabric.operation; +import com.keuin.kbackupfabric.exception.ZipUtilException; import com.keuin.kbackupfabric.operation.abstracts.InvokableBlockingOperation; import com.keuin.kbackupfabric.util.PrintUtil; import com.keuin.kbackupfabric.util.ZipUtil; -import com.keuin.kbackupfabric.exception.ZipUtilException; import com.mojang.brigadier.context.CommandContext; import net.minecraft.server.MinecraftServer; import net.minecraft.server.command.ServerCommandSource; @@ -121,6 +121,16 @@ public class RestoreOperation extends InvokableBlockingOperation { ZipUtil.unzip(backupFilePath, levelDirectory, false); 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 visit the project manual at: https://github.com/keuin/KBackup-Fabric/blob/master/README.md"); + + try { + Thread.sleep(1000); + } catch (InterruptedException ignored) { + } + + //ServerRestartUtil.forkAndRestart(); + System.exit(111); + } catch (SecurityException | IOException | ZipUtilException e) { PrintUtil.error("An exception occurred while restoring: " + e.getMessage()); } diff --git a/src/main/java/com/keuin/kbackupfabric/operation/abstracts/AbstractBlockingOperation.java b/src/main/java/com/keuin/kbackupfabric/operation/abstracts/AbstractBlockingOperation.java index de672cd..15b72c9 100644 --- a/src/main/java/com/keuin/kbackupfabric/operation/abstracts/AbstractBlockingOperation.java +++ b/src/main/java/com/keuin/kbackupfabric/operation/abstracts/AbstractBlockingOperation.java @@ -13,11 +13,11 @@ public abstract class AbstractBlockingOperation extends AbstractSerializedOperat protected final boolean operate() { synchronized (sync) { if (isBlocking) { - System.out.println("blocked."); +// System.out.println("blocked."); wasBlocked = true; return false; } else { - System.out.println("not blocked."); +// System.out.println("not blocked."); wasBlocked = false; isBlocking = true; } -- cgit v1.2.3