Building boot caches on boot helper partition failed Due to a Hard Drive failure I have had to restore my mac from a backup. Following the Restore From Time Machine Backup procedure under recovery mode takes about 8 hours. Eventually the data is restored on the new hard drive, but the drive won't boot. It gets stuck at around 50% of the boot process with the apple logo.
I have tried the Reinstall macOS procedure under recovery mode, but at the end it prompts the message:

OS X could not be installed on your computer
Building boot caches on boot helper partition failed. Quit the installer to restart your computer

This happens for both Mavericks as for Sierra.
What can I do to fix this problem? After several, very long attempts, I am desperate to get my data and mac back.
I have fixed my problem. Before the crash of my hard drive, I was using Yosemite as OS. Apparently you cannot restore a backup made in Yosemite with a bootable USB of either Mavericks or Sierra or with the network restore of Lion.

I eventually made a bootable USB drive of Yosemite and reinstalled a new copy of Yosemite on my new HDD. After installation I used the Migration Assistant to retrieve my data. This took several hours, but afterwards I could normally reboot my computer. I had tried this same procedure with Lion, Mavericks and Sierra, but that didn't work and the computer wouldn't boot.

So if you find yourself having to restore a time machine backup, use a bootable macOS of the same macOS version you were running.