My laptop is configured to go to sleep after two minutes of being idle.
But it also suspends while a backup to an external disk is running :(
The solution is to tell your system that something important is running and that it should not go to sleep/suspend or to shut down.
With systemd you can use the command „systemd-inhibit“. Read the man page… (man systemd-inhibit).
Instead of starting your backup script directly you start it with:
systemd-inhibit \ --what="shutdown:sleep:idle:handle-lid-switch" \ --who="My backup script" \ --why="Finish the backup." \ /path/to/my/backup-script.sh
Please note that this is a single line but I split it for better reading. Copy and paste all 5 lines.
You may also modify your backup script to run the backup command with systemd-inhibit.
I created the following alias in the global shell rc to be able to use systemd-inhibit for my backup or other important stuff without the need to remember the options:
alias nosuspend='systemd-inhibit --what="shutdown:sleep:idle:handle-lid-switch"'
user@host $ nosuspend /path/to/your/script.sh
To get a list of inhibitions on your system use:
…the systemd-inhibit does only work if a command is running as root, while KDE/Plasma is running as a unprivileged user. But thats sufficient for what I want because my backup script does need root privileges. So I don’t need to „fix“ that issue for my case. Maybe later…
See https://www.freedesktop.org/wiki/Software/systemd/inhibit/ if you need more information.