From 61ade9adad4668494dfc32da7751e1b86251dc97 Mon Sep 17 00:00:00 2001 From: Keuin Date: Mon, 30 Nov 2020 13:15:15 +0800 Subject: Implementing incremental backup --- .../kbackupfabric/operation/RestoreOperation.java | 49 ++++------------------ 1 file changed, 8 insertions(+), 41 deletions(-) (limited to 'src/main/java/com/keuin/kbackupfabric/operation/RestoreOperation.java') diff --git a/src/main/java/com/keuin/kbackupfabric/operation/RestoreOperation.java b/src/main/java/com/keuin/kbackupfabric/operation/RestoreOperation.java index ef6ab2b..22397a1 100644 --- a/src/main/java/com/keuin/kbackupfabric/operation/RestoreOperation.java +++ b/src/main/java/com/keuin/kbackupfabric/operation/RestoreOperation.java @@ -84,54 +84,21 @@ public class RestoreOperation extends InvokableBlockingOperation { } } - PrintUtil.info("Wait for 5 seconds ..."); - try { - Thread.sleep(5000); - } catch (InterruptedException ignored) { - } - - // Delete old level - PrintUtil.info("Server stopped. Deleting old level ..."); - File levelDirFile = new File(levelDirectory); - long startTime = System.currentTimeMillis(); - - int failedCounter = 0; - final int MAX_RETRY_TIMES = 20; - while (failedCounter < MAX_RETRY_TIMES) { - System.gc(); - if (!levelDirFile.delete() && levelDirFile.exists()) { - System.gc(); - forceDelete(levelDirFile); // Try to force delete. - } - if (!levelDirFile.exists()) - break; - ++failedCounter; - try { - Thread.sleep(500); + int cnt = 5; + do { + PrintUtil.info(String.format("Wait %d seconds ...", cnt)); + try{ + Thread.sleep(1000); } catch (InterruptedException ignored) { } - } - if (levelDirFile.exists()) { - PrintUtil.error(String.format("Cannot restore: failed to delete old level %s .", levelDirFile.getName())); - return; - } + }while(--cnt > 0); - // Decompress archive - PrintUtil.info("Decompressing archived level ..."); - 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) { + } catch (SecurityException e) { PrintUtil.error("An exception occurred while restoring: " + e.getMessage()); } } -- cgit v1.2.3