Thursday, October 2, 2014

BTSync - an alternative to cloud storage

For a while now, I have been concerned about my reliance on cloud services such as dropbox, evernote, google drive and Spider Oak. I have an active account with all of these services and more and more I worry about the fact that I have given so much of my data to these companies. I don't necessarily believe that these corporations are necessarily doing anything particularly evil with my data and I also don't upload anything terribly sensitive to the cloud. But in any case, that's not to say that quite a bit of the data I do put on the cloud I would still prefer to keep out of the public domain. For this reason I have started to look an alternative service, BitTorrent Sync.

For those unfamiliar with this system, it is basically a service developped by the folks that invented torrenting where you use a similar bit torrent protocol to sync data between different machines. The beauty of this system lies on the fact that all this data is stored locally in all machines involved and all data transfer is done in an encrypted manner. Meaning that you are not giving your data to anyone else, it stays withing all the machines sharing this data, and that's it. Not only that, but much like bit torrents, it can download this data in a really efficient way using direct connections to all machines involved. Lastly, one of the major advantages of this service over dropbox and others is the fact that there is no storage limits beyond how much you can store on your hard drive. Now, that's not to say that there isn't a downside of using this service. The downside is the fact that at least two machines need to be online for the data to successfully sync, so people like me that turn off their computers when they are not being used can't keep files updated all the time. For this reason I have devised a solution, which is to use my ubuntu server as a torrent sync server. BT Sync by its nature has no server, all clients just share the data, however if I add my home server to the loop, it will be updated at all times when it is online, serving as my personal "cloud" storage in a way. In this post I will go through the process of getting my server setup.

To start, download the appropriate tar file from the official website, http://www.bittorrent.com/sync/download

 note that you need to download the file that correspond to your system, whether it is 32 or 64 bits. To find out what your machine is, type:

$ uname -a

if you see a i386 in the response you are using a 32 bit install, while anything showing x86_64 is likely a 64 bit install.

Once I downloaded the appripriate file, unpak it into a folder where you will keep your executable and configuration files. Note that this folder needs to separate from the folder you intend to share since apparently failing to do that will cause a lot of synching issues.

To unpack the tar ball type:

$ tar -xvzf bittorrent_sync_i386.tar.gz

of course, substitute the name of the tar ball if you are using a 64 bit system. Once that's done run the executable with

$ ./btsync

This should prompt  a message indicating even the process id for the BitTorrent Sync application in case you need to restart it. Setting up your shares on linux is done via a web GUI via the default port 8888. One issue I came across the first time I set up my BTSync was that since I'm using a headless server and connecting to it via SSH, I needed to use the web GUI and for some reason could not connect to it right away. Instead, I needed to configure my BTSync to listen to the 8888 port from all ips (0.0.0.0) instead of just 127.0.0.1. To accomplish this you need to type

$ ./btsync --webui.listen 0.0.0.0:8888

Now to use the web GUI, use your favorite browser from a machine that does have a graphical interface and type the your server's ip followed by the port number you selected, in our case port 8888. So if my internal ip is 192.168.0.70 (use ifconfig if you need to find this out), then use

http://192.168.0.70:8888

From there, click on the "add folder" icon and select the folder you would like to sync. Just remember to backup this folder before going further. It's unlikely you will screw up, but just for good measure, you should always back up your data before an action like this.

Once you have added the folders you want synced to your list, click on the "3 dots" icon at the end of the line where the folder is displayed and go to "preferences". There you should see a button to "View Key". Here you will have the opportunity to copy a key for sharing this folder as a "read only" folder, or as a read and write folder.

Install following the instructions once again on another machine you want to sync with your server and this time, instead of clicking on the add folder button use the cog button instead, where you should see the option to "Enter a key..." That's where you will enter the hashed number you saw previously. Find the folder you want to sync and voila.

That's it, it should work and will work over several different installs. One last detail, you may need to set up a cron job or some other way of initializing the btsync executable every time you turn your server online.

edit- One detail I forgot to mention, you will need your clocks to be synchronized for BTsync to work. In case you need instructions on how to do that on your linux machine, use the following link http://www.howtogeek.com/tips/how-to-sync-your-linux-server-time-with-network-time-servers-ntp/