From 483d91a54912f2c87d6d686184f66a8d091ef9b7 Mon Sep 17 00:00:00 2001 From: Keuin Date: Sat, 23 Jan 2021 15:44:15 +0800 Subject: Now it will display information after restoring from an incremental backup --- .../method/ConfiguredIncrementalBackupMethod.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/main/java/com/keuin/kbackupfabric/operation/backup/method') 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; } -- cgit v1.2.3