Restore logseq graph from .transit file

background

recently, I’ve lost my logseq notes for about twenty days. as I use onedrive to sync and had not launched onedrive for about 20 days. and when I relaunched onedrive, something bad happened, it just override my latest updates with the old versions. I know it’s my own mistake for trust onedrive totally without any extra backup.

lights

I struggled to recover the data, and eventually I found a .transit file which is out of notes directory and is free from override by onedrive. and I do observe the override updates in it.

ask for help

is it possible to recover graph from .transit file, mainly the markdown files.
ps. I have checked the bak directory, but with no luck, it do has some updates, but lost too much. and this is probably caused by my forcing quit logseq when onedrive was doing crazy things(another mistake)
ps. I tried to read logseq source code, but clojurescript is too strange for me. and I found restore-graph! and it calles restore-from-transit-str!. so I think it’s possible to recover graph from .transit files. but unfortunately clojurescript is too hard for me at present. I do have some little programming skill, I really appreciate it if someone can help!

Update Edit

what I encountered is graph and logseq app both lost the data. if your logseq app keeps the latest update version, there is no need to manipulate the .transit file. If the .transit file is also updated with the outdated version, this post cannot help you. If graph is really important, git or ‘timely sync’ is strongly encouraged.


original post

finally, I’ve recovered most files without programming a tool in clojurescript :grinning:. maybe I will learn this language sometime later.
here is what I did if it can help some one in the future

  1. go to ~/.logseq directory, find xxx.transit file.(I didn’t recover all of my data for this file is saved three days ago and I suppose this saving action is mainly triggered by a normal quit app). this file location may diff in different os, check first. and then save a copy in time. as this file may be updated by logseq, for example when quit. we have to make use of the time gap and inconsistency of state between .transit file and graph directory as logseq can restore it’s consistent state automatically and drop the data we lost

  2. quit logseq

  3. duplicate the saved copy of .transit file in the same origin directory with another name. logseq just join the full directory of graph to name the .transit files. and relaunch logseq.

  4. the exciting moment came, in the dropdown menu of graph selection(left top), the extra graph(it’s name is determined by the name of .transit file which is what you give in step 3). Just select and switch to the new graph, and you will see the lost pages.

  5. ignore the error tips logseq display, as the new graph has a new name, but the derived directory (notes content )does not exist. you can then export or just follow the refer link Can I Convert Cache to Graph? - Questions & Help - Logseq. run logseq.api.download_graph_pages() in the js console of dev tools of chromium.

  6. a zip archive is downloaded and that’s your lost pages and journals. regarding asset(eg. some pdf file), it just gets lost in the void.

tips:

  • quit logseq normally may helps sync and persist graph state in local disk.
  • Do not force quit logseq and be patient especially when doing sync.
  • remember not to trust any software totally, especially when you know not much about it. and make a backup in time/scheduled.
  • when restore the markdown files, diff is a great tool and helper.
2 Likes