Nov 25, 2024 3 min read

Syncthing: A Complete Checklist for Self-Hosting Success

Syncthing: A Complete Checklist for Self-Hosting Success
Table of Contents

Syncthing is an open-source, peer-to-peer file synchronization application designed to replace proprietary sync and cloud services. By self-hosting Syncthing, you retain complete control over your data while ensuring secure and efficient file synchronization across devices. In this guide, we’ll cover installation, reverse proxy configuration, logging, backups, updates, and advanced features of Syncthing to help you deploy and manage it effectively in your environment.

Installing Syncthing

πŸ“¦ Docker/Docker Compose Setup

To deploy Syncthing using Docker, create a docker-compose.yml file to define the service and its settings. This setup enables easy container management and ensures persistent data storage.


version: '3.8'

services:

syncthing:

image: syncthing/syncthing:latest

container_name: syncthing

ports:

- "8384:8384" # Web UI

- "22000:22000/tcp" # Sync Protocol

- "21027:21027/udp" # Local Discovery

volumes:

- ./config:/var/syncthing/config

- ./sync:/var/syncthing/sync

environment:

- PUID=1000

- PGID=1000

restart: unless-stopped

Deploy Syncthing with the following commands:


docker-compose up -d

docker ps # Verify the container is running

πŸš€ Manual Installation

For a manual installation on a Linux-based server, use the official Syncthing binaries:


sudo apt update && sudo apt install -y curl tar

## Download Syncthing

curl -s https://syncthing.net/release-key.txt | sudo gpg --dearmor -o /usr/share/keyrings/syncthing-archive-keyring.gpg

echo "deb [signed-by=/usr/share/keyrings/syncthing-archive-keyring.gpg] https://apt.syncthing.net/ syncthing stable" | sudo tee /etc/apt/sources.list.d/syncthing.list

## Install Syncthing

sudo apt update && sudo apt install -y syncthing

## Start Syncthing

syncthing

Configuring Nginx as a Reverse Proxy

🌐 Nginx Configuration

Use Nginx to route external traffic to Syncthing for better access control and SSL termination. Create a new configuration file in /etc/nginx/sites-available/syncthing:


server {

listen 80;

server_name yourdomain.com;

location / {

proxy_pass http://localhost:8384;

proxy_set_header Host $host;

proxy_set_header X-Real-IP $remote_addr;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

}

}

Enable the site and reload Nginx:


sudo ln -s /etc/nginx/sites-available/syncthing /etc/nginx/sites-enabled/

sudo nginx -t

sudo systemctl reload nginx

πŸ”’ SSL/TLS Setup

Use Let's Encrypt to secure your Syncthing deployment:


sudo apt install -y certbot python3-certbot-nginx

sudo certbot --nginx -d yourdomain.com

sudo systemctl reload nginx

πŸ› οΈ Testing and Reloading Nginx

Verify the Nginx configuration and ensure Syncthing is accessible via https://yourdomain.com:


sudo nginx -t

sudo systemctl reload nginx

Logging and Debugging Syncthing

πŸ—ƒοΈ Enabling Debug Logs

Enable debug-level logging in Syncthing’s configuration file. Locate the config.xml (default path: ~/.config/syncthing/config.xml) and modify the <logLevel> parameter:


<logLevel>debug</logLevel>

πŸ“„ Viewing Logs

Access logs using Docker or directly from the file system:


## Docker logs

docker logs -f syncthing

## Manual Installation

journalctl -u syncthing -f

πŸ› οΈ Troubleshooting Common Issues

Check logs for common issues, such as connectivity errors or permission problems. For example:


grep "error" ~/.config/syncthing/syncthing.log

πŸ“€ Exporting Logs

Forward logs to an external ELK Stack for advanced analysis by using Filebeat:


sudo apt install filebeat

sudo nano /etc/filebeat/filebeat.yml

## Configure Syncthing log path and output destination

Backup and Restore

πŸ—‚οΈ File-Based Backups

Backup Syncthing’s configuration and synced files:


tar -czvf syncthing-backup.tar.gz ~/.config/syncthing ~/sync

πŸ”„ Database Backups

Syncthing stores metadata in index-v0.14.db. Backup it directly:


tar -czvf syncthing-db-backup.tar.gz ~/.config/syncthing/index-v0.14.db

πŸ“… Automated Backup Scripts

Set up a cron job to automate backups:


crontab -e

## Add the following line for daily backups at 2 AM

0 2 * * * tar -czvf ~/syncthing-backup-$(date +\%F).tar.gz ~/.config/syncthing ~/sync

Updating and Upgrading Syncthing

⬆️ Updating Docker Images

Pull and redeploy the latest Syncthing Docker image:


docker-compose pull

docker-compose down

docker-compose up -d

πŸ› οΈ Manual Updates

Manually update Syncthing and restart:


sudo apt update && sudo apt install --only-upgrade syncthing

sudo systemctl restart syncthing

πŸ” Checking for Updates

Check for updates from the Syncthing Web UI under Actions > About or run:


syncthing --version

Leveraging Syncthing’s Unique Features

πŸ”§ Enabling APIs

Syncthing provides a REST API for automation and integrations. Enable it in config.xml:


<gui enabled="true" tls="false">

<address>0.0.0.0:8384</address>

<apikey>your-api-key</apikey>

</gui>

Test the API with curl:


curl -X GET -H "X-API-Key: your-api-key" http://localhost:8384/rest/system/version

🌟 Advanced Configurations

Enhance Syncthing’s functionality by enabling advanced options, such as introducing folder-specific settings or tweaking bandwidth usage:


syncthing -option=folder -option=value

Wrapping Up

This guide provided an end-to-end walkthrough of deploying, configuring, and managing Syncthing. Whether you want to synchronize files securely, leverage APIs, or automate backups, Syncthing offers unparalleled flexibility for self-hosting. Start implementing the steps outlined here to unlock the full potential of Syncthing for your projects.

Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to Selfhosted Ninja.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.