Syncthing Server: Difference between revisions

From Unixcat.net Wiki
Jump to navigation Jump to search
(Created page with "[https://syncthing.net/ Syncthing] is a tool written in Go to keep files synchronised between computers. It's decentralized, meaning instead of syncing to a server, your comp...")
 
No edit summary
Line 1: Line 1:
[https://syncthing.net/ Syncthing] is a tool written in Go to keep files synchronised between computers.  It's decentralized, meaning instead of syncing to a server, your computers can find each other on the network and sync amongst themselves.  It can work over the internet as well, although I don't use it that way.
[https://syncthing.net/ Syncthing] is a tool written in Go to keep files synchronised between computers.  It's decentralized, meaning instead of syncing to a server, your computers can find each other on the network and sync amongst themselves.  While I don't use it outside of my home network, it can run over the internet as well - it uses relay and discovery severs, and can even traverse NAT.


Prior to Syncthing, I used [https://nextcloud.com/ NextCloud], which runs on a web server.  I used this to keep some directories on several computers in my home network synchronized.  It worked, and I actually still have an install I point my phone too (although Syncthing has an Android app as well).  However, sometimes it would be slow, particularly with a lot of small files.  The server also stores all of its files in its own directory, and depends on a database (I have used both MariaDB and SQLite).
Prior to Syncthing, I used [https://nextcloud.com/ NextCloud], which runs on a web server.  I used this to keep some directories on several computers in my home network synchronized.  It worked, and I actually still have an install I point my phone too (although Syncthing has an Android app as well).  However, sometimes it would be slow, particularly with a lot of small files.  The server also stores all of its files in its own directory, and depends on a database (I have used both MariaDB and SQLite), as opposed to Syncthing which is just its own executable.


While I like the idea of not having to have a dedicated server in the sense of NextCloud, I do have a NAS I would like to keep the directories I sync on.
One advantage of the central model NextCloud uses is that if you only have one of the computers you're syncing online, it can still keep the copy of the server up to date.  While Syncthing can deal with conflicts (by renaming the conflicting files), it's nice to not have to have both machines on for them to sync in all cases.  (Although again, Syncthing can sync the two if only the two of them are online; NextCloud would still need to talk to its server.)  I had already had a machine running with an external hard drive as kind of a stopgap NAS, so I looked into how to get Syncthing going on this as well.
 
== Syncthing on a Headless Server ==
 
Syncthing can run just fine on a headless machine, with a caveat - each user requires a running instance.  (This is the case as far as I know, I don't know if a multiuser version is in the works at the moment.)  Also, on my laptops and desktop, I start it with my desktop environment, whereas my server doesn't have a GUI installed.  I'd like it to start up on boot, but running as my user.
 
These instructions are from the [https://docs.syncthing.net/users/autostart.html#linux Syncthing documentation] for autostarting on Linux.  I'm running this on Debian 10 on a single board computer (PC Engines Alix, an i386 board), but it should work on a Raspberry Pi as well.  In fact, with a Pi 3 or 4, it would probably run better.  I'm assuming you have it running and configured on one or more client machines as well.
 
Basically, I'm using a systemd unit file to start as a normal user.  There should be one with syncthing when you installed it; I found it in <code>/usr/lib/systemd/user/</code>.  Copy it to your home directory like this, where <code>user</code> is your username:
 
cp /usr/lib/systemd/user/syncthing.service /home/user/.config/systemd/user/
 
Next, as a normal user, run these commands to enable the service on boot and start it immediately:
 
systemctl enable syncthing@user.service
systemctl start syncthing@user.service

Revision as of 19:36, 12 September 2020

Syncthing is a tool written in Go to keep files synchronised between computers. It's decentralized, meaning instead of syncing to a server, your computers can find each other on the network and sync amongst themselves. While I don't use it outside of my home network, it can run over the internet as well - it uses relay and discovery severs, and can even traverse NAT.

Prior to Syncthing, I used NextCloud, which runs on a web server. I used this to keep some directories on several computers in my home network synchronized. It worked, and I actually still have an install I point my phone too (although Syncthing has an Android app as well). However, sometimes it would be slow, particularly with a lot of small files. The server also stores all of its files in its own directory, and depends on a database (I have used both MariaDB and SQLite), as opposed to Syncthing which is just its own executable.

One advantage of the central model NextCloud uses is that if you only have one of the computers you're syncing online, it can still keep the copy of the server up to date. While Syncthing can deal with conflicts (by renaming the conflicting files), it's nice to not have to have both machines on for them to sync in all cases. (Although again, Syncthing can sync the two if only the two of them are online; NextCloud would still need to talk to its server.) I had already had a machine running with an external hard drive as kind of a stopgap NAS, so I looked into how to get Syncthing going on this as well.

Syncthing on a Headless Server

Syncthing can run just fine on a headless machine, with a caveat - each user requires a running instance. (This is the case as far as I know, I don't know if a multiuser version is in the works at the moment.) Also, on my laptops and desktop, I start it with my desktop environment, whereas my server doesn't have a GUI installed. I'd like it to start up on boot, but running as my user.

These instructions are from the Syncthing documentation for autostarting on Linux. I'm running this on Debian 10 on a single board computer (PC Engines Alix, an i386 board), but it should work on a Raspberry Pi as well. In fact, with a Pi 3 or 4, it would probably run better. I'm assuming you have it running and configured on one or more client machines as well.

Basically, I'm using a systemd unit file to start as a normal user. There should be one with syncthing when you installed it; I found it in /usr/lib/systemd/user/. Copy it to your home directory like this, where user is your username:

cp /usr/lib/systemd/user/syncthing.service /home/user/.config/systemd/user/

Next, as a normal user, run these commands to enable the service on boot and start it immediately:

systemctl enable syncthing@user.service
systemctl start syncthing@user.service