How I Organize My Static Files With IPFS and Org-Roamfleeting
Traditionally, when we store a file, there is a central question that we ask ourselves: where do I put the file?
I seldom find satisfying answers to this question using the classical folder hierarchy. Also, when I need the file in the future, I generally have a hard time finding it, because my mindset changed in the mean time.
Imagine I want to keep some file, like my emoji. In that traditional state of mind, I would put the data in some hard drive in a location that would make sense at the time. Something like “personal/identity/emoji.jpg”.
zettelkasten to the rescue
I’ve always wanted to remove the burden of finding a path. I was quite convinced by tools like git or ipfs, with a content addressable state of mind. But I did not have a satisfying way to index those files.
Why stop here and just retrieve old thoughts? Why not also use my conversation partner to dig out files I have put in it.
my new workflow
Then, my workflow is:
- realize I need to store a file,
- decide what this file means. What is the concept that this file makes concrete,
- ipfs add the file,
- provide this hash to my conversation partner, like I put any other zettel,
- forget about it.
If I need to get the file back, I trust my conversation partner for showing my the appropriate note when the time comes. That means that when I want the file back, I don’t have to think in file hierarchy, but I can just look for whatever comes to mind and let the network of thoughts naturally lead me to my file.
how to store those files
To do so, the system needs to be able to store files in addition to simply store notes.
I also have an ipfs companion program per ipfs node that runs `ipfs get`, ensuring that the node has the content it is supposed to have. There is also an ipfs controller whose role is to find CIDs not yet allocated and ask the ipfs companions to ensure the nodes have downloaded them.
To make the ipfs companions and the controller discuss and store a temporary state of what files to get, I also have an instance of redis running.
Finally, my laptop runs also an ipfs node connected to the cluster, allowing me to ipfs add locally.
the workflow of the ipfs companions
The ipfs companions keep up-to-date a redis value of the remaining disk space.
The ipfs controller, at regular intervals, finds in postgresql what CIDs have not been replicated yet, decides what companion should store the CID based on the remaining space, then order via redis the companions to get the appropriate files and finally update the postgresql database to indicate what companion owns which CID.
Also, I made a script that
- extract all the CIDs from places of interest (like my zettelkasten),
- add missing CIDs in postgresql,
- remove extra CIDs from postgresql,
At first, the CID are only added in the ipfs node that runs in my laptop. Then, when the postgresql database is updated, the ipfs controller duplicate those in the ipfs nodes.
From time to time, I also have a script that consult the ipfs controller and the ipfs companion to check whether the sync is done.
likecycle of the data and backup
The ipfs controller makes sure that at least two nodes store each CID, making the system resilient to the possible crash of one disk.
Garbage collecting old files is a side effect of me practicing manual progressive chaos monkey. From time to time I replace a hard drive with an empty one. Because the controller allocated each CID to at least two nodes, then the system realizes there are bunch of files that are to be duplicated again. It does the work of asking another node to keep a new copy.
Now, the last part of the system is about backups. I have an external drive that receives weekly a copy of all the CIDs stored in postgresql. It puts them in a multi layered directories3. Then, using an encrypted borg, I create a remote backup of my backup on the drive of a friend that lives in another country.
Therefore, to loose some file, it means that
- either my computer crashed before the sync happens,
- or the same thing4 + at least two nodes crash during the week of adding the file without me noticing (or quickly enough for me not to have time to deal with the crashes),
- or the same thing + my external backup and my friend encrypted copy crash quickly enough for me not to be able to fix them,
Well, I feel pretty good about the persistence of my data.
Now, with all that in place, here is the complete workflow to add a file:
- I need to save a file,
- I ipfs add it,
- Put the CID in some sensible note,
- then, the system deals with replicating the file, so that I don’t have to bother thinking about it again.
And the workflow to retrieve a file:
- I ask the system,
- I get the note,
- I open the file,
Notice that the part of the flow where I actually use cognitive energy is very small (EAST). In the end, I just add a file where it naturally belong and let the system deal with the rest.
I have made the system such as it leans on some habits I must have, like running the sync script. This semi automated system is my personal way of dealing with automation.
Notes linking here
- comment je référence mes fichiers
- ideal file system
- inverse la dépendance aux fichiers
- literate data storage
- my stack
I could have created any system that provides content addressable addresses. Ipfs shines in the way it works well on raspberry pi, it is meant to work in cluster so that I can easily add a node to add space and redundancy. ↩︎
Actually, not only does it sync my CIDs with postgresql, but it also wait for the CIDs to be replicated before actually publish, so that I can poweroff my laptop without the risk of having a note referring to some unavailable file that would have only one copy (in my off laptop), ↩︎
I ipfs repo gc my laptop only after a successful backup ↩︎