Ubuntu – Can I prevent the time consuming backup command from being interrupted by system suspension due to inactivity for a period


I am using XFCE power manager. Under System tab, for System Power Saving part, I choose System Sleep Mode to be: suspend when inactive for 1hr when Plugged in. The maximum inactive time length is 6 hours.

If I am running a command to back up my home to an external drive, such as

sudo rsync -a /home/tim  /media/tim/externaldrive/  2>rsync-errors

which can take more than 10 hours, and I leave my laptop alone and go to sleep, will my Ubuntu be suspended one hour after I leave my laptop, and therefore interrupt the backup command?

If yes, how can I prevent my backup command from being interrupted, without changing System Sleep Mode?


Best Answer

  • 1) systemd's inhibit

    Using systemd's inhibit for a single process can be accomplished by running

    sudo systemd-inhibit --what=idle:sleep:shutdown:handle-power-key:handle-suspend-key:handle-hibernate-key:handle-lid-switch --mode=block rsync -a /home/tim  /media/tim/externaldrive/  2>rsync-errors

    systemd-inhibit requires elevated privileges. The invoked command was run as root on my system. For additional options see either Systemd-inhibit or run man systemd-inhibit

    2) logind D-Bus API

    The logind D-Bus API and Inhibitor Locks can be used in developing an app that properly issues and releases inhibitor locks.

    3) Presentation mode

    xfce4-power-manager gui includes an option called Presentation mode. It will; turn off DPMS (Display Power Management Signaling) so your screen won't blank or sleep, and prevents screensaver mode from activating.

  • Related Question