Hackviking He killed Chuck Norris, he ruled dancing so he took up a new hobby…

8Mar/160

Raspberry Pi: BitTorrent Sync

BitTorrent is not only pirated movies and tv-shows it's an actual technology for moving large amounts of data between several nodes at once. There are several applications for this sync technology. Large companies like Facebook use it to sync new releases among all their production servers for example. If three or more nodes are syncing the same content it will increase the sync speed since it's a non centralized technology. All the clients will help to seed the data they already have which will make the sync go faster and faster the more nodes the data propagates to.

Btsync will make use off all the memory available in your Raspberry Pi so I recommend running this on it's own. I have tested this out on both a Raspberry Pi 2 B and the older Raspberry Pi B and they more or less run the same. It will take some time to index all your data but when testing it on a regular windows pc it was pretty slow as well.

Pre-requirements

Make a standard install of a Raspberry Pi, I recommend the light version for this application. Make sure you expand the file system and upgrade the Pi. Then we need to mount all the shares from the NAS. So create a root folder for the btsync files in the /mnt folder.

sudo mkdir /mnt/btsyncroot

Give write permissions to the mount folder, if you don't do this before mmounting you will end up with errors about write permissions when you add folders.

sudo chmod 777 /mnt/btsyncroot

Then let's edit /etc/fstab so run sudo nano /etc/fstab and add a line representing your share.

192.168.0.5:/nfs /mnt/btsyncroot nfs rsize=8192,wsize=8192,timeo=14,nolock,intr 0 0

It will map the root nfs share from the server 192.168.0.5, which is my WD Live DUO 6TB nas. For more information on how to format your fstab lines check out the official fstab documentation. This will give me the root for all the shares so I don't have to map every share individually but are able to access all of them as sub folders.

To test this out we can run sudo mount -a. Then reboot the system and check that the mount is persistent. If you have issues with the persistence and are running DHCP please see my Raspbian:fstab doesn't mount NFS on boot article for reference.

Installation

Now we can install the Btsync client. First we need to add the repository and repository key for btsync.

apt-key adv --keyserver keys.gnupg.net --recv-keys 6BF18B15
echo deb http://debian.yeasoft.net/btsync wheezy main contrib non-free | sudo tee --append /etc/apt/sources.list.d/btsync.list
echo deb-src http://debian.yeasoft.net/btsync wheezy main contrib non-free | sudo tee --append /etc/apt/sources.list.d/btsync.list

Then update the package lists and install BitTorrent Sync.

sudo apt-get update
sudo apt-get install btsync

This will end up in a "graphic" setup of btsync.

btsync_setup_1

Step 1: Start configure a default instance. The Pi can probably not take running several instances.

btsync_setup_2

Step 2: Configure what privileges the btsync instance will run under. Since I gave /mnt/btsyncroot rights to all users and mounting NAS shares that are public this will work just fine. If you have a different more locked down setup you have to address the privileges accordingly.

btsync_setup_3

Step 3: Same as step 2, default will be fine for my setup.

btsync_setup_4

Step 4: This will set the process prio level for the btsync daemon.

btsync_setup_5

Step 5: This Pi is running of DHCP so I bind to 0.0.0.0

btsync_setup_6

Step 6: The standard port 8888 for the web UI is fine.

btsync_setup_7

Step 7: If you want to publish the web UI publicly you should use SSL.

btsync_setup_8

Step 8: Select the root folder that btsync will browse for folders. Since I mounted my nfs shares in /mnt/btsyncroot I will select that.

Configuration

When the installation has finished we can browse to https://{ip}:8888. If you chose to go with the SSL option you will get a warning for the unverified certificate, just continue.

btsync_web_setup_1

1. Select a username and password to access this instance.

2. Agree to the terms of service and click Continue.

2. Agree to the terms of service and click Continue. You will be prompted to login with the username and password you selected.

3. Information about the 30 days trial of premium features will display, just click Continue.

3. Information about the 30 days trial of premium features will display, just click Continue.

4. If you following this guide you probably don't have an instance running already so select: "This is my first Sync 2.0 device".

4. If you following this guide you probably don't have an instance running already so select: "This is my first Sync 2.0 device".

5. Since version 2.0 all instances using the same identity will sync all folders automatically. This is however a premium feature and will stop working after 30 days unless you pay for it. So I will name this instance after it's geographical location.

5. Since version 2.0 all instances using the same identity will sync all folders automatically. This is however a premium feature and will stop working after 30 days unless you pay for it. So I will name this instance after it's geographical location.

Add folders and share

By now you should have ended up in the basic web interface. From here you can add new folders to share.

Basic BtSync Web UI

Basic BtSync Web UI

Just follow the tool tips that show up. Start by adding a folder, select one of the folders below your root. BtSync will now start indexing your files and consume all the Raspberry Pi's memory in the process, this is why I recommend that you run this on a separate Pi. Even if BtSync is still indexing you can still start sharing the folder with other instances. Just select the share link and a new window will show up.

btsync_share_dialog

Then just use the Copy link to get the code. You can then use that on any BitTorrent Sync client under Manual connection..., you will be able to select the target folder to link to. Between my two apartments I setup Read & Write since the data can be changed in both locations, for my backup Pi in the office I select Read Only just to retain a copy of my data.

Conclusion

When I first tried this out the performance for indexing was very bad. I actually ended up running this on a Odroid-C1 in the end. It indexes much faster then the Raspberry Pi. First I suspected it was the memory that was the problem but after installing nload on both my nas and the raspberry/odroid I realized that it actually reads the entire file during the indexing. The Odroid was pushing +200Mbit/s against my nas for the entire index. The Raspberry is not able to do that with it's 100Mbit nic so as long as you are running this with a separate storage device I recommend going for the singel board computer with the faster nic.

On both the Raspberry and the Odroid all the memory was consumed. I'm really interested to see if the performance increase if I run this on an Odroid, or similar, with more memory. I can also see a lot of CPU usage on both machines but the Odroid stays below 60% for most of the time. The web UI also seem more responsive then on the Raspberry Pi 2. So my recommendation to run this setup is on a Odroid, preferably one with more then 1GB of memory.

I have read a lot of discussions on forums about BtSync being to heavy these days and Syncthing being an alternative. I tested that as well and was disappointed! It's a much more immature product and doesn't feel as robust as BtSync. It consumed just as much system resources as BtSync, indexing was just as slow. So for now I will stay with BtSync, indexing might be slow but during it's initial index it still digs through 100Gb/hour more or less. The only thing I like more about Syncthing is that it's open source!

Comments (0) Trackbacks (4)

    Leave a Reply