docker-bg-sync icon indicating copy to clipboard operation
docker-bg-sync copied to clipboard

`rm foo.txt` not synced to host

Open normanlolx opened this issue 7 years ago • 5 comments

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.

normanlolx avatar Feb 06 '18 12:02 normanlolx

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

cweagans avatar Feb 06 '18 15:02 cweagans

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 :)

dj95 avatar Feb 19 '18 12:02 dj95

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

normanlolx avatar Feb 19 '18 13:02 normanlolx

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.

dj95 avatar Feb 19 '18 14:02 dj95

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.

weitzman avatar Jun 07 '19 18:06 weitzman