Redo rsync to preserve hard links

rsync

I'm copying a Raspbian partition from one SD Card to a stand alone Raspbian install on a new SD Card. Based on a suggestion elsewhere, I ran:

rsync -av --exclude=/mnt / /mnt

but now I'm concerned that I didn't preserve hard links because I didn't include the -H directive and instead rsync made copies of files instead of preserving hard links.

How can I correct this possible error? Can I run some form of rsync to fix this? such as:

rsync -avH --delete-after --exclude=/mnt / /mnt

Best Answer

Your idea is right.

Here is a test:

/foo$ stat -c '%i-%n' *
658846-egg
656129-spam
656129-test


/bar$ rsync -av /foo/ .
sending incremental file list
./
egg
spam
test
sent 229 bytes  received 76 bytes  610.00 bytes/sec
total size is 0  speedup is 0.00


/bar$ stat -c '%i-%n' *
657110-egg
663431-spam
663560-test


/bar$ rsync -Hav --delete-delay /foo/ .
sending incremental file list
test => spam

sent 107 bytes  received 19 bytes  252.00 bytes/sec
total size is 0  speedup is 0.00


/bar$ stat -c '%i-%n' *
657110-egg
663431-spam
663431-test

On a different note, its better to use --delete-after rather than other similar options i.e. --delete-before, --delete-delay, --delete-during because these options decide which files to delete either before or during the transfer.

Related Question