How to restore a time machine backup of a USB drive to a new USB drive?

Solution 1:

I found a solution that does use the existing backup. The trick is to use sudo tmutil associatedisk (see man tmutil).

My old disk was mounted under /Volumes/USB-old and the new disk is mounted as /Volumes/USB-new. My backup is under /Volumes/backups. (If your old and new disk have both the same name, you have to follow all of the steps, because the name of the disk is not sufficient to associate an old backup with a new disk)

  1. Stop time machine to do backups (in the preferences)
  2. Restore the old data to the new disk:

    sudo tmutil restore /Volumes/backups/Backups.backupdb/MacBookPro/Latest/USB-old/* /Volumes/USB-new
    

    (note this does not restore files starting with . at the top level)

  3. Tell time machine to associate the new disk to the old backups:

    sudo tmutil associatedisk /Volumes/USB-new /Volumes/backups/Backups.backupdb/MacBookPro/Latest/USB-old
    
  4. Start time machine to do backups

Now time machine does not try to backup the entire new disk. Instead, it creates incremental backups based on the old snapshot.

However, it seems not possible to go back in history using Time Machine. I have tried to associate all old backups with the new disk without much success:

for dir in `find /Volumes/backups/Backups.backupdb/MacBookPro -maxdepth 2 -name USB-old`; do 
    echo sudo tmutil associatedisk /Volumes/USB-new $dir
done