• Skip to main content
  • Skip to primary sidebar

Technical Notes Of
Ehi Kioya

Technical Notes Of Ehi Kioya

  • About
  • Contact
MENUMENU
  • Blog Home
  • AWS, Azure, Cloud
  • Backend (Server-Side)
  • Frontend (Client-Side)
  • SharePoint
  • Tools & Resources
    • CM/IN Ruler
    • URL Decoder
    • Text Hasher
    • Word Count
    • IP Lookup
  • Linux & Servers
  • Zero Code Tech
  • WordPress
  • Musings
  • More
    Categories
    • Cloud
    • Server-Side
    • Front-End
    • SharePoint
    • Tools
    • Linux
    • Zero Code
    • WordPress
    • Musings
Home » Dropbox » Backup Website/Folders With Dropbox On Ubuntu Server

Backup Website/Folders With Dropbox On Ubuntu Server

By Ehi Kioya 3 Comments

I like to automate things! There’s this great feeling you get when you set things up to run without manual intervention. It just makes you feel “powerful”. I have scripts and code pieces to backup stuff like Microsoft SQL Server Databases (see my post on Backing up SQL Server to Dropbox), MySQL Databases, entire cloud machines, entire websites, and/or selected folder(s) within a directory.

Dropbox is a file hosting service that offers cloud storage, file synchronization, and client software. In brief, Dropbox allows users to create a special folder on each of their computers, which Dropbox then synchronizes so that it appears to be the same folder (with the same contents) regardless of the computer it is viewed on.

Dropbox is currently the best free cloud storage service. It is extremely easy-to-use and even allows for data syncing to devices like smartphones and tablets.

Let us explore how the power and flexibility of Dropbox can be enjoyed for website administrators. This tutorial will show you how to:

  1. Install and configure Dropbox on your server. I will demonstrate this using Ubuntu Server 12.04
  2. Set your website folder (usually /var/www) as the synced folder on the server. The same principles will apply if your website lives on a different folder.
  3. Simplify your server using Dropbox selective sync.

Install and configure Dropbox on Ubuntu Server 12.04

Step 1: Go into your local Dropbox folder and create a folder called “Server” or whatever you prefer. But if it’s different you’ll need to remember that later.

Step 2: Get a command line session with your server via SSH. Then use this command to check if you are on 32 or 64 bit.

uname -m

If it says x86_64 then download the 32-bit version from the official website:

wget -O dropbox.tar.gz "http://www.dropbox.com/download/?plat=lnx.x86"

If it says i686 then download the 64-bit version from the official website:

wget -O dropbox.tar.gz "http://www.dropbox.com/download/?plat=lnx.x86_64"

Step 3: Extract the archive just downloaded with the command below:

tar -zxvf dropbox.tar.gz

Step 4: Run the Dropbox client daemon with this command:

~/.dropbox-dist/dropboxd

Since your server has not been linked to any Dropbox account yet, the daemon will keep displaying a notification message every few seconds.

The message will be something like this:

Dropbox daemon

Copy and paste the link in the message to a web browser using any computer. This will start the process of linking your Ubuntu Server to your Dropbox account. You will be asked to authenticate with your username and password. If the authentication is successful, you will see the message “Client successfully linked, Welcome!”. And the notification message containing the authorization link will stop printing. The daemon will also automatically create a Dropbox folder in the home directory of the current logged in user. Press CTRL+C to terminate the Dropbox deamon process.

Step 5: Create a script for service management functions like starting and stopping Dropbox. We will name the script “dropbox”. Use the following commands:

sudo touch /etc/init.d/dropbox
sudo nano /etc/init.d/dropbox

Copy the following text into the script file just created:

#!/bin/sh
# dropbox service
# Replace with linux users you want to run Dropbox clients for
DROPBOX_USERS="user1 user2"

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

You could also grab the above script from github here.

Now edit the script and replace “user1 user2” with an Ubuntu Server username (not your Dropbox account username).

Make the script executable and enable Dropbox to start up automatically on boot using the following 2 commands:

sudo chmod +x /etc/init.d/dropbox
sudo update-rc.d dropbox defaults

Now, you can easily control the Dropbox client like any other Ubuntu service (if Dropbox hasn’t started, start it):

sudo service dropbox start|stop|reload|force-reload|restart|status

How to Check The Dropbox Status with a Python Script

Step 6: Download the dropbox.py script and make the file excutable using the following 2 commands:

wget -O ~/.dropbox/dropbox.py "http://www.dropbox.com/download?dl=packages/dropbox.py"
chmod +x ~/.dropbox/dropbox.py

