在ubuntu server上安装dropbox服务

由于之前用的budgetvm的VPS在前两周出现了严重的不稳定问题,也导致网站几乎整整3天都处于访问不能的状态。
这导致虽然我设置了自动备份,但由于VPS无法启动,所以没办法获得最新的备份文件,总之很头疼。于是想到了用dropbox同步备份文件这一办法,下面进入正题。
1.下载
Dropbox for 32-bit Server:
wget -O dropbox.tar.gz “http://www.dropbox.com/download/?plat=lnx.x86”

Dropbox for 64-bit Server:
wget -O dropbox.tar.gz “http://www.dropbox.com/download/?plat=lnx.x86_64”

2.将下载好的文件解压缩:tar -zxvf dropbox.tar.gz

3.运行dropbox(假设文件被解压在~目录):~/.dropbox-dist/dropboxd

4.由于并未连接上任何dropbox账户,所以会弹出以下信息:
This client is not linked to any account…
Please visit https://www.dropbox.com/cli_link?hostid=XXXXXXXX to link this machine.
复制其中的链接,并用浏览器打开,然后输入想用来同步的账号。验证完成后,terminal会显示已经完成的提示:
Client successfully linked, Welcome!
现在可以使用ctrl+c关闭这个进程了,这时你会发现已经建立了“~/Dropbox”这个文件夹

5.下面是创建一个新的服务:sudo vim /etc/init.d/dropbox

#!/bin/sh
# dropbox service
# Replace with linux users you want to run Dropbox clients for
DROPBOX_USERS="YOUR_USER_NAME"
# Here is the path to the file "dropbox"
DAEMON=.dropbox-dist/dropbox
start() {
 echo "Starting dropbox..."
 for dbuser in $DROPBOX_USERS; do
 HOMEDIR=`getent passwd $dbuser | cut -d: -f6`
 if [ -x $HOMEDIR/$DAEMON ]; then
 HOME="$HOMEDIR" start-stop-daemon -b -o -c $dbuser -S -u $dbuser -x $HOMEDIR/$DAEMON
 fi
 done
}
stop() {
 echo "Stopping dropbox..."
 for dbuser in $DROPBOX_USERS; do
 HOMEDIR=`getent passwd $dbuser | cut -d: -f6`
 if [ -x $HOMEDIR/$DAEMON ]; then
 start-stop-daemon -o -c $dbuser -K -u $dbuser -x $HOMEDIR/$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
 ;;
 stop)
 stop
 ;;
 restart|reload|force-reload)
 stop
 start
 ;;
 status)
 status
 ;;
 *)
 echo "Usage: /etc/init.d/dropbox {start|stop|reload|force-reload|restart|status}"
 exit 1
 esac
exit 0

这个脚本假定dropbox的执行文件在运行用户的home内,编辑完成后需要给文件添加可执行权限:sudo chmod +x /etc/init.d/dropbox
然后使用updte-rc.d 命令将dropbox添加到启动服务列表:sudo update-rc.d dropbox defaults
好了现在可以使用 service dropbox start 启动dropbox的服务了

Ref:http://rbgeek.wordpress.com/2012/08/19/how-to-install-and-configure-dropbox-on-ubuntu-server-12-04-lts/

Leave a Reply

Your email address will not be published. Required fields are marked *