Is it possible to configure systemd service that will delay the boot process (by about 10-20 minutes) to run a local backup script (something like dd if=/dev/sdb of=/dev/sdc
) while filesystem is still read-only? Or maybe it's possible to execute such task just before shutdown?
I have tried several configurations, but still cannot achieve this behavior in my Ubuntu 22 box.
This variant causes timeout and boot process failed - system goes into maintenance mode:
[Unit]
Description=Backup on demand
DefaultDependencies=no
After=systemd-fsck-root.service
Before=systemd-remount-fs.service -.mount local-fs-pre.target local-fs.target
[Service]
Type=oneshot
TimeoutSec=0
ExecStart=/root/backup-on-boot.sh
[Install]
WantedBy=local-fs.target
This variant doesn't block boot process and run in background (which is undesired behavior)
[Unit]
Description=Backup on demand
After=local-fs.target
Wants=local-fs.target
[Service]
Type=oneshot
TimeoutSec=0
ExecStart=/root/backup-on-boot.sh
[Install]
WantedBy=multi-user.target
dd
is overkill, especially for flash drives, so I already switched toblocksync
).systemctl isolate
). No idea if this would work, but it's something to think about!