Howto pause pm-suspend when program is running

I have a backintime running every hour. Sometimes, it’s running when I suspend/hibernate the machine. The suspend will fail, because backintime refuses to suspend. BIT will fail because network is pulled down. Then we have backintime running forever, and suspend/hibernate failing forever too(until you kill BIT manually).

This script will wait until backintime is done, and then let the computer suspend/hibernate.

/etc/pm/sleep.d/01_backintime:

#!/bin/bash
case "${1}" in
  hibernate|suspend)
    while pgrep -f "/usr/bin/backintime "; do
      sleep 5
    done
  ;;
esac

exit 0

Remember to make the file executable.