1 |
On Fri, Oct 1, 2021 at 4:36 PM antlists <antlists@××××××××××××.uk> wrote: |
2 |
> |
3 |
> I now want to run lvm snapshot on the first boot of the weekend. Writing |
4 |
> a unit to do the snapshot seems pretty easy, but obviously I don't want |
5 |
> it firing every boot, if I stick the date in the volume name I don't |
6 |
> want it colliding with an earlier run the same day, etc etc. |
7 |
|
8 |
I'm not sure a timer is a great way to do this. Offhand I'm not sure |
9 |
how the persistence on those works exactly - maybe you could get it to |
10 |
fire off when you want it to. However, there is another issue you're |
11 |
missing. |
12 |
|
13 |
I assume you want to wait for the snapshot to complete before you |
14 |
mount local filesystems. Normally you'd just do this with a |
15 |
dependency - the local filesystems get an After dependency on your |
16 |
snapshot, so they don't get mounted until the snapshot is complete. |
17 |
The problem is that the service that does the snapshot won't be |
18 |
enabled - so the dependency will not constrain mounting the |
19 |
filesystems. An After dependency on its own doesn't cause the thing |
20 |
it depends on to run - it just says that IF it is going to run it has |
21 |
to run first. The service that does the snapshot is going to be |
22 |
started by the timer, not a target, and so at the moment the |
23 |
dependencies are analyzed it won't be taken into account. That |
24 |
creates a race condition, since timers do not launch their services in |
25 |
any sort of synchronization with the system startup. |
26 |
|
27 |
Now, you could set a dependency on the snapshot such that it doesn't |
28 |
let filesystems be mounted while it runs, but then when it gets run it |
29 |
will force all your filesystems to unmount (which is basically going |
30 |
to do a clean near-shutdown of your entire system to whatever degree |
31 |
it has started up), then do the snapshot, then remount everything and |
32 |
restart it all. That isn't what you want either. |
33 |
|
34 |
I think the cleanest approach is just make the snapshot a regular |
35 |
service and enable it and set up the dependencies so that it has to |
36 |
complete before local filesystems are mounted. Then all you need to |
37 |
do is put logic in that service that turns it into a no-op if there is |
38 |
a recent enough snapshot already. |
39 |
|
40 |
Timers are really useful for stuff that is asynchronous, whether |
41 |
time-based or not. They're not really good for anything synchronous |
42 |
with the boot process, unless there is some magic to this that I'm |
43 |
unaware of. |
44 |
|
45 |
-- |
46 |
Rich |