I use a script to do incremental backups of a btrfs partition from one disk to another.
The script is started by cron.weekly at random time of a day.
If I shut down the system while the script is running, I am getting into trouble with old backups removed and new not created.
Is there a way to setup the system to wait till the script is finished?
I am using Ubuntu 16.04 with systemd.
For Ubuntu 16.04+ using systemd (the default).
===
Test:
===
There are 7 locks:
sleep
inhibits system suspend and hibernation requested by (unprivileged) usersshutdown
inhibits high-level system power-off and reboot requested by (unprivileged) usersidle
inhibits that the system goes into idle mode, possibly resulting in automatic system suspend or shutdown depending on configuration.handle-power-key
inhibits the low-level (i.e. logind-internal) handling of the system power hardware key, allowing (possibly unprivileged) external code to handle the event instead.handle-suspend-key
inhibits the low-level handling of the system hardware suspend key.handle-hibernate-key
inhibits the low-level handling of the system hardware hibernate key.handle-lid-switch
inhibits the low-level handling of the systemd hardware lid switch.You probably also want to prevent
suspend
,idle
andhibernate
.Example using "package manager":
Similar to this you can code your version and add a "shutdown" at the end of this script (or add a way to determine a shutdown needs to be the next action).
In BackInTime I'm using couple different DBus methods to work on all major DEs. Only downside is this won't work for
root
becauseroot
has nodbus.SessionBus
.