summaryrefslogtreecommitdiff
path: root/src/main/java/com/keuin/kbackupfabric/worker
diff options
context:
space:
mode:
authorKeuin <[email protected]>2020-04-24 11:55:18 +0800
committerkeuin <[email protected]>2020-04-24 11:55:18 +0800
commitb692a73e039fbdb404ef1219785660dc9eb60e60 (patch)
tree598351d6fcf5f4dcad0212e4cca37ffc16966e0d /src/main/java/com/keuin/kbackupfabric/worker
parent87f5cd97ab22b17a948eb9af1b49a0b1e777048d (diff)
Added /kb delete <backup_name> 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.
Diffstat (limited to 'src/main/java/com/keuin/kbackupfabric/worker')
-rw-r--r--src/main/java/com/keuin/kbackupfabric/worker/BackupWorker.java11
-rw-r--r--src/main/java/com/keuin/kbackupfabric/worker/RestoreWorker.java12
2 files changed, 11 insertions, 12 deletions
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());
}