Skip to content

A command to wait for sync #7849

Open

Description

@njaard

I would like a command that blocks until the current folder is fully synchronized.

Why? I have a directory on my "local" machine with my data and my remote computer that I ssh into, which processes the data. Sometimes I make a small change to the data and want to process it. Let's say I process the data with make. Right now, if I make a small change locally and then immediately type in make, my remote server won't see the changes for several seconds, which means I don't know what I'm making.

So, instead of typing in make on my local server, I type in something like syncthing sync && make

  • syncthing sync immediately fails if all of my remotes are not connected
  • Then it makes sure that the synchronization is complete, which means that local and remote servers have detected and transferred all changes
  • syncthing exits (no error code), which means that the files match the remote files.
  • make is now sure to complete properly

There are no alternatives other than waiting, and there's no way to know how long to wait.

I write this like "syncthing sync" verifies that all files are synced the syncthing folder that $PWD is contained in, it could alternately be all syncthing folders that are "mounted" on the local machine.

Activity

  1. added
    enhancement
    needs-triage
    on Jul 23, 2021
  2. changed the title [-]A command to block on sync[/-] [+]A command to wait for sync[/+] on Jul 23, 2021
  3. calmh commented on Jul 24, 2021

    @calmh
    Member

    This can be determined via the API, so it could be done in an external script. It could also be done by something like syncthing cli await-insync now that we have the CLI integration.

  4. removed
    needs-triage
    on Jul 24, 2021
  5. added theissue type on May 30, 2025
  6. achadwick commented on Sep 7, 2025

    @achadwick

    I would like this feature in core syncthing too. My use case is a little Lakka box that I set up to sync game state files. A physical switch shutdown that interrupts the game will make Lakka's RetroArch autosave the game state locally, which then may or may not trigger a Syncthing sync (during shutdown, eek). It would be nice to wait for the autosave file to propagate out to my cloud in a systemd service's ExecStop before issuing a syncthing cli operations shutdown, say.

    Martchus/syncthingtray's syncthingctl command already does something like this, and has obviously considered some edge cases. There's no mention of syncthing cli operations shutdown doing this.

    $ syncthingctl --help
    [...]
    wait-for-idle, -w
      waits until the specified dirs/devs are idling
      note: Directories are considered idling if they are locally up-to-date and NOT otherwise
      busy with e.g. scanning. Devices are considered idling if they are disconnected or all d
      irectories shared with the device are remotely up-to-date.
      --dir, -d [ID]
        specifies a folder by ID
      --dev [ID/name]
        specifies a device by ID or name
      --all-dirs
        applies the operation for all folders
      --all-devs
        applies the operation for all devices
      --at-least, -a [number]
        specifies for how many milliseconds Syncthing must idle (prevents exiting too early in
        case of flaky status)
      --timeout, -t [number]
        specifies how many milliseconds to wait at most
      --require-devs-connected
        requires all specified devices to be connected (by default disconnected devices are co
        nsidered idling)
    
      example: syncthingctl wait-for-idle --timeout 1800000 --at-least 5000 --all-devs --all-d
               irs && systemctl poweroff
               syncthingctl wait-for-idle --dir dir1 --dir dir2 --dev dev1 --dev dev2 --at-lea
               st 5000
    [...]
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions