cweagans / docker-bg-sync

A container that syncs files between two configurable directories.
224 stars 39 forks source link

`rm foo.txt` not synced to host #16

Open leymannx opened 6 years ago

leymannx commented 6 years ago

Same docker-compose.yml as in the README only added SYNC_PREFER=newer. Adding files are synced just fine in both directions. Removing files in contrast is synced in only one direction host -> container but not vice versa.

Steps to reproduce:

  1. $ git clone https://gist.github.com/leymannx/277095bcc750300e749d5ae185181b74.git bg-sync
  2. $ cd bg-sync
  3. $ docker-compose up -d (wait until done)
  4. $ touch foo.txt
  5. $ docker exec -it -w /var/www/myapp bgsync_web_1 bash -c "touch bar.txt"
  6. Confirm both files exist in both locations:
    1. $ ls
    2. $ docker exec -it -w /var/www/myapp bgsync_web_1 bash -c "ls"

Now delete the files:

  1. Again inside the bg-sync folder from step 1. on the host: $ rm foo.txt
  2. $ docker exec -it -w /var/www/myapp bgsync_web_1 bash -c "rm bar.txt"
  3. Confirm that bar.txt still exists on the host but both files are removed from the container:
    1. $ ls
    2. $ docker exec -it -w /var/www/myapp bgsync_web_1 bash -c "ls"

macOS 10.13.3 Docker for Mac (stable) 17.12.0-ce-mac49 (21995)

I guess for most people that's just OK as they are more interested to sync from the host into the container which works just fine also for removing files. Also as $ echo "bla bla bla" >> file.txt inside the container is synced still fine to the host. It's only rm that's not synced.

cweagans commented 6 years ago

Huh. That's interesting. Not sure what I can do about it though. Sounds like a Unison bug.

dj95 commented 6 years ago

This happens because in the default configuration the nodeletion option is set to the source (https://github.com/cweagans/docker-bg-sync/blob/master/sync.sh#L131). In the log file unison logs, that it skipped removing the file because of a nodeletion option. Overwrite the nodeletion-option with a custom setting or set the environment variable SYNC_NODELETE_SOURCE=0 in you docker-compose.yml. It's always helpful to read the log files and documentation :)

leymannx commented 6 years ago

@dj95 Wow Thanks! How exactly do you access the log files?

dj95 commented 6 years ago

The default unison log-file is unison.log in the users home directory which runs unison(default with your docker-compose.yml should be /root/unison.log). With logfile = $PATH in your SYNC_EXTRA_UNISON_PROFILE_OPTS you're able to save it anywhere in your container. But be aware of setting it into one of your synced volumes because it throws a lots of errors because of a kind of race condition when unison wants to read and write the file at the same time.

weitzman commented 5 years ago

Probably worth fixing this. Inside the container there can be deletions of compiled twig, css/js, etc. You dont want that bloating and confusing the IDE on the host.