6

How can I make my Macbook automatically shutdown after a Time Machine backup?

I have a 40GB worth backup to do but I keep having to cancel it to go to bed. Would be great if I could leave it on to do it overnight.

Any suggestions of how to do this in ML?

  • Why do you have to cancel it to go to bed? – Gerry Sep 11 '12 at 20:16
  • Because I wouldn't want my Macbook on all night incase of overheating – Jamesking56 Sep 11 '12 at 20:19
  • 3
    Once it idles, it will go to sleep. You are overthinking this one. – Gerry Sep 11 '12 at 20:21
  • Set it to sleep even with power on after X minutes and let it run until done? – Thorbjørn Ravn Andersen Sep 11 '12 at 20:21
  • Doesn't sleeping still use a considerable amount of power resources? – Jamesking56 Sep 11 '12 at 20:29
2

You could setup a crontab to use tmutil through the command line to do a backup and then shutdown. since shutdown requires sudo privs, you have to set your crontab up as sudo.

sudo crontab -e

Enter your password and then that brings you to edit the contab file

shutdown -h now

Shutdown does exactly that but with the -h flag, it halts the system (shutdown). For the shutdown to work, this would have to be setup as an crontab under sudo

tmutil startbackup

Starts the timemachine backup.

Putting it all together:

00 20 ** ** ** tmutil startbackup --block && shutdown -h +5

Would do the backup at 10:00pm every day and then shutdown

| improve this answer | |
  • Looking at the post by @da4 you could replace rsync with tmutil. I was unaware of their command line tool – slowBear Sep 11 '12 at 21:56
7

I wanted to be able to leave an existing backup to complete, so my approach is a little different.

The backupd process seems only to be running whilst a backup is underway (and for a minute or two afterwards, from what I've observed) so I logged in as root (so that I can (a) see all users' process and (b) trigger a shutdown) and then polled for the process to finish before shutting down. So:

sudo -s

and enter your password to become root, then:

while ( ps -ef | grep 'backupd$' ); do echo "Still backing up..."; sleep 60; done; shutdown -h +1

to wait for backupd to finish and then shut down. (I used shutdown -h +1 instead of shutdown -h now just to be over-cautious and give it an extra minute to tidy up or whatever before shutting down.)

| improve this answer | |
2

Assuming you have already set a destination for your TM, you could open a shell in Terminal (or ssh in), sudo su into super-user mode, then run tmutil startbackup --block;shutdown -h now;exit which tells TM to begin a backup immediately, turn off the Mac, and exit the shell. man tmutil for more info.

You could also then add this as a launchctl item or even cron it to schedule.

| improve this answer | |
  • Be careful with this. I plugged my time machine drive in and ran this command. The time machine backup was already being prepared, so the tmutil errored out (saying a backup was in progress) and then the shutdown command was issued (which froze my laptop for some reason, I had to do a hard reset). Trying again now with no backup being prepared, fingers crossed! – Chris Parton Jan 19 '15 at 11:16

You must log in to answer this question.

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