Backup your server data to Dropbox

Though personal blogs are not that serious comparing to your account data in the bank, it still worths some backup. Linode does offer sophisticated official backup service starting from $5 per month, however if your website doesn’t have huge traffic and the database/webroot size reasonably, you can choose some free alternative approaches.
You’ve already known Dropbox,(If not, click here to register, which can bring both of us extra 250M quotas:)) the state-of-the-art file syncing service. Good news is that it can be running without GUI, which makes the backup on your server as easy as simply compressing and copying.

So let’s start.

Install Dropbox

Firstly, open Putty, ssh to your server, and install Dropbox.

$ cd ~
$ wget http://dl-web.dropbox.com/u/17/dropbox-lnx.x86-0.7.110.tar.gz
$ tar xzf dropbox-lnx.x86-0.7.110.tar.gz
$ .dropbox-dist/dropbox

Dropbox will spit out numerous messages informing you that you need to link your server to your Dropbox account.

This client is not linked to any account…
Please visit https://www.dropbox.com/cli_link?host_id=blahblahblahblahblah23445435365 to link this machine.

Copy and paste that link into a browser on your client machine. You will then have to log in to Dropbox’s website using your Dropbox account. It won’t be obvious at first that anything happened. If you review the “Events” tab on the website, however, you will see a message indicating that your server has been linked to your account. Now you can go back to the command line.

Kill the Dropbox process with Control-Z.

Now there should be a folder named ‘Dropbox’ sitting in your home.

mkdir /home/kymair/Dropbox/Linode

Creating a Service to Run at Boot

$ cd /etc/init.d
$ wget http://www.kymair.com/files/dropbox.txt
$ mv dropbox.txt dropbox
$ chmod +x /etc/init.d/dropbox
$ update-rc.d dropbox defaults

Create daily backup script

I’ve created a specific user within MySQL to perform the backup task. In order to export data, the user has to be granted ‘LOCK TABLES’ and global ‘SELECT’ privileges.

mkdir /root/scripts
vi daily_backup.sh

Paste the text below to create the script.

#!/bin/sh
echo "Exporting MySQL databases..."
mysqldump -S /tmp/mysql.sock -u admin -p12345678 --all-databases > mysql.sql
zip mysql.zip mysql.sql
rm mysql.sql

echo "Compressing htdocs..."
zip -r htdocs.zip /srv/htdocs
echo "Moving to Dropbox sync folder"
mv mysql.zip htdocs.zip /home/kymair/Dropbox/Linode/

At the end, add the script into cron jobs.

crontab -e

Add following line

0 3 * * * /root/scripts/daily_backup.sh > /dev/null &2>1

And don’t forget to start Dropbox daemon

service dropbox start

About Kymair

A simple guy living in Zhuhai, likes reading, not go out often.
This entry was posted in Hosting. Bookmark the permalink.

Leave a Reply

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

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>