MacOS – OSX: How to compare and merge two folders and their subfolders and differing files of the same origin

finderfoldersmacosmerge

I'm among those unlucky few (I'm hoping there are more than one) that are stuck with truly utterly messy backups from multiple machines, in multiple folders.

I've now managed to figure out that I've got one folder with 18gb and 44000+ files and one folder with 17gb and 34000+ files. They are the same folder, but one is on backup2/ and the other is in backup3/. I've used MacPaw's Gemini to remove duplicates from folder1 – and sometimes used Gemini to remove duplicates from folder2. They could be described as being totally out of sync with eachother – they are from separate times and now with mismatching files – i.e., there are duplicates there, but not really enough to use Gemini easily.

I'd like to compare and merge them, but safely. Without losing folders. One might have a subfolder inside a subfolder with 35 files, the other with 12 files – yet the 12 files wouldn't be in the 35 files, so I'd have to be able to merge subfolders so that I don't lose any files. Also, there are, as you would expect, duplicates there too, files with the same name, but with differing file content. I'd have to make copies of those to compare them, remove lines (in case of a textfile) from txt1 and add them to txt2, etc.

What should I do, and which app should I use to visually be able to combine these folders and their subfolders and their contents, merging the files and only keeping the ones that are absolutely differently sized (maybe I've touched a few of the files, maybe not, it's a total shambles).

How should I proceed? I'm running diff on the folders, but that's really quite complicated work.

I realize this is quite the complex question.

Best Answer

The rsync command line tool is able to merge two folders. You'll need to open a terminal window. Take a look at the manual pages

man rsync 

There may be a one liner but the following steps are non-destructive since you won't change your source folders.

  1. Create a new folder (dest)
  2. Sync source1_path to dest
  3. Sync source2_path to dest

Here the script - check the manual pages for additional options

rsync -rv source1_path/ dest
rsync -rv source2_path/ dest

The following commands also create copies for non-identical files which exist in both source directories (with a difference in size or timestamp for example)

rsync -rv --backup --suffix=_source1 source1_path/ dest
rsync -rv --backup --suffix=_source2 source2_path/ dest