Backup history fix
This commit is contained in:
parent
0c8290f16e
commit
5cdcc9a490
2 changed files with 32 additions and 0 deletions
|
|
@ -36,6 +36,17 @@ object BackupHistory {
|
|||
return entries.sortedByDescending { it.timestamp }
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the file count for a backup entry without computing its full size.
|
||||
*/
|
||||
fun fileCount(entry: BackupEntry): Int {
|
||||
return if (entry.isCompressed) {
|
||||
java.util.zip.ZipFile(entry.path).use { it.size() }
|
||||
} else {
|
||||
entry.path.walkTopDown().count { it.isFile }
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes old backups that exceed the given max count.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -64,6 +64,27 @@ object BackupScheduler {
|
|||
return@collect
|
||||
}
|
||||
|
||||
// On first config emission, restore last backup info from disk
|
||||
if (_state.value.lastBackupTime == null && config.backupPath != null) {
|
||||
val backups = BackupHistory.listBackups(File(config.backupPath))
|
||||
if (backups.isNotEmpty()) {
|
||||
val latest = backups.first()
|
||||
val fileCount = BackupHistory.fileCount(latest)
|
||||
_state.update {
|
||||
it.copy(
|
||||
lastBackupTime = latest.timestamp,
|
||||
lastBackupResult = BackupResult.Success(
|
||||
backupPath = latest.path,
|
||||
fileCount = fileCount,
|
||||
sizeBytes = latest.sizeBytes,
|
||||
durationMs = 0,
|
||||
),
|
||||
)
|
||||
}
|
||||
logger.info { "Restored last backup info from disk: ${latest.path.name} ($fileCount files)" }
|
||||
}
|
||||
}
|
||||
|
||||
val tz = TimeZone.currentSystemDefault()
|
||||
val targetTime = config.backupTimeOfDay
|
||||
logger.info { "Scheduling daily backup at $targetTime ($tz)" }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue