1
0
silverbullet/website/Sync.md
Zef Hemel 2577a2db32
Continuous sync (#320)
* Continuous sync

* Mobile dep upgrade
2023-01-20 16:08:01 +01:00

3.4 KiB
Raw Blame History

SilverBullet now has a sync engine. Its still early in its development, so somewhat experimental. If you decided to use it make back-ups.

The synchronization algorithm implemented is pretty much the one described here.

Architecture

To use SilverBullet sync, youll use a single SilverBullet Server as your central synchronization space, then connect any other instances of SilverBullet (likely primarily Mobile and Desktop apps, but could also be other Server instances) to it. Each “client” instance keeps track of sync snapshots that it uses to figure out what files have changed where.

Lets put this information in a graph, just because we can!

graph TD;
    iPhone-->SB(SilverBullet Server);
    iPad-->SB;
    Desktop-->SB;
    OtherSB(Other Silver Bullet instance)-->SB;

Usage

Heres how to use SilverBullets sync functionality:

  1. Set up a SilverBullet Server somewhere where all your other devices have access to it. This can be your local network, a VPN, or if youre living the wild life — the public Internet (do put some SSL and authentication on it please).
  2. Connect any other SilverBullet instance (likely the Desktop or Mobile app) to it via the {[Sync: Configure]} command. This will ask for:
    • A URL to connect to (the URL of the SB server configured under (1))
    • A username and password (optional) if you run the server with the --user myuser:mypass flag (as you should)
  3. Now you have two options:
    1. Perform a one-time “clean sync” wiping all local content and syncing down content from the sync server. For this, use the {[Sync: Wipe Local Space and Sync]} command. This is likely what you want for e.g. an initial Mobile setup.
    2. Use {[Sync: Sync]} to perform a regular sync, comparing the local and remote space and generating conflicts where appropriate.
  4. Check {[Show Logs]} for sync logs.

Sync is triggered:

  • Continuously when changes are made to a page in a client set up with sync, immediately after the page persists (single file sync)
  • Automatically every minute (full space sync)
  • Manually using the {[Sync: Sync]} command (full space sync)

The sync process

  1. The sync engine compares two file listings: the local one and remote one, and figures out which files have been added, changed and removed on both ends. It uses timestamps to determine changes. Note this doesnt make any assumptions about clocks being in sync, timezones etc.
  2. In most cases, based on this info (together with the snapshot from the last sync) it should be obvious what to do, and it will do just do it.
  3. In case of a conflict — which would happen if files on both ends have been changed since the last sync, it will first pull down both files and compare their content. If theyre the same, no issues. If theyre different: a conflicting copy will be created with a name of page name.conflicted.timestamp. Youll see those appear in your page list.

Caveats

  • This is new code, and not been extremely thoroughly tested. Make backups.
  • The sync engine doesnt synchronize _plugs code, so to update the plug list based on your PLUGS you have to manually run {[Plugs: Update]}.

So, if youre ready for this. Go try it. We do recommend: make regular backups in case the proverbial shit hits the fan, dont say we didnt warn you!