Synchronizing and backing up Logseq data with Syncthing and rclone
Even in a world of cloud-based software, it's often necessary and useful to set up custom synchronization and backup solutions. In my case, this necessity presented itself during my use of Logseq, an incredibly powerful and intuitive privacy-first knowledge management software tool. While Logseq does offer a sync feature, as of now it's only available to sponsors and backers of the project, and includes a disclaimer:
Please note that while it's a public beta, it's still very much a beta test.
In this article I will explore my solution to synchronize Logseq data between devices and additionally back this data up to Google Drive. While the focus will be on the Logseq use case, this information is easily adaptable to general synchronization and backup requirements (such as for use with Obsidian).
My tools of choice for this purpose are:
Syncthing, a "continuous file synchronization program"
rclone, a "command-line program to manage files on cloud storage"
My integrated solution entails the synchronization of data from two machines to a local server where cloud backups are performed. All of my devices run Linux, but this setup should be adaptable to other operating systems.
Let's take a look at how to set this up! 🛠️
Synchronizing with Syncthing
I suggest you begin with Syncthing's thorough Getting Started guide. Here you will find installation instructions as well as introductions to its specific terminology including "local" and "remote" devices.
For my setup, I chose to sync the entire
~/Documents directory, home to Logseq's data folder. The following screenshots are from the "local" device (my local home server) hosting a Syncthing instance in a container - this is why the folder path exists inside the
I share this directory between two devices with the hostnames
This approach means the two devices don't need to be powered on simultaneously to sync data between them. The local server acts as an "always on" intermediary.
For more information about running Syncthing in a container on a home server, check out my blog post about using Ansible for precisely this purpose!
Backing up with rclone
While Syncthing ensures all devices on the local network have access to the same Logseq data, it's important to back this data up outside the network. I chose to use Google Drive for this purpose as I find it an easy-to-use option with generous free storage space. The featureful rclone tool interfaces with many other cloud storage options as well, so feel free to use any of its supported providers.
Setting up rclone
First, install rclone using these instructions.
Next, initialize a new remote using rclone's interactive setup processing, following the instructions provided in its excellent Google Drive documentation.
Now, you can backup the synchronized
Documents directory using this rclone command (assuming Syncthing is running in a container with a volume named
syncthing-config, using a remote named "remote"):
rclone sync ~/.local/share/containers/storage/volumes/syncthing-config/_data/Documents remote:Backup/Documents
~/.local/share/containers/... path is where container volumes are stored by podman, an alternative to Docker.
If you're synchronizing the entire
Documents directory but you're not running Syncthing in a container, you can back up the
Documents directory directly:
rclone sync ~/Documents remote:Backup/Documents
Backups reside in the
Backup directory at the top level of my Google Drive. Here you can see the "brain" graph inside the
Documents/logseq directory backed up as intended.
However, this required manually running the rclone command-line tool. Let's automate this process using systemd timers!
First, create a new systemd service file
~/.config/systemd/user/rclone-sync.service containing this content (adapting the rclone command for your specific setup):
ExecStart=/usr/bin/rclone sync ~/.local/share/containers/storage/volumes/syncthing-config/_data/Documents remote:Backup/Documents
Next, create a systemd timer file
~/.config/systemd/user/rclone-sync.timer. Note that the filename (minus the
.timer extension) must match the service name, i.e.
rclone-sync. The file will look like this:
Description=rclone hourly backup
OnUnitActiveSec= options instruct systemd to run this timer an hour after the machine boots, then an hour after the last activation, so this timer will run continuously every hour. Should you prefer an alternative backup schedule, see this documentation for information about the available time specifications.
Finally, enable the timer with this command:
systemctl --user enable rclone-sync.timer
You can observe the status of timers using this command:
systemctl --user list-timers
The availability of open-source synchronization and backup tools allows anyone to create custom solutions for their given use case. With the setup explored here, Logseq data is automatically synchronized between devices through a home server where this data is backed up to the cloud so that your knowledge base is readily available on your network and securely stored outside of it for redundancy and peace of mind.
Have fun using Logseq! 🥳