Possibly stupid question about sync vs local

With apologies for this basic question:

As far as I can see, if I have a Logseq local graph in my Mac, I can’t sync it with my iPhone or iPad. If I want to use all those devices, I have to keep my graph on GitHub.

Is that correct, or have I missed something obvious (new to GitHub, so that’s entirely possible)?

Thanks

1 Like

You can keep your files on your hard drive to work with them offline in desktop app, but to access them on mobile devices you need github. By default you would need to manually update your github repo and your local repo by add/commit/push and pull commands in mac terminal. But it’s possible to automate this, let me know if you want to do that, I could give you instructions to make this work.

Thanks for the confirmation - and yes please, if you could summarise the Terminal automation, I’d appreciate it. I expect it’s quite simple for those familiar with Github, but that ain’t me!

Thanks again

First of all, clone your github repo to place where you want to keep it. I would assume here that your repo name is logseq and you will keep it in your documents folder

cd ~/Documents && git clone https://github.com/YourGithubUsername/logseq.git

Install fswatch with homebrew, if you’re using this package manager. If not, install it first https://brew.sh/ , or compile fswatch yourself, there is INSTALL file with instruction in their repo.

Create folder log in your user folder mkdir ~/log
Create file com.thatguy.logseqfswatch.plist and place it in ~/Library/LaunchAgents/. Content of the file:

?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
	<dict>
		<key>Label</key>
		<string>com.thatguy.logseqfswatch</string>
		<key>Program</key>
		<string>~/Documents/logseq/logseq-fswatch.sh</string>
		<key>RunAtLoad</key>
		<true/>
		<key>KeepAlive</key>
		<true/>
		<key>StandardOutPath</key>
		<string>~/log/logseqfswatch.log</string>
		<key>StandardErrorPath</key>
		<string>~/log/logseqfswatch.log</string>
	</dict>
</plist>

Create file logseq-fswatch.sh and place it in ~/Documents/logseq/logseq-fswatch.sh. Content of the file:

#!/bin/bash
/usr/local/bin/fswatch -0 ~/Documents/logseq -l 10 -e "\\.git.*" | xargs -0 -n 1 -I{} sh -c 'cd ~/Documents/logseq && git add .; git commit -m "auto sync"; git push;'

It will add, commit and push changes 10 seconds after it detect it. If you want to push immediately then remove -l 10.
Make this file executable chmod a+x ~/Documents/logseq/logseq-fswatch.sh

Run these commands
launchctl load ~/Library/LaunchAgents/com.thatguy.logseqfswatch.plist
launchctl start com.thatguy.logseqfswatch.plist

And right away run this tail /var/log/system.log and look if there are no errors regarding your com.thatguy.logseqfswatch service.

Thats it for pushing your local changes to github repo. Now for pulling changes:

Create file com.thatguy.logseqautopull.plist and place it in ~/Library/LaunchAgents/. Content of the file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
 <key>Label</key>
 <string>com.thatguy.logseqautopull</string>
 <key>ProgramArguments</key>
 <array>
  <string>git</string>
  <string>-C</string>
  <string>~/Documents/logseq/</string>
  <string>pull</string>
 </array>
 <key>StandardErrorPath</key>
 <string>~/log/logseqautopull.log</string>
 <key>StandardOutPath</key>
 <string>~/log/logseqautopull.log</string>
 <key>StartInterval</key>
 <integer>60</integer>
</dict>
</plist>

It will pull changes from github every 60 seconds, you can change this line <integer>60</integer> if you want different interval.

Run these commands
launchctl load ~/Library/LaunchAgents/com.thatguy.logseqautopull.plist
launchctl start com.thatguy.logseqautopull.plist

If you see that something didn’t sync, you can look for errors in logs in ~/log folder.

That’s all, at least it was for me :slight_smile: There are minor problems with Logseq when it comes to working on multiple devices, you might see in your mobile devices that it want you to decide if you want to keep your local changes or update it with changes from github. AFAIK they are working on making it more smooth.

2 Likes

Many thanks for this. I’ll have a go and report back

Hey @Piotr thanks for the amazing complete instructions. If I got it correctly this is similar to a cronjob, just automating back up to the github repository right?

If so, this is a great method for keeping constant backups which is always a good idea.

In regards to syncing with mobile, what are the added benefits of using this approach? Is it mostly to make sure that any chances in mobile are automatically pulled into the local desktop folder? Or is there something else that I’m missing when it comes to using logseq in mobile?

Thanks again for the excellent instructions!

1 Like

Similar on surface - with cron you can only do stuff in intervals (AFAIK), for example once a day or hour or minute. Here the script is being run every time something changes (update in file, new file added, file removed, etc). Every time Logseq updates something on hard drive in directory with your repo, changes are commited to git and pushed to github. Which means there is no way to loose data (and you will always have access to latest state of your notes on multiple devices).

You can work in desktop Logseq app, have your local copy for offline use, and still being able to work with your data in Logseq on mobile browsers. This is the only way to mix these things together.
Also it’s impossible to upload images and other files to your private repo with browser version of Logseq, they are uploading them to AWS, not to github, so this is another reason to keep files on hard drive - images and files can be stored in “assets” folder on your drive and on github, you have full control over all of your data :slight_smile:

1 Like

Got you, thanks a lot @Piotr really appreciate your explanation, it makes perfect sense. Can’t wait to try it out!

I’m on older MacOS and someone PM me to say that there is problem with launchctl load command, it gives error Load failed: 5: Input/output error. Looks like Big Sur (and Catalina?) broke this https://www.reddit.com/r/MacOS/comments/kbko61/launchctl_broken/

launchctl is here to test these scripts without rebooting - by default everything loads itself at startup. User in that reddit thread said that it works after reboot, but here is another comment that says it doesn’t bash - How can I run a Python script on Startup (macOS)? - Stack Overflow

I’m sorry, but it looks like my solution with .plist files might not work for at least some you. There are other solutions to run scripts at startup, some of that might work for you bash - Running script upon login mac - Stack Overflow

To clarify it a bit, all you need are these two commands:

  • to push stuff from your local repo to github, this will run constantly and watch your changes until you manually kill it or reboot/close the system:
/usr/local/bin/fswatch -0 ~/Documents/logseq -l 10 -e "\\.git.*" | xargs -0 -n 1 -I{} sh -c 'cd ~/Documents/logseq && git add .; git commit -m "auto sync"; git push;'`
  • to pull from github into your local repo, this needs to be executed in intervals if you want to have always same data in mobile and desktop:
git -C ~/Documents/logseq/ pull

You can just do both manually in terminal, first one once after you start your system and second one everytime when you update something on mobile, but of course it’s so much better if you can automate this.

There’s a much easier way. Download SparkleShare. It’s open source Mac software which automatically syncs a local folder with a Git repository.

http://www.sparkleshare.org/

1 Like

Thanks - in fact, I solved the problem by using Obsidian for mobile, following @Luhmann’s approach.

With only luck the forthcoming mobile LogSeq app will do the job.

Hello, since the update, I use the native Logseq folder on my iCloud Drive, and it keeps my desktop and mobile app graphs in synch.