20141217 syncthing for windows linux and bsd - plembo/onemoretech GitHub Wiki

title: syncthing for windows, linux and bsd link: https://onemoretech.wordpress.com/2014/12/17/syncthing-for-windows-linux-and-bsd/ author: phil2nc description: post_id: 9053 created: 2014/12/17 23:29:36 created_gmt: 2014/12/18 04:29:36 comment_status: closed post_name: syncthing-for-windows-linux-and-bsd status: publish post_type: post

syncthing for windows, linux and bsd

Recently lost another hard disk on one of the Windows machines and decided it was time to implement a automated backup solution. What I settled on was a combination of Syncthing and AWS S3, brokered through the house FreeBSD file server. Setting up Syncthing itself wasn't too difficult. The executable as an archived binary for Windows and Linux. I used the port on FreeBSD. Configuration is through a web interface on first launch. Each platform had a slightly different automated start up solution. For FreeBSD a simple init script, for Linux a systemd script and on Windows a neat (but sparsely documented) little program called Syncthing Tray for Windows. For the FreeBSD and Linux boxes I set up the web interfaces so they could be reached remotely, complete with a username and password. All that took was entering the system's host name in place of the loopback adapter IP address. On all 3 platforms I also reset the web listening port to 8083 and turned on TLS encryption. I also unchecked the option to automatically launch the web browser on all of the Windows machines. In order to sync folders from one machine to another the device (host) names were set to their DNS FDQN's and each shared folder was given a unique ID that matched that of the corresponding folder on the other host. So, for example, "alpha-phil-documents" on the alpha.example.com Windows machine was mapped to "D:\Users\phil\Documents" on that machine, corresponding to /data/backup/alpha/phil/Documents on the FreeBSD file server. On each machine being backed up these folders were also marked as the "master" to prevent any changes on the backup host from corrupting the data. For hosts that were not on the file server's subnet I made sure the server's IP address was included in its device configuration there. Syncthing Tray was configured to point to the Syncthing binary (in my case "D:\apps\syncthing\syncthing.exe"), and a symlink to it put in the user's Startup folder. Here are my init scripts for FreeBSD and Fedora 21 Linux. First for FreeBSD (from the port): [code lang="bash" gutter="false"] #!/bin/sh # $FreeBSD: head/net/syncthing/files/syncthing.in 373700 2014-12-01 03:42:08Z swills $ # # PROVIDE: syncthing # REQUIRE: LOGIN # KEYWORD: shutdown # # Add the following lines to /etc/rc.conf.local or /etc/rc.conf # to enable this service: # # syncthing_enable (bool): Set to NO by default. # Set it to YES to enable syncthing. # syncthing_user (user): Set user to run syncthing. # Default is "syncthing". # syncthing_group (group): Set group to run syncthing. # Default is "syncthing". # syncthing_dir (dir): Set dir to run syncthing in. # Default is "/var/tmp/syncthing". . /etc/rc.subr name=syncthing rcvar=syncthing_enable load_rc_config $name : ${syncthing_enable:="NO"} # : ${syncthing_user:="syncthing"} : ${syncthing_user:="root"} # : ${syncthing_group:="syncthing"} : ${syncthing_group:="wheel"} : ${syncthing_dir:="/var/db/syncthing"} pidfile=/var/run/syncthing.pid procname="/usr/local/bin/syncthing" command="/usr/sbin/daemon" command_args="-f -p ${pidfile} ${procname} -home=${syncthing_dir} -no-browser ${syncthing_args}" start_precmd=syncthing_startprecmd syncthing_startprecmd() { if [ ! -e ${pidfile} ]; then install -o ${syncthing_user} -g ${syncthing_group} /dev/null ${pidfile}; fi if [ ! -d ${syncthing_dir} ]; then install -d -o ${syncthing_user} -g ${syncthing_group} ${syncthing_dir} fi } run_rc_command "$1" [/code] In addition to this script the following line was added to /etc/rc.conf:

syncthing_enable="YES"

Next for Fedora 21: [code lang="bash" gutter="false"] [Unit] Description=Syncthing for %i [Service] Type=simple User=%i ExecStart=/usr/local/bin/syncthing WorkingDirectory=%h [Install] WantedBy=multi-user.target [/code] Once the service is run for the first time using "systemctl start syncthing@phil" (giving the user who owns the folders to be backed up), a "systemctl enable syncthing@phil" will ensure it starts after reboot. Once on the file server the synched files are mirrored to a secondary drive and then every couple of days sent over to AWS S3 using the s3cmd diff command.

Copyright 2004-2019 Phil Lembo