Categories
backuppc backups Linux magic packet wake on lan WOL

Backuppc and waking machines

In our office there are 9 machines, all of which are backed up nightly with Backuppc. However I did often notice that machines did not get backed up, usually because the machine was not turned on. This was becoming a problem and over half of the machines were not being backed up nightly and some had not been done for many weeks. The nagging e-mails that Backuppc sends out were also being ignored as well.

I needed a way to ensure the machines were on, at least when it was their turn to be backed up. Enter the linux program etherwake. Etherwake sends out a magic packed to a specific machine by it MAC address. Typically machines will not wake when they are pinged, only a specific so-called “magic packet” will wake a machine.

Backuppc does not however have anything currently builtin which invokes etherwake before attempting to wake it. It also has a habit of doing a nmblookup before backup as well, which will most likely fail if the machine has been off for some time.

What I did was replace the ping command in backuppc with a bash shell script and disable the nmblookup. Here’s how I did it.

First write a script in bash and place where you like. It will be someplace where the backuppc user will have rights to access to it. I put the script in the backuppc user’s home.



#!/bin/bash

#this script is totally designed for the backuppc ping command
#which is the first thing it does before it starts a backup
#this is a substitute which pings the machine, if it is not
#awake then it wakes it using a magic packet - using the wol.bsh script
#then pings again to make sure

PING=/bin/ping
ARG1=$1
ARG2=$2
WAKEHOST=$3
ETHWAKE=/usr/sbin/etherwake
SLEEPTIME=3m

logger "Backuppc pinging $1 $2 $3"


function fwol {
TO_WAKEUP=$1
sudo $ETHWAKE $1
if [ $? -eq 0 ]
then
WOL_RES="OK"
else
WOL_RES="FAIL"
fi
}

$PING $ARG1 $ARG2 $WAKEHOST >>/dev/null 2>&1

if [ $? -ne 0 ]; then
fwol $WAKEHOST
if [ "$WOL_RES" = "FAIL" ]; then
exit 1
fi
sleep $SLEEPTIME
$PING $ARG1 $ARG2 $WAKEHOST
if [ $? -eq 0 ]
then
logger "success waking $WAKEHOST."
else
logger "unable to wake $WAKEHOST."
exit 1
fi
else
$PING $ARG1 $ARG2 $WAKEHOST
fi

exit 0

I saved this a wolping.bsh. Essentially this first checks if the machine is up by pinging it. If it does respond then it simply drops out and pings again. Otherwise it invokes etherwake, waits for three minutes and then ping again. Note that in the backuppc code it will invoke the ping command twice, the first time as a wakeup and second the check the roundtrip time. Which is why I first send the ping to /dev/null and then ping again, I don’t want the first output read by backuppc.

Now in backuppc in the server config, you will need to do the following:

  • Set PingPath to the path to where you saved the script above
  • Set NmbLookupFindHostCmd on Backup Settings to blank

Removing the NmbLookup will disable this “feature” and prevent backuppc from reporting the machine down before it wakes up.

That’s it for the backuppc configuration. There is one last item which is needed. Remember etherwake only understands MAC addresses, but backuppc is invoking our script with a host name. So how can you make a host name to a MAC address?

Etherwake will search a /etc/ethers file when it is given a host name. So create one, you’ll need to obtain the MAC addresses of all the machines you want to respond and add them into a ethers file as MAC hostname pairs, similar to a hosts file, eg:



00:3B:56:89:1A:22   myhost

And that’s all there is to it. I now even have the backup server woken up by the router when needed. There is no reason to have any more machines on than necessary.

Next post I’ll get into how you set this up on Linux and Windows to respond to these WOL/magic packet requests.

4 replies on “Backuppc and waking machines”

I just wanted to say thank you. I have been trying (occasionally) to get my BackupPC server to wake-on-lan my clients. Your post "Backuppc and waking machines" is simple and to the point. It worked like a charm. Again, thanks.

Hi Salik,

I am trying to apply your script on my gentoo server to wake up windows clients on LAN.
But have encoutered some problems, could you please advise me on the following:
I can launch etherwake successfully directly from terminal by the following command:

ether-wake -i enp3s0 ‘client MAC’

With this regard could you please assist me with modifing your script as I am not good enough in bash scripting.

Many thanks

Hello Russ. Thanks for asking that question.

I believe on Gentoo the command is ether-wake and has identical parameters to the Ubuntu version that I use. see Gentoo Etherwake

So substitute in the path to ‘ether-wake’ for the path on ETHWAKE above and you should be fine. The Gentoo version will also read the /etc/ethers file so you should not need to change anything else.

The ‘i’ option is for the interface you wish it to use. set that on the $ETHWAKE and all should be well.

I hope that helps you out and do let me know how you get on.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.