On Fri, Oct 1, 2021 at 4:36 PM antlists <
[email protected]> wrote:
I now want to run lvm snapshot on the first boot of the weekend. Writing
a unit to do the snapshot seems pretty easy, but obviously I don't want
it firing every boot, if I stick the date in the volume name I don't
want it colliding with an earlier run the same day, etc etc.
I'm not sure a timer is a great way to do this. Offhand I'm not sure
how the persistence on those works exactly - maybe you could get it to
fire off when you want it to. However, there is another issue you're
missing.
I assume you want to wait for the snapshot to complete before you
mount local filesystems. Normally you'd just do this with a
dependency - the local filesystems get an After dependency on your
snapshot, so they don't get mounted until the snapshot is complete.
The problem is that the service that does the snapshot won't be
enabled - so the dependency will not constrain mounting the
filesystems. An After dependency on its own doesn't cause the thing
it depends on to run - it just says that IF it is going to run it has
to run first. The service that does the snapshot is going to be
started by the timer, not a target, and so at the moment the
dependencies are analyzed it won't be taken into account. That
creates a race condition, since timers do not launch their services in
any sort of synchronization with the system startup.
Now, you could set a dependency on the snapshot such that it doesn't
let filesystems be mounted while it runs, but then when it gets run it
will force all your filesystems to unmount (which is basically going
to do a clean near-shutdown of your entire system to whatever degree
it has started up), then do the snapshot, then remount everything and
restart it all. That isn't what you want either.
I think the cleanest approach is just make the snapshot a regular
service and enable it and set up the dependencies so that it has to
complete before local filesystems are mounted. Then all you need to
do is put logic in that service that turns it into a no-op if there is
a recent enough snapshot already.
Timers are really useful for stuff that is asynchronous, whether
time-based or not. They're not really good for anything synchronous
with the boot process, unless there is some magic to this that I'm
unaware of.
--
Rich
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)