0

I want to synchronize two computers that are similar and update just a few files. Therefore I would like to perform a Unison and ignore everything except a list of files in different paths.

Something like:

# /usr/bin/unison-gtk /home/ ssh://root@192.168.0.199:22//home/ -ignore "Name *" -ignorenot "Name {config/text.cfg, Pictures/test.jpg, Desktop/test.mp3"

Or even better starting with root directory:

# /usr/bin/unison-gtk / ssh://root@192.168.0.199:22// -ignore "Name *" -ignorenot "Name {/home/config/text.cfg, /home/Pictures/test.jpg, /usr/local/bin/test.sh"

The first ignore is exclude everything else so the ignorenot won't catch them. Any Help? Can anyone help? Nothing I have found is helping me.

1 Answers1

1

Have you tried the -path option for unison instead of -ignore? From the unison manual and reference guide section Using Unison for All Your Files

tell Unison to synchronize only some of the files and subdirectories within it on any given run. This can be accomplished by using the -path switch on the command line: ... The -path option can be used as many times as needed, to synchronize several files or subdirectories:

Here is a quick practical example.

  • create local and remote directories (the remote directory is a stand-in for an actually remote directory in this case).
root@ubuntu:~# mkdir local remote
  • create 9 files in the local directory.
root@ubuntu:~# for i in $(seq 9); do uuidgen > local/${i}.txt ; done
root@ubuntu:~# ls local
1.txt  2.txt  3.txt  4.txt  5.txt  6.txt  7.txt  8.txt  9.txt
  • use unison to sync the files, but limit the sync to the files named 1.txt, 2.txt, and 3.txt.
root@ubuntu:~# unison -auto -batch local/ remote/ -path 1.txt -path 2.txt -path 3.txt
Contacting server...
Looking for changes
...
Reconciling changes
file     ---->            1.txt
file     ---->            2.txt
file     ---->            3.txt
...
  • confirm the remote directory only contains those files.
root@ubuntu:~# ls remote/
1.txt  2.txt  3.txt

Things get more interesting when content changes.

  • Create the same files in the remote directory. This will update the synced files and create new files for the unsynced.
root@ubuntu:~# for i in $(seq 9); do uuidgen > remote/${i}.txt ; done
  • use unison to sync the directories again
root@ubuntu:~# unison -auto -batch local/ remote/ -path 1.txt -path 2.txt -path 3.txt
Contacting server...
Looking for changes
Reconciling changes
         <---- changed    1.txt
         <---- changed    2.txt
         <---- changed    3.txt
...
  • the synced files (e.g. 1.txt) content will match in both directories. The unsynced files (e.g. 9.txt) content will be different.
root@ubuntu:~# cat {local,remote}/1.txt
7317d9ef-9747-43ae-9f4c-347fc4134e65
7317d9ef-9747-43ae-9f4c-347fc4134e65
root@ubuntu:~# cat {local,remote}/9.txt
76654fcf-d0b2-4788-8a84-b765c9a41cc3
f5db8eb3-4300-463a-9d49-fcb14afcae12