Thursday, August 22, 2013

Raspberry Pi driven Dropbox alternative

As mentioned earlier I bought Raspberry Pi. After some struggles with the board shipping I finally got it almost one month after my order. Components work as expected. I went for official Debian image installation.

Lately there has been quite some publicity about privacy and security on the the public services hosting data. So I decided to minimize the Dropbox usage for file sync and go for locally hosted solution. It doesn't mean I'm out of dropbox, but rather I use it only for things I need to share outside my LAN.

My synchronization requirements

  • two way sync
  • non-interactive sync
  • sync over ssh/local dirs (as pi works with ssh as a server out of the box)
  • support for star topology - PC1..n (laptops) <-> Server (Raspberry Pi)
  • keep additional dependencies to be installed on Raspberry low
  • enable sync within LAN only (as I have quite some restricted internet connection with respect to data transfer quotas)
  • operating on demand, rather than instantly (I want to use pi for other things as well and it's performance is not too impressive)

Alternative synchronization programs

I checked briefly only following:
  • rsync
  • Unison
    • quite well known,
    • but not actively developed any more, still patches seem to be applied from time to time.
  • ownCloud
    • looks actively developed
    • but compared to other 2 - eats more resources (on both sides, client and server)
To me, the unison looks like a winner. So I went for it.

Unison setup from scratch on Pi

I followed these steps:
  1. [on server] changed default raspberry password via:
    passwd
    
  2. [on clients and the server] set up password-less authentication for ssh connection (following the howtoforge tutorial)
  3. [on clients and the server] installed unison:
    • For Fedora:
      sudo yum install unison
      
    • For (X)ubuntu/Debian:
      sudo apt-get install unison
      
  4. [on clients] setup unison with ssh as a synch protocol (following the howtoforge tutorial) with the custom unison preferences file (see next section for reference).
That was basically it.

Custom setup

I created new unison preferences file:
~/.unison/unison.prf 
that has following contents:
# WATCH OUT: keep in sync across clients!

# dirs
root = /home/pb/unison
root = ssh://pi@192.168.2.109//media/My Book/pi/unison

# Work silently
batch = true

auto=true
times = true

# logging
log = true
logfile = /home/pb/.unison/unison.log

# Prevent deletion of all files if all files are locally deleted
confirmbigdeletes = true

# Check fast, don’t compare bit by bit
fastcheck = true # "the default on Unix systems", see docs

# ignore stuff
ignore = Name *~   ## ignores all files with ~ (gedit backup files)
Then I went for one more step. To synchronize via command line I issue following command on my client machines:
unison -ui text unison
To make my life easier, I created in:
~/.bashrc 
alias:
alias u-u="unison -ui text unison"
So that I can simply initiate the synchronization with:
u-u
That's it for my setup. Please note the paths as well as server IP should be adapted in case you'd be using it.

More info/inspiration

For more information, that I got inspired with, see:

No comments: