13

I'm one of those greatly suffering from the problem with TM in which the entire backup sparsebundle on a NAS gets corrupted if the Mac goes to sleep in middle of a backup operation. There's a long process for recovering the backup, but it would be far better to avoid the corruption in the first place.

Is there any way to hack the sleep function so that the Mac refuses to go to sleep if a TM backup is currently in progress? Or, if that's not possible, is there at least some way to show a confirmation dialog when manually choosing "sleep" from the apple menu, to prompt for a manual verification that no TM is currently running?

Clarification: One of the situations I need to protect against, is my habit of manually choosing "sleep" from the apple menu. Hence, something like Caffeine which only prevents automatic sleep, isn't a solution for me.

  • 1
    As a last resort you could try using the Caffeine app (itunes.apple.com/us/app/caffeine/id411246225?mt=12). When you start Caffeine an icon will be placed in the menu bar that will allow you to prevent your Mac from going to sleep when enabled. A better solution would be if you could find a way to automatically disable sleep before TM starts and reenable sleep after TM quits. Someone who knows AppleScript could probably put something together pretty easily. – recklesscoder Apr 13 '13 at 15:20
  • @recklesscoder please see clarification. – GJ. Apr 13 '13 at 18:31
  • Interesting. On my Macbook Pro TM actively prevents sleeping. I can see that with pmset if I check assertions. – Dmitry Dulepov Nov 8 '16 at 12:45
6

I have solved this with a bash script. It involves caffeinate built-in command and NoSleepCtrl (prevents sleep on lid close).

In my setup, I have TimeMachine disabled and run it using this command. It should not be difficult to create a wrapper, which would execute it periodically and either ask user for confirmation or wake the computer up and do it automatically.

My experience and steps for TM backup corruption on QNAP.

  • please see clarification. – GJ. Apr 13 '13 at 18:32
  • Give try to the NoSleep utility. It does prevent sleep, even if you invoke Sleep from menu. I have checked it using simple: while true; do date; sleep 1; done. On caffeinate only it stops; with NoSleep screen goes blank, but loop does not stop. – brablc Apr 13 '13 at 18:50
2

This will keep Mac awake for two days:

turn it into a script and make sure to chmod +x stayup.sh or whatever the name of the script is.

#! /bin/sh
let TIME=$(expr 24*60*60*2); # 2 days in seconds
echo caffine for $TIME;
caffeinate -s -m -i -t $TIME;

or just caffeinate -t 3600 &
& - allows to run in the background, freeing up terminal.

1

Try Mac app called "Caffeine" it keeps your mac on for a time period or indefinitely.

1

I had the same problem, so I turned off my sleep function, password, and also checked 'prevent computer going to sleep when the display is off'. I am hoping this works. I just discovered that a back up hadn't run in 76 days. Thanks for the other help.

0

Yeah, I was thinking of recommending the Caffeine app, especially if you are in the habit of kicking off Time Machine backups manually.

Another option might be to go into System Preferences > Energy Saver and setting your computer sleep timer to closer to 3 hours. Be advised, though, that this will increase the amount of energy your computer is consuming (since it will be awake longer for each session). You can keep your display timer down to a more reasonable duration to save power. Display sleep won't affect Time Machine.

0

I just ran into this new addition -- the caffeinate command is built into OS X now, no app needed.

http://osxdaily.com/2014/06/16/caffeinate-prevent-sleep-while-command-active-mac-os-x/

0

I suffered with Time Machine being interrupted by what I thought was the Mac going to sleep. I set the energy saver to "Never got to sleep" but would come back to the Mac and it was back to "log in" and the Time Machine action had been stopped. Eventually I realized in the Security settings that "Log Out (after so many minutes) was checked. After unchecking this option I was able to stay logged in.

0

This might be a bit simplistic but I went into System Preferences, opened Energy Saver and moved the slider to "never sleep". I will revert to the original when my backup has finished.

0

One solution to perform backups that may take longer than the default sleep time, that does not require preventing your Mac from sleeping, is using Power Nap which allows your backup to be performed during sleep while connected to an AC Power Outlet (assuming you are using Time Machine to backup).

Note that backups can only be performed in this method if your Mac is connected to power. However, this solution will work even during the OP's problem of manually forcing their Mac to sleep.

Power Nap can be easily enabled by going to System Preferences → Energy Saver and clicking the check box next to Enable Power Nap.

Screenshot of the Power Nap on macOS Mojave

For more information refer to the Apple Support article:

You must log in to answer this question.

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