Redo rsync to preserve hard links?

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
Asked By: BartmanEH

||

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.

Answered By: heemayl
Categories: Answers Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.