Use BitTorrent Sync (btsync) to Back Up Debian 8 Server

BitTorrent Sync, aka btsync, is a very convenient tool for file sharing and syncing. In this tutorial, I will show you how to use BitTorrent Sync to back up Debian 8 server.

Install BitTorrent Sync on Debian 8 Server via Official Deb Repository

Open sources.list file with nano text editor or vi text editor in the terminal.

sudo nano /etc/apt/sources.list

Append the following APT line at the end of this file.

deb http://linux-packages.getsync.com/btsync/deb btsync non-free

Save and close this file.

In order for APT to authenticate packages from the above repository, we need to import BitTorrent Sync’s public key. First download the public key with wget.

wget http://linux-packages.getsync.com/btsync/key.asc

Import the key with apt-key.

sudo apt-key add key.asc

Now let’s update local package index and install BitTorrent Sync

sudo apt-get update

sudo apt-get install btsync

Once it’s installed, we can start it using systemctl.

sudo systemctl start btsync

Enable BitTorrent Sync to auto start when Debian 8 server is booted up.

sudo systemctl enable btsync

Check its status.

systemctl status btsync

Output:

● btsync.service - BitTorrent Sync service
  Loaded: loaded (/lib/systemd/system/btsync.service; enabled; vendor preset: e
  Active: active (running) since 六 2016-05-21 09:15:19 CST; 1min 26s ago
    Docs: http://help.getsync.com/
Main PID: 6406 (btsync)
  CGroup: /system.slice/btsync.service
  └─6406 /usr/bin/btsync --config /etc/btsync/config.json

5月 21 09:15:19 xenial systemd[1]: Starting BitTorrent Sync service...
5月 21 09:15:19 xenial systemd[1]: Started BitTorrent Sync service.

As you can see from the output, btsync service is successfully enabled and it’s running. By default, it’s running as btsync user.

Accessing the Web GUI

By default, btsync process only listens on 127.0.0.1:8888. So if you install BitTorrent Sync on Debian 8 server, you won’t be able to access the Web GUI from your computer. To be able to access the Web GUI from a remote connection, we can set up Nginx reverse proxy for btsync.

First install Nginx on Debian 8 server.

sudo apt-get install nginx

Start Nginx and enable auto start.

sudo systemctl start nginx

sudo systemctl enable nginx

Then create a server block config file under /etc/nginx/conf.d/. Your Nginx config files can also be located at /etc/nginx/site-avaiable/. I just like to use /etc/nginx/conf.d.

sudo nano /etc/nginx/conf.d/btsync.conf

Paste the following lines in the file. Replace sync.yourdomain.com with your real domain name. You should also point your domain name to the IP address of your Debian 8 server.

server {
  listen 80;
  server_name sync.yourdomain.com;

  access_log /var/log/nginx/sync.yourdomain.com.log;
  location / {
    proxy_pass http://127.0.0.1:8888;
  }
}

Save and close this file. Reload Nginx.

sudo systemctl reload nginx

Now in your browser’s address bar type your domain name and you should be able to access the Web GUI.

Secure the BitTorrent Sync Web GUI

Install a TLS/SSL Certificate

To obtain and install TLS/SSL certificate with Nginx on a Debian 8 server, check out the following tutorial.

Install Let’s Encrypt Free TLS/SSL Certificate with Nginx on Debian 8 Server

Once the certificate is obtained, Let’s configure Nginx TLS/SSL settings. Open /etc/nginx/conf.d/btsync.conf again.

sudo nano /etc/nginx/conf.d/btsync.conf

Change the content of this file to the following. Replace sync.yourdomain.com with your real domain name.

server {
  listen 80;
  server_name sync.yourdomain.com;
  return 301 https://sync.yourdomain.com$request_uri;
}
server {
  listen 443 ssl;
  server_name sync.yourdomain.com;

  ssl_protocols TLSv1.1 TLSv1.2;
  ssl_certificate /etc/letsencrypt/live/sync.yourdomain.com/fullchain.pem;
  ssl_certificate_key /etc/letsencrypt/live/sync.yourdomain.com/privkey.pem;

  access_log /var/log/nginx/sync.yourdomain.com.log;
  location / {
  proxy_pass http://127.0.0.1:8888;
  }
}

Save and close the file. Now start Nginx again.

sudo systemctl start nginx

Go to your BitTorrent Sync Web GUI again, you will find HTTP connection is automatically redirected to HTTPS secure connection.

Password Protect

By default, the above configuration allows anyone to access the Web management interface. We can set up a username and password by clicking the gear icon on the upper right corner, then click Preferences.

secure BitTorrent Sync Web GUI

Click the login tab and enter a username and password. Since this is a new account, you can leave Current password field blank.

bittorrent sync web.png

Use btsync to Back Up Debian 8 Server

To backup your Web root directory, click Add Folder link on the upper left corner, then select your Web root directory such as /var/www/html/ or /usr/share/nginx/html/.

debian 8 btsync

If the following error appears,

Don’t have permissions to write to the selected folder.

Then issue the following command to grant read, write and execute permissions of Web root directory to btsync user.

sudo apt-get install acl

sudo setfacl -R -m "u:btsync:rwx" /var/www/html

acl package provides getfacl and setfacl utility.

After that, share your link, key or QR code with another computer that also runs BitTorrent Sync.

debian 8 BitTorrent Sync

Open the Web management interface of another computer that also runs BitTorrent Sync. Then click the arrow on the upper left corner, select Enter or key or link.

use btsync to back up debian 8 server

Enter your key or link in the next window.

btsync debian 8

and specify the destination folder for receiving files.

btsync backup

Important !

Make sure the system time of the two computers are the same or your data could be lost. Check out the following post to see how to sync system time.

Set Time Zone and Synchronize System Clock to Your Time Zone in Linux

Rate this tutorial
[Total: 2 Average: 5]

Leave a Comment

  • Comments with links are moderated by admin before published.
  • Your email address will not be published.
  • Use <pre> ... </pre> HTML tag to quote the output from your terminal/console.
  • Please use the community (https://community.linuxbabe.com) for questions unrelated to this article.
  • I don't have time to answer every question. Making a donation would incentivize me to spend more time answering questions.

The maximum upload file size: 2 MB. You can upload: image. Links to YouTube, Facebook, Twitter and other services inserted in the comment text will be automatically embedded. Drop file here