Search code examples
backuprsync

RSYNC and folder hierachcy


After making a full forensic copy of a harddrive using dd, I would like to keep up with changes between the original and backup harddisc, therefore I started using rsync.

Whenever, I run

sync -a -v -n  --progress /media/drive1 /media/drive2

the command would start listing all files contained in drive1. However, only a couple of them has changed after I did DD.

Trying that on a single folder

sync -a -v -n  --progress /media/drive1/folder /media/drive2

works fine and just displays the new files in that folder - those which are not contained in /media/drive2/folder.

However, executing the command on the level of both volumes

sync -a -v -n --progress /media/drive1 /media/drive2

does not account for the differentials, contrary to the documentation which is everywhere available, but takes all files which are already on both drives.
What is my mistake?


Solution

  • The way rsync treats its source and destination paths is easy to get wrong. When you use the command:

    sync -a -v -n  --progress /media/drive1 /media/drive2
    

    ...it tries to sync the drive1 folder into drive2; that is, it creates and populates /media/drive2/drive1. When you add "/folder" to the source path, it works as expected because then it's trying to sync with /media/drive2/folder, which is what you want.

    Fortunately, the solution is easy: add "/" to the end of the source path, which tells it to sync the contents of drive1 into drive2, rather than the folder itself:

    sync -a -v -n  --progress /media/drive1/ /media/drive2
    

    BTW, I'd recommend adding --dry-run to make sure it's doing what you want before running it "for real". You'll probably also have to delete /media/drive2/drive1.