Unison: sync only in one direction
Asked Answered
T

5

12

If I have folder A and B, is it possible to sync the new files from A to B and to not erase in B files erased in A?

That is to say, I would like to use B as a big container for any file, including the one that I once synchronized from A and than erased. I think is considered kind of "one way syncing".

Thorton answered 23/8, 2017 at 19:54 Comment(0)
A
15

I understand that you are having these two requirements on Unison

  • mirroring folder A to B and
  • preserving data on B

Mirroring

According to the Unison manual, the -force xxx option "effectively changes Unison from a synchronizer into a mirroring utility". The force option takes the folder that is to be favored as argument. Unison will resolve all changes in favor of this folder.

The commandline to mirror, e.g., folder /src/dir to /dest/dir would be

unison /src/dir /dest/dir -force /src/dir

Preserving

Use the option -nodeletion xxx to prevent Unison from recommending any deletion on the folder xxx as default action.

The commandline to preserve files on /dest/dir after they have been deleted from /src/dir would be

unison /src/dir /dest/dir -nodeletion /dest/dir

Sum up

So in total you want to run Unison with these two options to satisfy your requirements:

unison /src/dir /dest/dir -force /src/dir -nodeletion /dest/dir

Notes

Until you have set up Unison to run in batch mode, I recommend to run Unison in interactive mode using the graphical UI. Working with the graphical UI is more convenient as you see all pending changes including the default actions Unison suggests.

When you are satisfied with the default actions, you can run unison in batch mode (option -batch) using the textual UI. In batch mode, changes with default actions will accepted, changes without default action (due to conflicts) will be skipped.

Remember, these options can be overridden in interactive mode by the user. They are in no way an absolute protection against deletion, they just provide guidance to Unison about how to decide on the default action. In interactive mode, the user can always override the default action, i.e., press "<" to propagate the change to the source folder (the direction which you do not want).

Augustineaugustinian answered 17/2, 2019 at 11:21 Comment(2)
The manual says: Including the preference -force root causes Unison to resolve all differences (even non-conflicting changes) in favor of root. So why bother to use -nodeletion?Charr
@TomHale Because without it, the conflict "a file exists in /dest/dir but not in /src/dir" would also be resolved in favor of /src/dir (which means "/src/dir is correct"), effectifely deleting it in /dest/dirGervase
F
2

Yes, you probably want to use noupdate and/or nodeletion options: -nodeletion xxx prevent file deletions on one replica -noupdate xxx prevent file updates and deletions on one replica

Read the full description in the manual.

Flori answered 22/12, 2017 at 22:12 Comment(0)
C
1

I would say:

source=A
target=B
unison $source $target -batch -nocreation $source -noupdate $source -force $source
Crucifix answered 26/12, 2018 at 11:53 Comment(2)
I suggest to try the above command first without the flag -batch so you can see what unison is about to do BEFORE it actually does it.Augustineaugustinian
Note: Contrary to the requirements set forth in the question ("to not erase in B files erased in A"), this answer does propagate deletions to the destination. Sorry, I upvoted this answer before I tried this exact setup myself. And it seems that I cannot remove my upvote. My bad. To make good, I provided my own answer below. Thanks.Augustineaugustinian
T
0

If anyone else came here looking for an actual answer on how to do this with unison you simply need to use the -force flag followed with the source directory e.g.

unison /source/dir /destination/dir -force /source/dir

This will ensure that the destination will match the source no matter what changes are made to the destination.

BTW, unison is way faster than rsync when you have very large amounts of data spread across millions of files when only a few of which have changed.

Topaz answered 14/6, 2018 at 11:29 Comment(1)
The correct command line has to be unison /source/dir /destination/dir -force /source/dir Sorry lads, I also edited this answer to correct this mistake in it and upvoted it after my correction. However, my edit has been rejected. So this wrong answer stands uncorrected (and I can not downvote it).Augustineaugustinian
R
-3

Yeah, don't use unison. Just use rsync. If you'd like to get fancy, you can use cron to schedule whenrsync gets run, or useinotify-tools to watch for changes in folder A and sync exactly when changes happen.

Rarefied answered 23/8, 2017 at 22:7 Comment(2)
Honestly, I don't get why you got so many downvotes for this answer. My first reaction when I read the question was also "rsync" :) Esp. since not propagating deletions is the default there!Essene
The thing that unison really does better is that it automatically detects moves, even across different directories! So if your use case is frequent re-organization of files, then unison gives you a huge decrease in network transfer. The "price" for that is that unison needs a (small) database to make move-detection efficient. So the tools have different pro's and con's.Ataliah

© 2022 - 2024 — McMap. All rights reserved.