Creating an in-house Dropbox: Phase 1

Create a Central Repository

Create a folder on a large hard drive or raid your main computer/server

For example:

mkdir /meda/drobo/inhouseDropbox

On the repository machine install Unison

sudo apt-get install unison

On the local machine connect via SSH and test that the install went ok

ssh yourhostname unison -version

You should see something like, “unison version 2.27.57”.

Create a file in your repository directory:

test.txt

Install Unison on the Local Machine

For a Debian based system do:

sudo apt-get install unison

Make a folder in your home directory or wherever you want:

mkdir /home/nixtutor/inhouseDropbox

Then run Unison:

unison inhouseDropbox/ ssh://nixtutor//media/drobo/inhouseDropbox

Note the double slash after the hostname. This is used to indicate an absolute path

You will be greeted with a message saying that this is the first time it has detected changes go ahead and hit the space bar.

Press y to confirm the “conflict” and transfer the files. This should only happen the first time you setup a new directory.

Setup Unison

Create a inhouseDropbox.prf file and stick it in ‘/home/youruser/.unison’.

If should look something like:

root = /home/youruser/inhouseDropbox
root = ssh://youruser@yourhost//media/drobo/inhouseDropbox

force = newer
times = true
batch = true

Now we have automated preferences and just need to get rid of the password prompt for SSH. The most common method of this is making a key file.

Making a key

On the local machine do ssh-keygen. Then scp the .pub file and append it to ~/.ssh/authorized_keys file on the remote computer.

Automating it

Running Unison by hand doesn’t do us much good. Let’s make Cron run it every two minutes or so.

crontab -e

Then add the following line:

*/2 * * * * /usr/bin/unison inhouseDropbox > /dev/null

Then save the file.

To test it go ahead and drop another file in the folder and wait a few minutes. The changes should propagate to the central repository.

Troubleshooting

Use

tail -f /var/log/crond

To see if cron is running the job.

You can also append, >> /home/youruser/log.txt 2>&1 instead of > /dev/null to output all errors and regular messages to a log file in your home directory.