Time Machine backup keeps restarting over and over again I have been trying to backup about 30GB of data for an entire week now. The hard drive hasn't been disconnected for a week.

What happens is it will "prepare" the backup for a few hours and then copy maybe 500MB and then randomly restart back at "preparing" again. There is an inProgress file inside backups.backupdb where I can see that it has restarted 35 times.

I have turned off throttling through this Terminal command

sudo sysctl debug.lowpri_throttle_enabled=0


which made it go slightly faster, but it still keeps restarting.

Could this be a sign of coming hard drive failure, or is it a time machine bug? 

Here is a few log messages when the backup cancels:

2018-01-24 17:23:52.269569+0100  localhost backupd[2082]: (TimeMachine) [com.apple.TimeMachine:TMLogError] Failed to unmount disk mounted at '/Volumes/com.apple.TimeMachine.localsnapshots/Backups.backupdb/Macbook Pro 15/2018-01-24-164749/MacHD', error: {
    Action = Unmount;
    Target = "file:///Volumes/com.apple.TimeMachine.localsnapshots/Backups.backupdb/Macbook%20Pro%2015/2018-01-24-164749/MacHD";
}
2018-01-24 17:23:52.269970+0100  localhost backupd[2082]: (TimeMachine) [com.apple.TimeMachine:TMLogError] Failed to unmount snapshot: com.apple.TimeMachine.2018-01-24-164749 source: MacHD
2018-01-24 17:23:53.322938+0100  localhost backupd[2082]: (TimeMachine) [com.apple.TimeMachine:TMLogInfo] Backup canceled.
This problem appears to have been caused by either lack of free space, Spotlight, or both.

First I had to free up space so that I had at least 30GB free. Then boot in to recovery mode (+R on start), open the Terminal and disable SIP (System Integrity Protection) through this command:

csrutil disable


Then I disabled Spotlight through this command:

sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.metadata.mds.plist


After doing this I was able to finish my backup.