php-backup icon indicating copy to clipboard operation
php-backup copied to clipboard

$backup->getCreatedAt() is not robust

Open kachkaev opened this issue 10 years ago • 4 comments

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.

kachkaev avatar Dec 06 '15 16:12 kachkaev

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

kbond avatar Dec 06 '15 17:12 kbond

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...

kbond avatar Dec 06 '15 17:12 kbond

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.

kachkaev avatar Dec 06 '15 17:12 kachkaev

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.

kbond avatar Dec 06 '15 17:12 kbond