billw2 / rpi-clone

A shell script to clone a booted disk.
BSD 3-Clause "New" or "Revised" License
2.52k stars 331 forks source link

Hard linked files synced as individual files #48

Open 6b6561 opened 6 years ago

6b6561 commented 6 years ago

"-H" should be added to $rsync_options to have any hard linked files synced as hard links and not as indivividual files.

    -H, --hard-links            preserve hard links

As an example, the bzcat files in the source are all hard linked files with the same inode, while the destination has these as three separate files.

Source root@hall2:/mnt/clone/bin# cd /bin root@hall2:/bin# ls -li bunzip2 bzcat bzip2 998 -rwxr-xr-x 3 root root 30404 Jan 29 2017 bunzip2 998 -rwxr-xr-x 3 root root 30404 Jan 29 2017 bzcat 998 -rwxr-xr-x 3 root root 30404 Jan 29 2017 bzip2 root@hall2:/bin#

Clone root@hall2:/tmp# cd /mnt/clone/bin/ root@hall2:/mnt/clone/bin# ls -li bunzip2 bzcat bzip2 475 -rwxr-xr-x 1 root root 30404 Jan 29 2017 bunzip2 493 -rwxr-xr-x 1 root root 30404 Jan 29 2017 bzcat 508 -rwxr-xr-x 1 root root 30404 Jan 29 2017 bzip2 root@hall2:/mnt/clone/bin#

The good news is that adding -H to the rsync flags will correct the clone on the next run.

Clone after re-running rpi-clone with -H added to rsync flags root@hall2:/mnt/clone/bin# ls -li bunzip2 bzcat bzip2 475 -rwxr-xr-x 3 root root 30404 Jan 29 2017 bunzip2 475 -rwxr-xr-x 3 root root 30404 Jan 29 2017 bzcat 475 -rwxr-xr-x 3 root root 30404 Jan 29 2017 bzip2 root@hall2:/mnt/clone/bin#