Now you can easily check the status of the Dropbox client with following command:

~/.dropbox/dropbox.py status

Statuses could be “Idle” or “Uploading” etc.

To get more help for dropbox.py use the following command:

~/.dropbox/dropbox.py help

Set Your Website Folder as a Synced Folder in Dropbox

Step 7: In Step 1 above, you created a folder called Server within your Dropbox folder. Let’s assume that you want this folder to act as your www root folder. Edit /etc/apache2/sites-available/default and replace /var/www/ with /home//Dropbox/Server. Make sure that files inside the “Server” folder are readable by www-data user.

If you prefer to add /var/www/ to your Dropbox, and keep it synced, create a symlink inside ~/Dropbox/ to point to /var/www using this command:

cd ~/Dropbox
ln -s /var/www www

You might want to chown the www folder so as to add files to it without using root.

Simplify Your Server Using Dropbox Selective Sync

Right now Dropbox is syncing all the folders in your Dropbox account to your Ubuntu Server. For me that’s not good so let’s pare it down using selective sync.

Step 8: You will need to call the ‘exclude add’ command for each top level folder you don’t want to sync. If you only just installed Dropbox, I’d suggest starting by excluding your biggest folder to save Dropbox and your server some work. If you want to sync only the “Server” folder we created earlier, proceed like this (assuming the dropbox.py script was stored in your home directory… I however, recommend keeping scripts like this in a “utils” folder):

cd ~/Dropbox
~/dropbox.py ls
-> Photos  Projects  Public  Server  Work

~/dropbox.py exclude add Projects
~/dropbox.py exclude add Photos
~/dropbox.py exclude add Public
~/dropbox.py exclude add Work
~/dropbox.py ls
-> Server

There you go… the only synced folder is now the “Server” folder.

Found this article valuable? Want to show your appreciation? Here are some options:

  1. Spread the word! Use these buttons to share this link on your favorite social media sites.
  2. Help me share this on . . .

    • Facebook
    • Twitter
    • LinkedIn
    • Reddit
    • Tumblr
    • Pinterest
    • Pocket
    • Telegram
    • WhatsApp
    • Skype
  3. Sign up to join my audience and receive email notifications when I publish new content.
  4. Contribute by adding a comment using the comments section below.
  5. Follow me on Twitter, LinkedIn, and Facebook.

Related

Filed Under: Dropbox, Linux & Servers Tagged With: Dropbox, Linux

About Ehi Kioya

I am a Toronto-based Software Engineer. I run this website as part hobby and part business.

To share your thoughts or get help with any of my posts, please drop a comment at the appropriate link.

You can contact me using the form on this page. I'm also on Twitter, LinkedIn, and Facebook.

Reader Interactions

Comments

  1. Stanley says

    October 9, 2016 at 2:45 pm

    Excellent post!

    When I visit https://raw.github.com//gist/2347727/108fc8af551cb4fdf7cdd08b891a45f405d283dc/dropbox I get a 404

    WIll this also work for centos 7?

    Reply
    • Ehi Kioya says

      October 10, 2016 at 1:04 pm

      Hi Stanley,

      Since the github link seems to have died, just copy and paste the script I provided. That was actually the reason I posted the code on here (in case the link dies or something).

      As for CentOS 7, I believe the code will work as well. However, I haven’t tried yet.

      Thanks.

      Reply
  2. Santi says

    May 22, 2017 at 9:47 am

    Note you have the definitions switched on top: “If it says x86_64 then download the 32-bit version…” Feel free to correct and delete my comment.

    Reply

Leave a Reply Cancel reply

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

Primary Sidebar

23,570
Followers
Follow
30,000
Connections
Connect
14,568
Page Fans
Like
  • Recently   Popular   Posts   &   Pages
  • Actual Size Online Ruler Actual Size Online Ruler
    I created this page to measure your screen resolution and produce an online ruler of actual size. It's powered with JavaScript and HTML5.
  • Fix For “Function create_function() is deprecated” In PHP 7.2 Fix For "Function create_function() is deprecated" In PHP 7.2
    As of PHP 7.2 create_function() has been deprecated because it uses eval(). You should replace it with an anonymous function instead.
  • How To Change A SharePoint List Or Library URL How To Change A SharePoint List Or Library URL
    All versions of the SharePoint user interface provide an option to change the title (or display name) of a list or library. Changing SharePoint library URL (or internal name), however, is not exactly very intuitive. We will discuss the process in this article.
  • About
  • Contact

© 2022   ·   Ehi Kioya   ·   All Rights Reserved
Privacy Policy