Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am looking for an automated backup system and I like bacula. I have 3 Notebooks and a Desktop computer that need regular backup. Now I don't want to let them run all night just to do the backuping, so I was thinking I could use wake-on-lan to have bacula wake up the machines, then do the backups, and shut them down afterswards. While this may work with devices on the ethernet, it won't work with the Notebooks on the wifi. So is it possible to have the Notebooks schedules to automatically wake up from suspend or shutdown ?

Or is it possible to interject a shutdown command if it is after a certain hour and call the bacula director to start the backup now?

I'm new to controlling the linux system using scripts, so any hints on how and where to start are greatly appreciated.

Thanks alot for your help, input and ideas.

share|improve this question

migrated from Mar 24 '10 at 13:53

This question came from our site for professional and enthusiast programmers.

My answer didn't get moved over from SO. Hunh.

The command you might want to search for is apmsleep, although it might be Debian-specific.

share|improve this answer
apmsleep is also present in recent versions of RHEL. – Kevin M Mar 24 '10 at 14:41
thanks for the hint, looking for apmsleep I found rtcwake: rtcwake -m mem -t date --date="tomorrow 01:30" +%s will put the notebook to sleep and bring it back at 1:30 in the following morning the only problem is, that it needs to be run as su, is there a tricky to avoid that? Now I could send a magic packet to the fileserver to wake it up and perform the backup, but how can I remotely shut down the fileserver afterwards? Thanks alot! – gletscher Mar 26 '10 at 16:59
up vote 2 down vote accepted

So this is my backup solution, it consists of two scripts:

1.) I replaced the standard /usr/lib/hal/scripts/hal-system-power-suspend script with the following code to ensure that every time the computer goes to sleep (e.g. close the lid) it will wake up for the backup:


#Determine when to wake up computer

if [ `date --date=$waketime +%s` -gt `date +%s` ]
  echo today
  waketimesec=`date --date=$waketime +%s`
  echo tomorrow
  waketimesec=`date --date="tomorrow $waketime" +%s`

#Determine switch sleep modus to choose
state=`cat /proc/acpi/ac_adapter/AC0/state | grep on-line`
if [ "$state" = '' ]
  echo Computer on battery mode
  sudo /usr/sbin/pm-suspend           
  echo Computer on AC mode
  sudo rtcwake -m mem -t $waketimesec

  state=`cat /proc/acpi/ac_adapter/AC0/state | grep on-line`
  if [ "$state" = '' ]
  sudo /usr/sbin/pm-suspend

Notice that no backups are made if the AC-Adapter is unplug and the computer is running on battery.

2.) The second script does the actual backup and is triggered by cron a few minutes after the wake-up. It wakes up the remote destination computer, mounts a smbfs share, performs a differential backup using backintime and shuts down the remote computer, then puts the local pc back to sleep:

echo Wake up destination computer and sleep...
wakeonlan <mac_address>
echo ..sleep for 90s #the time your computer needs to boot and start smb
sleep 90
echo Mounting share..
sudo smbmount //<ip_address>/backup_folder /home/<user>/local_folder/ -o username=<user>,password=<pass>,file_mode=0777,dir_mode=0777,uid=1000,user
echo ..share mounted!
echo Starting backup!
backintime --backup > backintime.log
echo Backup finished, giving it time to settle..
sleep 10
echo Unmounting share..
sudo smbumount /home/<user>/local_folder/
sleep 5
echo Shutdown remote computer...
ssh '<user>@<ip_address>' "sudo shutdown -h now"
echo Going back to sleep..

For every sudo command use visudo to grant superuser rights. Use publickey authorization to avoid password-prompts on the ssh command.

Now you have fresh backups every night with minimal power-consumption. Hope this helps someone.

share|improve this answer

So is it possible to have the Notebooks schedules to automatically wake up from suspend or shutdown?

Yes it's possible. I have done this a long time ago - however i can't remember exactly how but it was not hard, from what i remember there was a configuration file you simply edited.

Try looking at the kernel configuration, should be APM/ACPI related. Good luck.

EDIT: Found the command, it's apmsleep. I think that's what your looking for.

share|improve this answer

This problem is well known for the users of linux-based home PVR systems like MythTV (they want their video recording machine wake up when there is something to record on) and MythTV wiki gives a lot of information on this topic:

share|improve this answer

The easiest way to accomplish this, would probably be to set the wakeup-timer in the BIOS. So the computer always boots up at backup-time. And then write a script to make sure no-one is logged in, and the backup is completed for a shutdown.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .