I am trying to sync a subset of my directories between two machines (both Ubuntu 16.04) with Unison (version 2.48.3). On both machines, I have a directory called "research". It contains a folder for each project that I am working on. Within each of these folders, there is a folder named "lit", and I would like to synchronize all those "lit" folders with unison, without really having to care about the project names themselves.
Example: on both machines, there are the following folders:
/home/chris/research/projA/lit
/home/chris/research/projA/otherstuff
/home/chris/research/projB/lit
/home/chris/research/projB/otherstuff
And of these I want to sync projA/lit
across the two machines, and also projB/lit
.
I have installed Unison, and read myself through the manpage. Based on that, I have modified the Unison profile file default.prf
as follows:
# Unison preferences file
# used for syncing lit between work and home
# roots
root = /home/chris/research
root = ssh://pc-work//home/chris/research
# paths
path = */lit
While Unison connects successfully to my work computer, it does not find anything to sync.
If in contrast, I replace path = */lit
in the above profile with path = projA/lit
, it works.
Thus, the question: can I get Unison to sync the lit
subfolder for all projects without having to specify these, and if so, how? Or do I have to wrap the unison command in some sort of loop in order to iterate through all project folders?
path
is not the right way to achieve what you want. From the documentation on path
:
Note that
path
preferences are intepreted literally—they are not regular expressions.
Even though you're not using a regular expression, but a shell glob, I take the above to mean that the value of path
isn't interpreted specially by unison
.
You could achieve the effect you're after, though, by judicious use of ignore
and/or ignorenot
. Those do allow shell globs or regular expressions.
For example, (disclaimer: I haven't tested this)
ignore = Path proj*/otherstuff
for any directory that you want to skip while synchronizing. You could also specify it the other way around, if you have more directories to skip than to synchronize:
ignore = Path proj*/*
ignorenot = Path proj*/lit
Note that you don't need to set path
if the files and directories you want to synchronize are already directly under the root
you specify.