Skip to main content

Keeping everything in sync

For anyone who has used multiple machines before, it can be a pain. This or that configuration is different, a file is on this machine but not that one, programs are at different update levels. It’s never clear what is backed up and from when. While I’m not even close to solving all these problems in their entirety, I have made some progress in making things more manageable.

The same files across devices

If you use Microsoft’s Onedrive or Apple’s iCloud, files have probably often been kept in sync between your devices (sometimes even if you didn’t know something was in the cloud, it somehow was synced there anyways). Without using those services, I wanted a way to make sure that certain directories were always in the same state across devices.

Syncthing solves this problem. Instead of syncing files to a cloud and back down again, the sync is done solely among the devices. It has clients for almost all platforms, making it a great option for those that may work across operating systems. Additionally, if the internet is unavailable you don’t have to worry about not being able to access files that aren’t also present on your device. The worst that happens is that syncing stops until you connect to the internet again.

Installing Syncthing on Debian

To install on Debian, you will need to configure the syncthing apt repository and then install the application through apt. For any other operating system, the instructions and releases are on this page.

# Add the syncthing keys
sudo mkdir -p /etc/apt/keyrings
sudo curl -L -o /etc/apt/keyrings/syncthing-archive-keyring.gpg https://syncthing.net/release-key.gpg

# Add the "stable" channel to your APT sources:
echo "deb [signed-by=/etc/apt/keyrings/syncthing-archive-keyring.gpg] https://apt.syncthing.net/ syncthing stable" | sudo tee /etc/apt/sources.list.d/syncthing.list

sudo apt-get update
sudo apt-get install syncthing

Configuring which folders to sync

After installation, you should be able to start the Syncthing service by launching Start Syncthing from the application launcher. Then, launch the web UI through a similar manner by launching Syncthing Web UI. This will open on localhost:8384.

syncthing web gui screenshot

Adding devices and folders is pretty straightforward once you have the GUI up, so I won’t go over it in depth here. Just make sure that Syncthing is installed on all the devices that you want to keep in sync (it even does mobile devices) and you should be good to go.

Using the same configuration across devices

The experience of different tools, such as the shell, neovim, and tmux, should be consistent between devices. Nothing is worse than hitting some keys and having something not happen because the functionality is only available on the other machines. For this, I use gnu stow

Download and setup stow

sudo apt install stow

Create a dotfiles git repository

There are a ton of examples of dotfile repositories out there, so you can really set it up in the way that feels best for you. The only real thing to keep in mind when using stow is that the setup of the repository should mirror what the configuration would look like in your home directory. For example:

~/
  .config/nvim
  .zshrc
  
dotfiles/
  .config/nvim
  .zshrc

Then, place the repository at ~/dotfiles. Change into the dotfiles repository with cd dotfiles then run stow .. For a more in depth look on how to setup dotfiles and stow (including if you need to work with existing files), I would recommend this video. It took me a while to wrap my head around it, but once it clicked, it made a lot of sense.

Once setup, any changes that you make to your configuration (including the versioning of neovim plugins if using a plugin manager like lazy.nvim) will be synced through this system. Just pull and push between the different machines[1].

Managing backups

For backups I use borg. There are two options, either having both desktops and laptops pushing to borg independently, or having one machine push on every machine’s behalf. Since Syncthing is now setup, all machines should have a synced directories, which can then just be pushed using Vorta on a scheduled interval. This has the benefit of reducing duplication in the backup repository, and only one machine needs to be configured with an ssh key.

a diagram showing two way sync between the laptop and desktop and one way backup to an offsite backup

The backup system works differently than the sync, backups should not be real-time copies of the files, and should have snapshots that can be restored from. There should also be warnings setup if backups stop for whatever reason.

Code is kept separate and managed by git

I maintain a separate directory that is exclusively used for git repositories. This repository is neither synced or backed up through Borg. Instead, each repository is backed up to a remote git repository.

Is there a role for cloud storage?

The only feature that this setup doesn’t have is an easy way to share files with others, and this is the primary purpose that cloud storage will have to fill for the time being. Aside from that, my usage of cloud storage has dropped quite dramatically for personal use.

If there is anything that you feel I have missed, or if you have any neat tips when it comes to file syncing and backups, I would love to hear about them.


  1. I’ve found that this works really well if all the systems are the same operating system. It will still work between a machine running macOS and linux, however some configuration may be expected to be different between them. ↩︎