Busy + Bittorrent Sync Tutorial

Posted by in Technology, Travel

Life in the last couple of months; I’ve been to 4 countries, started a new job, modified my server setup adding 3 more VPSs among many other things. This blog has been neglected for quite some time, it’s really difficult to find the time to write things during the week and weekends become busy because things can’t be done any other time.

One thing I have managed to do to that I’ve written about is setup BitTorrent Sync to keep configuration files synced between more than one server. The reason I have this setup primarily is to be able to create user accounts for my VPNs on one server and have them automatically synced to other servers. However I’m also using BT Sync to give my friends so web hosting, this allows them to update their site files by simply installing the BT Sync client on their computer and dropping files into the synced folder.

Installing and configuring BitTorrent Sync to sync config files between servers

BitTorrent Sync is a tool which is used to transfer files from one machine to another without requiring any type of cloud storage service.

In this tutorial you will need:

1. At least two servers
2. BitTorrent Sync

For this tutorial I will be using two 64bit Ubuntu VPSs, mileage may vary slightly depending on your platform of choice.

Step One:

Fire up your two servers (if they aren’t already running), once ready install the package you wish to sync config files for.

Step Two:

SSH to one of your servers and create a .btsync directory and change to it.

mkdir ~/.btsync && cd ~/.btsync

Download the BitTorrent Sync package for your platform from here: http://labs.bittorrent.com/experiments/sync.html (click ‘Download’), for me that would be Linux x64.

wget http://btsync.s3-website-us-east-1.amazonaws.com/btsync_x64.tar.gz

Un-tar the package to the newly created directory

tar -xvf btsync_x64.tar.gz

Create a BT Sync config file and open it with Nano

nano btsync.conf

Add the following to the config file making sure to set your own username and password at the relevant section of the file, it may also be useful to name the machine e.g. “device_name”: “Server 1”

  "device_name": "My Sync Device",
  "listening_port" : 0,                       // 0 - randomize port

/* storage_path dir contains auxilliary app files
   if no storage_path field: .sync dir created in the directory
   where binary is located.
   otherwise user-defined directory will be used
  "storage_path" : "/home/user/.sync",

// uncomment next line if you want to set location of pid file
// "pid_file" : "/var/run/btsync/btsync.pid",

  "check_for_updates" : true,
  "use_upnp" : true,                              // use UPnP for port mapping

/* limits in kB/s
   0 - no limit
  "download_limit" : 0,
  "upload_limit" : 0,

/* remove "listen" field to disable WebUI
   remove "login" and "password" fields to disable credentials check
  "webui" :
    "listen" : "",
    "login" : "admin",
    "password" : "password"

/* !!! if you set shared folders in config file WebUI will be DISABLED !!!
   shared directories specified in config file
   override the folders previously added from WebUI.
  "shared_folders" :
//  use --generate-secret in command line to create new secret
      "secret" : "MY_SECRET_1",                   // * required field
      "dir" : "/home/user/bittorrent/sync_test", // * required field

//  use relay server when direct connection fails
      "use_relay_server" : true,
      "use_tracker" : true,
      "use_dht" : false,
      "search_lan" : true,
//  enable sync trash to store files deleted on remote devices
      "use_sync_trash" : true,
//  specify hosts to attempt connection without additional search
      "known_hosts" :

// Advanced preferences can be added to config file.
// Info is available in BitTorrent Sync User Guide.


Create a startup script and open it with Nano

nano /etc/init.d/btsync

Add the following to the startup script, this has been adapted from Jack Minardi’s from here: http://jack.minardi.org/raspberry_pi/replace-dropbox-with-bittorrent-sync-and-a-raspberry-pi/, make sure you replace USERACCOUNT with the account you will be running the script from

#! /bin/sh
# /etc/init.d/btsync

# Carry out specific functions when asked to by the system
case "$1" in
    /USERACCOUNT/.btsync/btsync --config /USERACCOUNT/.btsync/btsync.conf
    killall btsync
    echo "Usage: /etc/init.d/btsync {start|stop}"
    exit 1

exit 0

Set the relevant permissions and add the init script

chmod 755 /etc/init.d/btsync
update-rc.d btsync defaults

Start BT Sync

service btsync start

You’ve now installed BT Sync and should be able to access it by browsing to your server’s IP address on port 8888 e.g.

Step Three:

Repeat Step Two on your other server(s)

Step Four:

Connect to BT Sync on one of your servers in your browser and click ‘Add Folder’

Click on the ‘Generate’ button for BT Sync to generate a secret and paste this secret to a text editor

Add the path to the box or click on the folders until you reach your desired conf folder

Click ‘Add’, this will index the directory and display it’s status to you on screen.

Step Five:

Connect to BT Sync on your other server(s) in your browser and click the ‘Add Folder’ button as you did before

Do NOT click ‘Generate’ this time but instead paste in the secret you generated on your first server

Select the folder that the config files reside in (as you did in step four)

Click ‘Add’, this will index the directory like it did before, but this time because you have another BT Sync instance with the same folder/secret combination they will start syncing with each other, you should be able to see the status on the screen.