btrbk
btrbk copied to clipboard
retain LAST snapshot of the hour/day/week/month, not FIRST
Hello, having a cron job regularly backing up systems at 6 AM, when I edit files and configs on the said systems, I like to take a manual backup immediatly after. Problem is, after the retain policy time is passed, btrbk will preserve the FIRST backup of the day, the one at 6AM, not the LATEST (the one I did), that is actually the most updated one. Is it possible to add the option to change this behaviour so to keep the last snap of the period (hour/day/week...)?
If you set target_perserve_min latest, it will always backup the latest snapshot. But of course that does not keep the last weekly/monthly/...
I'm not sure if I understand your use case correctly. Why would you want to preserve the latest of the day? The one taken at 06:00 the next day would be more or less identical?
Let's imagine it's 10:00 and I am editing a configuration on my server, then after I am sure it works, I want to immediately take a backup of this latest, most updated configuration. After a period that depends on my preserve settings, today's hourly snapshots will be removed, and only the one at 06:00 will be maintained, which is not the most updated of the day. Wouldn't be better to preserve only latest snapshot made in the day, as to be the most recent and updated one? Or at least giving the configuration option to choose to preserve either the first or the latest daily?
Wouldn't be better to preserve only latest snapshot made in the day, as to be the most recent and updated one?
IMO there is no general answer, that depends on the scenario. What if someone is interested in restoring data from accidental deletion? Then the first snapshot of the hour/day/... might be more appropriate.
A config option might still make sense, I'm not sure, but at the expense of additional complexity, like always.
In your specific case @MatteoGalet target_perserve_min latest should do it.
If random users have a voting right, I vote against this feature, for the sake of simplicity :)
I have the same request : due to sorting order used for @sorted_schedule (ascending), it keeps by default the FIRST snapshot from an interval rather than the LAST (applies also on daily / weekly / monthly / yearly snapshots).
Actual example on v0.31.3 : Date of btrbk invocation = tue 27 dec 2022 snapshot_preserve parameter : 10d 6w 18m *y (preserve day of week = default = sunday)
Snapshots availables before rotation : 20221025 = (tue) 63d / 9 wk ago / 2m ago 20221026 = (wed) 20221027 = thu 20221028 = fri 20221029 = sat 20221030 = sun 20221031 = mo 20221101 = tue 20221102 = wed 20221103 = thu 20221104 = fri 53d / 8 wk ago / 1.5m ago
During rotation, btrbk deletes 20221026 to 20221104 and keeps 20221025 (= FIRST snapshot).
It seems to me that sorting the schedule by descending order (instead of ascending) would fix the point.
This is especially usefull on systems not used every day / regularly where btrbk invocation can take place only from time to time.