How to prevent sleep while a Time Machine backup is in progress?
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.
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.
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.
For more information refer to the Apple Support article:
- How Power Nap works on your Mac
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.
Try Mac app called "Caffeine" it keeps your mac on for a time period or indefinitely.
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.