Skip to content

Instantly share code, notes, and snippets.

@sjorge
Last active July 31, 2023 14:16
Show Gist options
  • Star 16 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sjorge/173e4b8e8ded86918eb1 to your computer and use it in GitHub Desktop.
Save sjorge/173e4b8e8ded86918eb1 to your computer and use it in GitHub Desktop.
using syncthing for backups

introduction

I wanted to replace rsync for my current host backups.

I had 2 hosts (1 laptop and 1 desktop) that would get there changes polled from a backup server. (polled = cronjob ran every hours) Ofcourse those boxes are not always on and a frenzy of cron mails happen every now and then.

I replaced everything with syncthing, they have clients available for linux, illumos, openbsd and mac. With the config below (client::folder master = yes, server::folder master = no) we prevent the server from accidentally overriding a file on the client. The client knows the server's IPv4 and/or IPv6 address so we do not need global or local discovery nor UPnP.

We leave the client's set to dynamic on the the server side to prevent the server from making connection unless the client says hello first. When the laptop is online but not in my LAN it won't see the server so it won't sync (what I want, although you could manually open up your firewall to allow this).

The server is more or less passive and only takes files the clients give to it.

configuration

server and client setup

backup_server:

  • disabled global discovery
  • disabled local discovery
  • disabled upnp
  • disabled start browser
  • bound to: tcp://ipv4:22000, tcp://[ipv6]:22000

client1:

  • disabled global discovery
  • disabled local discovery
  • disabled upnp
  • bound to: tcp://0.0.0.0:22000 (dynamic)

client2:

  • disabled global discovery
  • disabled local discovery
  • disabled upnp
  • bound to: tcp://0.0.0.0:22000 (dynamic)

adding the backup server to the client

  1. click 'add device' on client X's GUI
  2. device id: server's id
  3. device name: backup server
  4. address: tcp://server-ipv4:22000, tcp://[server-ipv6]:22000 (IMPOTANT, client will reach out to server)
  5. compression: off for LAN, all data for remote
  6. introducer: no

adding a directory to backup

  1. click 'add folder' on client X's GUI
  2. enter an ID: 'clientX-somedir'
  3. interval: 120 (or whatever you want)
  4. Folder Master: Yes (important, we configure this so we only sync from the client -> server)
  5. Pull Order: Alphabetical (seems to work best in case of conflicts)
  6. Share With Devices: 'backup server'

... now open the backup server's GUI and wait ...

  1. accept the new device

  2. ...

  3. address: dynamic (IMPORTANT)

  4. accept the new 'folder'

  5. check if ID: 'clientX-somedir'

  6. interval: 0 (don't rescan, backup server should NOT have changes)

  7. Folder Master: No (important, we configure this so we only sync from the client -> server)

  8. Pull Order: Alphabetical (seems to work best in case of conflicts)

  9. Share With Devices: 'clientX'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment