Diff & Copy to a third location ?

tiberiusQ

Contributor
Joined
Jul 10, 2017
Messages
190
Dear all,

I have two datasets with slightly different data in it, so I need to diff the difference between them but I only want to copy the diff which is in folderA to a third location for human inspection ;-)

Eg. I have two folders with a lot of subfolders files in it: folderA and FolderB
diff -qr folderA folderB
superimportantfile.pdf. Only in FolderA
etc.

After a while I found and tested a nice way to do this, but this does only works on debian based linux because the cp option -t is not implemented on bsd....
diff -rq folderA folderB | sed -n "s/^Only in \(folderA\): \(.*\)/'\1\/\2'/p" | xargs cp -rtv folderC

Of course I could fire up debian mount folderA folderB and folderC via cifs to run this but due to the amount of data I prefer to run this directly on the truenas box.

Does Anybody has an idea to achieve this on Truenas ?
 
Last edited:

jgreco

Resident Grinch
Joined
May 29, 2011
Messages
18,680
Right, "-t" isn't POSIX, it's just random crap Linux added. I wish they wouldn't do that, because it significantly muddies the waters.

Is there some reason

# [blabla] | xargs -J % cp -rv % folderC

won't work for you? I concede that use of "-J" is not POSIX either, correct POSIX usage is left as an exercise to the reader. I'm just looking for the quick answer here.
 

tiberiusQ

Contributor
Joined
Jul 10, 2017
Messages
190
Except the posix thing I realized a new behavior which I really do not understand:

user@machine ~ % diff -rq a b
Only in a/folder: important.txt
user@machine ~ % diff -rq a b | sed -n "s/^Only in \(a\): \(.*\)/'\1\/\2'/p" | xargs -J % cp -rv % c
user@machine ~ % ls c
user@machine ~ %

As you can see diff shows the correct missing file in folder a but will not be copied to folder c if the folder exists in folder b.....:confused:

It looks like rsync could solve my issue:

rsync -rvcm --compare-dest=b/ a/ c/
 
Last edited:

tiberiusQ

Contributor
Joined
Jul 10, 2017
Messages
190
Update & Background: About a year ago I copied with rsync -a locally between two smb datasets and got a lot of acl errors indeed and due to the amount of data and time it takes I decided to keep the orig. data and enable the new data set for production. Followed up I just defined acls on the new data-set and no user ever complained about anything, but I am not sure if there is a data diff between those datasets, that's why I try to put the diff to a third location and then back to the production dataset in a dolder called eg. diff. so that the users are able to double check + I am able to delete the orig. data including snapshots.

That's the reason for my odyssey on this thread or task and currently I do get two super different file size outputs between ok, makes sense.
rsync -rvtmc --compare-dest=b/ a/ c/
and
rsync -rvtm --compare-dest=b/ a/ c/

Does rsync -rvtmc --compare-dest=b/ a/ c/ the same what I expected from my diff command above ?

Does anybody has an equal task and can share skills and or can confirm that if you copy with rsync -a between smb datasets no data get lost except acls ? OR is there a zfs command to diff and copy to a third location ?
 
Last edited:
Top