diff options
Diffstat (limited to 'src/main/java/com/keuin/kbackupfabric')
4 files changed, 23 insertions, 2 deletions
diff --git a/src/main/java/com/keuin/kbackupfabric/KBCommands.java b/src/main/java/com/keuin/kbackupfabric/KBCommands.java index 9f00790..73b61df 100644 --- a/src/main/java/com/keuin/kbackupfabric/KBCommands.java +++ b/src/main/java/com/keuin/kbackupfabric/KBCommands.java @@ -84,6 +84,8 @@ public final class KBCommands { * @return stat code. */ public static int list(CommandContext<ServerCommandSource> context) { + // TODO: Show real name and size and etc info for incremental backup + // TODO: Show concrete info from metadata for `.zip` backup MinecraftServer server = context.getSource().getMinecraftServer(); File[] files = getBackupSaveDirectory(server).listFiles( (dir, name) -> dir.isDirectory() && @@ -356,6 +358,7 @@ public final class KBCommands { * @return stat code. */ public static int prev(CommandContext<ServerCommandSource> context) { + // FIXME: This breaks after adding incremental backup try { // List all backups MinecraftServer server = context.getSource().getMinecraftServer(); diff --git a/src/main/java/com/keuin/kbackupfabric/backup/incremental/manager/IncCopyResult.java b/src/main/java/com/keuin/kbackupfabric/backup/incremental/manager/IncCopyResult.java index 6011ea5..dbaf9bf 100644 --- a/src/main/java/com/keuin/kbackupfabric/backup/incremental/manager/IncCopyResult.java +++ b/src/main/java/com/keuin/kbackupfabric/backup/incremental/manager/IncCopyResult.java @@ -95,7 +95,7 @@ public class IncCopyResult { @Override public String toString() { return String.format( - "Files copied: %d (%s in size, totally %d files). Total file tree size: %s.", + "Files copied: %d (%s in size, totally %d files). Total file tree size: %s", filesCopied, BackupFilesystemUtil.getFriendlyFileSizeString(bytesCopied), totalFiles, diff --git a/src/main/java/com/keuin/kbackupfabric/backup/incremental/manager/IncrementalBackupStorageManager.java b/src/main/java/com/keuin/kbackupfabric/backup/incremental/manager/IncrementalBackupStorageManager.java index 78c6943..9060d88 100644 --- a/src/main/java/com/keuin/kbackupfabric/backup/incremental/manager/IncrementalBackupStorageManager.java +++ b/src/main/java/com/keuin/kbackupfabric/backup/incremental/manager/IncrementalBackupStorageManager.java @@ -58,7 +58,7 @@ public class IncrementalBackupStorageManager { } { // element exists (file reused). Just update the stat info - copyCount = copyCount.addWith(new IncCopyResult(1, 1, 0, fileBytes)); + copyCount = copyCount.addWith(new IncCopyResult(1, 0, 0, fileBytes)); } } diff --git a/src/main/java/com/keuin/kbackupfabric/operation/backup/method/ConfiguredIncrementalBackupMethod.java b/src/main/java/com/keuin/kbackupfabric/operation/backup/method/ConfiguredIncrementalBackupMethod.java index 2320ef3..c4be40d 100644 --- a/src/main/java/com/keuin/kbackupfabric/operation/backup/method/ConfiguredIncrementalBackupMethod.java +++ b/src/main/java/com/keuin/kbackupfabric/operation/backup/method/ConfiguredIncrementalBackupMethod.java @@ -9,13 +9,17 @@ import com.keuin.kbackupfabric.backup.incremental.serializer.IncBackupInfoSerial import com.keuin.kbackupfabric.backup.incremental.serializer.SavedIncrementalBackup; import com.keuin.kbackupfabric.backup.name.BackupFileNameEncoder; import com.keuin.kbackupfabric.backup.name.IncrementalBackupFileNameEncoder; +import com.keuin.kbackupfabric.metadata.BackupMetadata; import com.keuin.kbackupfabric.operation.backup.feedback.IncrementalBackupFeedback; import com.keuin.kbackupfabric.util.FilesystemUtil; import com.keuin.kbackupfabric.util.PrintUtil; import com.keuin.kbackupfabric.util.ThreadingUtil; import java.io.File; +import java.io.FileOutputStream; import java.io.IOException; +import java.io.ObjectOutputStream; +import java.nio.file.Files; import java.nio.file.Paths; import java.time.ZoneId; import java.util.Arrays; @@ -127,6 +131,20 @@ public class ConfiguredIncrementalBackupMethod implements ConfiguredBackupMethod IncrementalBackupStorageManager storageManager = new IncrementalBackupStorageManager(Paths.get(backupBaseDirectory)); int restoreObjectCount = storageManager.restoreObjectCollection(info.getObjectCollection(), levelPathFile); + // write metadata file + File metadataFile = new File(levelPathFile, BackupMetadata.metadataFileName); + try (FileOutputStream fos = new FileOutputStream(metadataFile)) { + try (ObjectOutputStream oos = new ObjectOutputStream(fos)) { + oos.writeObject(new BackupMetadata(info.getBackupTime().toEpochSecond() * 1000, info.getBackupName())); + } + } catch (IOException e) { + PrintUtil.warn("Failed to write restore metadata: " + e + ". KBackup won't print restoration information during the next startup."); + try { + Files.deleteIfExists(metadataFile.toPath()); + } catch (IOException ignored) { + } + } + PrintUtil.info(String.format("%d file(s) restored.", restoreObjectCount)); return true; } |