Logseq DB (v2) and git sync
By chimo on (updated on )Just jotting down notes on a naive way of syncing my Logseq (v2) graph to a remote git repository using the Markdown Mirror Logseq feature.
- Initialize a git repository somewhere (ex: ~/logseq-git).
- Enable Markdown Mirror in your Logseq graph.
- Create a `logseq` alias/script which
- Starts an auto-commit loop in the background.
- Launches Logseq.
- Auto-commits one last time once Logseq terminates (ex: when Quitting).
#!/bin/sh -eu
git_dir="~/logseq-git/.git"
work_tree="~/logseq/graphs/Demo/mirror/markdown"
auto_commit() (
# Add all files
git --git-dir="${git_dir}" --work-tree="${work_tree}" add -A
# Commit
git --git-dir="${git_dir}" --work-tree="${work_tree}" commit -m 'Auto-commit.' || true
# Push
git --git-dir="${git_dir}" --work-tree="${work_tree}" push || true
)
main() (
# Auto-commit loop
(while true
do
auto_commit
sleep 60
done)&
loop_pid=${!}
# Launch logseq
logseq
kill "${loop_pid}"
# Commit on close
auto_commit
)
main
Notes:
- This would probably be better as an actual Logseq plugin.
- The script above only auto-commits a single graph (I only have one).
- From limited testing, it seems to be working okay but time will tell.
- Some weird things may or may not happen if multiple Logseq instances are launched via this script (I only ever have one instance running).