$backup->getCreatedAt() is not robust
I'm wondering if it is possible to improve $backup->getCreatedAt() in some way. Currently the result completely relies on the time reported by the OS. This may not work, for example, after I replaced the server and restored the backups from another place. The first call of zenstruck:backup then will keep only a single archive out of all that have been copied. This is because their creation date will actually be the same.
Maybe using the filename itself will help here, but I can't come up with some general solution in my head.
For the $backup->getCreatedAt(), what about a FilenameTimestampDestination wrapper that builds the Backup's using the filename for the createdAt? A constructor option could be a regex to be used to extract the timestamp from the filename? -- @kbond
Yeah, I guess that's the direction in which the solution is. Maybe it is even possible to use the backup namer as a source for a regexp. Prefix and timestamp format are there already. -- @kachkaev
Do you see an issue with: https://github.com/kbond/php-backup/blob/rotating-backups/src/Destination/RotatedDestination.php#L29 ? I don't think that it would be as the new backup would presumably be using the correct time...
What if that destination gets the namer as an additional parameter in the constructor? Backup::fromFile($filename) becomes Backup::fromFile($filename, $namer) too.
Then if the namer is of type timestamp and it is possible to extract createdAt from the $filename, actual file creation time does not matter. Otherwise, OS timestamp is used as a fallback.
Yeah, I like the Namer idea. I would prefer injecting the TimestampNamer directly though. The class wouldn't be usable without it.
EDIT: It would be usable but useless.