Migrate a Time Machine backup in terminal

Apple has fixed Finder in macOS 10.13.4 to preserve hard links so my answer is to use Finder to migrate your TM backup. They did not, however, fix cp. It still does not preserve hard links and doesn't have an option to do so.

I know the OP requested a way of doing it from the terminal but all my efforts to do so in macOS 10.13.3, where I had given up on Finder because it did not then preserve hard links, failed.

The rsync command suggested by @n1000 failed after more than 12 hours with out of memory, even though I have 16GB of memory. This is a known problem fixed in rsync v3+. However v3 sets all the user and group ids to 99 and was painfully slow. There were long periods with no disk and no significant CPU activity. I've found rsync very slow on other platforms too.

cpio did not preserve ownership.

pax got strange errors.

I came closest to success with tar:

cd /Volumes/My\ Passport
sudo bash
tar -cf - -T ~/TMFileList | (cd ../My\ Canvio;tar -xpvSf -)

where ~/TMFileList was created with

cd /Volumes/My\ Passport
sudo bash
find -d Backups.backupdb -print > ~/TMFileList

[I tried a tar -c | tar -x thing first but that was copying some hard links as separate files for reasons related, I guessed, to the order it was seeing the files. Which led to me making the depth-first list.]

However tar was taking an impractically long time. I killed it after 3 days. Some of this was because it was extracting files multiple times. The majority of this was, like rsync, due to long periods of inactivity for reasons I could not determine. What it managed to complete had correct ownership and hard links were preserved.

So I strongly recommend using Finder. Just make sure you have macOS 10.13.4. Follow the Apple support instructions in the link at the end of @n1000's answer.


As suggested to the answers and comments in this question, the -p option will not work on a Mac. I tested -rp and it will convert symbolic links to real files. That means when you use this your Time Machine backup will become significantly larger. Time Machine creates symbolic links for redundant files and therefore avoids copying duplicate files between the snapshots.

Hence, use

cp -a

to preserve the symbolic links. This will be necessary if you plan on continuing to use the data for Time Machine backups. Alternatively, you could also use rsync using the -K option to preserve symlinks, e.g.:

rsync -ahvrK

This Apple support document describes the procedure for migrating a backup from one drive to another (using Finder).