diff options
author | Keuin <[email protected]> | 2021-01-23 15:44:15 +0800 |
---|---|---|
committer | keuin <[email protected]> | 2021-01-23 15:44:15 +0800 |
commit | 483d91a54912f2c87d6d686184f66a8d091ef9b7 (patch) | |
tree | ea1cda511c69bb5efbf938d69060561d7a3d738b /src/main/java/com/keuin/kbackupfabric/operation/backup/method | |
parent | 4a1d885afa7217b47d6183488c3dc6537cef05b6 (diff) |
Now it will display information after restoring from an incremental backup
Diffstat (limited to 'src/main/java/com/keuin/kbackupfabric/operation/backup/method')
-rw-r--r-- | src/main/java/com/keuin/kbackupfabric/operation/backup/method/ConfiguredIncrementalBackupMethod.java | 18 |
1 files changed, 18 insertions, 0 deletions
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; } |