A while back I made some improvements to the backup scheme we use at KaiNexus. The requirements were pretty simple and straight forward. All our backups had to be encrypted, offsite and distributed. While there are a number of for-pay backup solutions out there we were looking for the bare minimum and free solution.
At the office, we all use Dropbox for file sharing so it seemed like a logical tool to use since we were all familiar with it. Dropbox lets us check off two requirements by being both off site and distributed. Here's my step-by-step guide on getting Dropbox setup on an Ubuntu server with minimal effort. I'm not covering the file encryption bit in this post but if you want to know how I did it let me know and I'll do a writup on it.
The steps outlined here were put together after reading through a couple of other guides. Feel free to read those guides if you want but you should be able to get everything you need from what I have below.
Install build-essentials and gcc
sudo apt-get install build-essential gcc
Download Python 2.5.5 (This seems to be the officially supported version)
wget http://www.python.org/ftp/python/2.5.5/Python-2.5.5.tgz
Extract
tar -xvzf Python-2.5.5.tgz
Compile and install
cd Python-2.5.5 ./configure --prefix=/usr/local/python2.5 make sudo make install sudo ln -s /usr/local/python2.5/bin/python /usr/bin/python2.5
Switch to root user
sudo -s
Create dropbox user and group and set the user's home to be /etc/dropbox
groupadd dropbox useradd -r -d /etc/dropbox -g dropbox -s /bin/false dropbox
Download the 64-bit Dropbox binary
wget -O /tmp/dropbox.tar.gz http://www.dropbox.com/download/?plat=lnx.x86_64
Create the dropbox user's home and set the ownership and permissions
mkdir -p /usr/local/dropbox /etc/dropbox chown dropbox.dropbox /etc/dropbox chmod 700 /etc/dropbox
Extract the dropbox binaries
tar xvzf /tmp/dropbox.tar.gz -C /usr/local/dropbox --strip 1
Remove the dropbox archive
rm /tmp/dropbox.tar.gz
Switch to the dropbox user
su -l dropbox -s /bin/bash
Set the user's permissions
umask 0027
Execute the dropbox daemon
/usr/local/dropbox/dropboxd
Terminate the dropbox daemon with ctrl+c
Log out of the dropbox user
exit
Create the control script
cat >> EOF | sed -e "s,%,$,g" >/etc/init.d/dropbox
### BEGIN INIT INFO
# Provides: dropbox
# Required-Start: $local_fs
# Required-Stop: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the dropbox service
# Description: starts dropbox using start-stop-daemon
### END INIT INFO
DROPBOX_USERS="dropbox"
DAEMON=/usr/local/dropbox/dropbox
unset DISPLAY
start() {
echo "Starting dropbox..."
for dbuser in %DROPBOX_USERS; do
HOMEDIR=%(getent passwd %dbuser | cut -d: -f6)
if [ -x %DAEMON ]; then
HOME="%HOMEDIR" start-stop-daemon -b -o -c %dbuser -S -u %dbuser -x %DAEMON
fi
done
}
stop() {
echo "Stopping dropbox..."
for dbuser in %DROPBOX_USERS; do
HOMEDIR=%(getent passwd %dbuser | cut -d: -f6)
if [ -x %DAEMON ]; then
start-stop-daemon -o -c %dbuser -K -u %dbuser -x %DAEMON
fi
done
}
status() {
for dbuser in %DROPBOX_USERS; do
dbpid=%(pgrep -u %dbuser dropbox)
if [ -z %dbpid ] ; then
echo "dropboxd for USER %dbuser: not running."
else
echo "dropboxd for USER %dbuser: running (pid %dbpid)"
fi
done
}
case "%1" in
start)
start
sleep 1
status
;;
stop)
stop
sleep 1
status
;;
restart|reload|force-reload)
stop
start
sleep 1
status
;;
status)
status
;;
*)
echo "Usage: /etc/init.d/dropbox {start|stop|reload|force-reload|restart|status}"
exit 1
esac
exit 0
EOF
Allow the control script to me executed and set it to autostart
chmod a+x /etc/init.d/dropbox update-rc.d dropbox defaults
Start dropbox
/etc/init.d/dropbox start
You should now have Dropbox running as a service on your server. All that's left is to create your cron jobs that run your backup scripts and have those backup files placed into the /etc/dropbox/Dropbox folder.