How to restore external hard drive from Time Machine backup the right way?

I found an answer over at superuser.com: https://superuser.com/a/1148703 But it seems there were some changes in MacOS so it did not work. But with this as a starting point I found a solution:

  1. Format the new drive (Or in my case the corrupted drive) with Disk Utility. Give it the same name as the old one. In my example "Daten"
  2. Go to the System Preferences - Time Machine and uncheck "Back Up Automatically"
  3. Go to the System Preferences - Security & Privacy. Unlock to make changes. Click on "Full Disk Access" and add Terminal.app from the Applications/Utilities Folder.
  4. Open Terminal.
  5. Put in sudo tmutil associatedisk -a. Then first drag your new Volume to the Terminal and after that drag the folder link Latest to the Terminal. You will find this folder link on your Time Machine Volume -> Backups.backupsdb -> Your Computer Name.
    The result should look like this: sudo tmutil associatedisk -a /Volumes/Daten /Volumes/YourBackupVolume/Backups.backupdb/Your\ Computer\ Name/Latest At the end of the line you need to add /Daten or whatever your failed HD was named.
  6. If the final result looks like this: sudo tmutil associatedisk -a /Volumes/Daten /Volumes/YourBackupVolume/Backups.backupdb/Your\ Computer\ Name/Latest/Daten press Enter, enter your password and press Enter again.
  7. Open the new volume in Finder. Start Time Machine. Restore all the files.
  8. Undo step 3.
  9. Undo step 2.

After that, Time Machine will see your new volume as the old one and will only backup the new files.

The reason why this is necessary is that Time Machine recognises the volumes not by their name but by their UUID, which is a long unique number that changes with every formatting. The associatedisk command tells Time Machine the new UUID of the volume.