diff options
author | Keuin <[email protected]> | 2020-04-23 14:51:29 +0800 |
---|---|---|
committer | keuin <[email protected]> | 2020-04-23 14:51:29 +0800 |
commit | 720e8ec8eeb69d24afbb6b14068563cde2d470f0 (patch) | |
tree | 83b6dee213737b138ede00d83aa1e9d5eab51fa3 /src/main/java/com/keuin/kbackupfabric/util/PostProgressRestoreThread.java | |
parent | 4605445eb90e15a0629cf937452054cab7dd2b85 (diff) |
Version 1.1.0-dev:1.1.0-dev
- Optimized backup lag (using async I/O).
- Added twice confirmation /kb confirm and cancellation /kb cancel, to avoid mistake.
- Added countdown before restoring.
- Adjusted some text.
- Code optimization.
Diffstat (limited to 'src/main/java/com/keuin/kbackupfabric/util/PostProgressRestoreThread.java')
-rw-r--r-- | src/main/java/com/keuin/kbackupfabric/util/PostProgressRestoreThread.java | 71 |
1 files changed, 0 insertions, 71 deletions
diff --git a/src/main/java/com/keuin/kbackupfabric/util/PostProgressRestoreThread.java b/src/main/java/com/keuin/kbackupfabric/util/PostProgressRestoreThread.java deleted file mode 100644 index 8427a2c..0000000 --- a/src/main/java/com/keuin/kbackupfabric/util/PostProgressRestoreThread.java +++ /dev/null @@ -1,71 +0,0 @@ -package com.keuin.kbackupfabric.util; - -import java.io.File; -import java.io.IOException; - -import static com.keuin.kbackupfabric.util.IO.*; -import static org.apache.commons.io.FileUtils.forceDelete; - -/** - * This thread wait the server to be stopped (must invoke stop out of this thread), - * then delete current level, and restore our backup. - */ -public class PostProgressRestoreThread implements Runnable { - private final Thread serverThread; - private final String backupFilePath; - private final String levelDirectory; - - public PostProgressRestoreThread(Thread serverThread, String backupFilePath, String levelDirectory) { - this.serverThread = serverThread; - this.backupFilePath = backupFilePath; - this.levelDirectory = levelDirectory; - } - - @Override - public void run() { - try { - // Wait server thread die - debug("Waiting server thread stopping ..."); - while (serverThread.isAlive()) { - try { - serverThread.join(); - } catch (InterruptedException ignored) { - } - } - - debug("Waiting ..."); - try { - Thread.sleep(5000); - } catch (InterruptedException ignored) { - } - // Delete old level - debug("Server stopped. Deleting old level ..."); - File levelDirFile = new File(levelDirectory); - - 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()) - ++failedCounter; - else - break; - } - if (levelDirFile.exists()) { - error(String.format("Cannot restore: failed to delete old level %s .", levelDirFile.getName())); - return; - } - - // Decompress archive - debug("Decompressing archived level"); - ZipUtil.unzip(backupFilePath, levelDirectory, false); - info("Restore complete! Please restart the server manually."); - } catch (SecurityException | IOException | ZipUtilException e) { - error("An exception occurred while restoring: " + e.getMessage()); - } - } -} |