Sync: Local wipe and sync command and better info

pull/320/head
Zef Hemel 2023-01-16 18:34:15 +01:00
parent c046d4a221
commit e4a4467547
5 changed files with 72 additions and 11 deletions

View File

@ -10,6 +10,11 @@ functions:
command:
name: "Sync: Sync"
wipeAndSyncCommand:
path: sync.ts:localWipeAndSyncCommand
command:
name: "Sync: Wipe Local Space and Sync"
check:
env: server
path: sync.ts:check

View File

@ -1,5 +1,11 @@
import { store } from "$sb/plugos-syscall/mod.ts";
import { editor, sync, system } from "$sb/silverbullet-syscall/mod.ts";
import {
editor,
index,
space,
sync,
system,
} from "$sb/silverbullet-syscall/mod.ts";
import type { SyncEndpoint } from "$sb/silverbullet-syscall/sync.ts";
export async function configureCommand() {
@ -68,6 +74,52 @@ export async function syncCommand() {
}
}
export async function localWipeAndSyncCommand() {
let config: SyncEndpoint | undefined = await store.get("sync.config");
if (!config) {
config = await configureCommand();
if (!config) {
return;
}
}
if (
!(await editor.confirm(
"Are you sure you want to wipe your local space and sync with the remote?",
))
) {
return;
}
if (
!(await editor.confirm(
"To be clear: this means all local content will be deleted with no way to recover it. Are you sure?",
))
) {
return;
}
console.log("Wiping local pages");
await editor.flashNotification("Now wiping all pages");
for (const page of await space.listPages()) {
console.log("Deleting page", page.name);
await space.deletePage(page.name);
}
console.log("Wiping local attachments");
await editor.flashNotification("Now wiping all attachments");
for (const attachment of await space.listAttachments()) {
console.log("Deleting attachment", attachment.name);
await space.deleteAttachment(attachment.name);
}
console.log("Wiping local sync state");
await store.set("sync.snapshot", {});
// Starting actual sync
await syncCommand();
}
// Run on server
export function check(config: SyncEndpoint) {
return sync.check(config);

View File

@ -139,7 +139,7 @@
.sb-bhs {
height: 300px;
width: 100%;
z-index: 1000;
z-index: 10;
.sb-panel {
height: 100%;

View File

@ -28,14 +28,14 @@ Dont believe me, check this out, heres a list of (max 10) pages in your sp
|name |
|---------------|
|Sync |
|SilverBullet |
|Getting Started|
|Mobile |
|PLUGS |
|🔌 Plugs |
|Desktop |
|Server |
|SilverBullet |
|Download |
|Getting Started|
|Markdown |
<!-- /query -->
@ -49,7 +49,9 @@ In the case of `#include` this means the body will again be replaced with the pa
Feel free to completely remove all content on this page and make it your own, its just to get you started.
## What next?
Generally, you can find more information about SilverBullet on its official website. You have two ways to access it:
If you plan to use SilverBullet on multiple devices, specifically on a [[Mobile]] device. Have a look at [[Sync]].
Beyond that, you can find more information about SilverBullet on its official website. You have two ways to access it:
1. Through its [regular website link](https://silverbullet.md/)
2. Directly without leaving SilverBullet, through [[Cloud Links]], just click on this: [[SilverBullet]] (note that all of these will be read-only, for obvious reasons)

View File

@ -1,9 +1,9 @@
SilverBullet now has a sync engine. Lets still consider it _experimental_, but its ready for use.
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 this one described here](https://unterwaditzer.net/2016/sync-algorithm.html).
The synchronization algorithm implemented is [pretty much the one described here](https://unterwaditzer.net/2016/sync-algorithm.html).
## Architecture
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.
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!
@ -22,10 +22,12 @@ Heres how to use SilverBullets sync functionality:
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. {[Sync: Sync]} performs a sync. It stores a local sync snapshot (basically a list of timestamps for all files in your space) in its local SQLite database every time.
4. Check {[Show Logs]} for sync logs.
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.
3. Check {[Show Logs]} for sync logs.
Right now, sync needs to be triggered manually, so run {[Sync: Sync]} whenever you feel a sync is warranted.
After this initial sync, **sync needs to be triggered manually**, so run {[Sync: Sync]} whenever you feel a sync is warranted.
## 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.