From b692a73e039fbdb404ef1219785660dc9eb60e60 Mon Sep 17 00:00:00 2001 From: Keuin Date: Fri, 24 Apr 2020 11:55:18 +0800 Subject: Added /kb delete for deleting an backup (with auto-complete supported). Command /kb confirm now confirms both /kb restore and /kb delete. Added /kb prev for easily check out the latest backup. --- .../java/com/keuin/kbackupfabric/worker/BackupWorker.java | 11 ++++------- .../java/com/keuin/kbackupfabric/worker/RestoreWorker.java | 12 +++++++----- 2 files changed, 11 insertions(+), 12 deletions(-) (limited to 'src/main/java/com/keuin/kbackupfabric/worker') diff --git a/src/main/java/com/keuin/kbackupfabric/worker/BackupWorker.java b/src/main/java/com/keuin/kbackupfabric/worker/BackupWorker.java index 57e59fb..3303f70 100644 --- a/src/main/java/com/keuin/kbackupfabric/worker/BackupWorker.java +++ b/src/main/java/com/keuin/kbackupfabric/worker/BackupWorker.java @@ -56,9 +56,9 @@ public final class BackupWorker implements Runnable { }); // Force to save all player data and worlds - LOGGER.debug("Saving players ..."); + LOGGER.info("Saving players ..."); server.getPlayerManager().saveAllPlayerData(); - LOGGER.debug("Saving worlds ..."); + LOGGER.info("Saving worlds ..."); server.save(true, true, true); // Start threaded worker @@ -86,6 +86,7 @@ public final class BackupWorker implements Runnable { String levelPath = getLevelPath(server); String backupFileName = getBackupFileName(backupName); LOGGER.debug(String.format("zip(srcPath=%s, destPath=%s)", levelPath, backupSaveDirectoryFile.toString())); + LOGGER.info("Compressing level ..."); ZipUtil.makeBackupZip(levelPath, backupSaveDirectoryFile.toString(), backupFileName, backupMetadata); File backupZipFile = new File(backupSaveDirectoryFile, backupFileName); @@ -96,11 +97,7 @@ public final class BackupWorker implements Runnable { long timeEscapedMillis = System.currentTimeMillis() - startTime; msgInfo(context, String.format("Backup finished. (%.2fs)", timeEscapedMillis / 1000.0), true); try { - double fileSize = backupZipFile.length() * 1.0 / 1024 / 1024; - if (fileSize > 1000) - msgInfo(context, String.format("File size: %.2fGB", fileSize / 1024)); - else - msgInfo(context, String.format("File size: %.2fMB", fileSize)); + msgInfo(context, String.format("File size: %s", humanFileSize(backupZipFile.length()))); } catch (SecurityException ignored) { } diff --git a/src/main/java/com/keuin/kbackupfabric/worker/RestoreWorker.java b/src/main/java/com/keuin/kbackupfabric/worker/RestoreWorker.java index 8d367d7..54e7beb 100644 --- a/src/main/java/com/keuin/kbackupfabric/worker/RestoreWorker.java +++ b/src/main/java/com/keuin/kbackupfabric/worker/RestoreWorker.java @@ -44,7 +44,7 @@ public final class RestoreWorker implements Runnable { public void run() { try { // Wait server thread die - LOGGER.debug("Waiting for the server thread to exit ..."); + LOGGER.info("Waiting for the server thread to exit ..."); while (serverThread.isAlive()) { try { serverThread.join(); @@ -52,15 +52,16 @@ public final class RestoreWorker implements Runnable { } } - LOGGER.debug("Wait for 5 seconds ..."); + LOGGER.info("Wait for 5 seconds ..."); try { Thread.sleep(5000); } catch (InterruptedException ignored) { } // Delete old level - LOGGER.debug("Server stopped. Deleting old level ..."); + LOGGER.info("Server stopped. Deleting old level ..."); File levelDirFile = new File(levelDirectory); + long startTime = System.currentTimeMillis(); int failedCounter = 0; final int MAX_RETRY_TIMES = 20; @@ -84,9 +85,10 @@ public final class RestoreWorker implements Runnable { } // Decompress archive - LOGGER.debug("Decompressing archived level"); + LOGGER.info("Decompressing archived level"); ZipUtil.unzip(backupFilePath, levelDirectory, false); - LOGGER.info("Restore complete! Please restart the server manually."); + long endTime = System.currentTimeMillis(); + LOGGER.info(String.format("Restore complete! (%.2fs) Please restart the server manually.", (endTime - startTime) / 1000.0)); } catch (SecurityException | IOException | ZipUtilException e) { LOGGER.error("An exception occurred while restoring: " + e.getMessage()); } -- cgit v1.2.3