We wanted to have our virtual servers backed up to Dropbox on a daily basis for real peace of mind.
To do this we will need to:
1. Sign up for Dropbox
2. Setup Dropbox on CentOS
3. Setup Virtualmin to Dropbox Folders
1. Sign up for Dropbox
** Please use my referral link to sign up to help me get some more space, this would be a great way to thank me!
Use this Dropbox referral link: http://db.tt/YT1fc4Rk
2. Setup Dropbox on CentOS
– Create a new user that you would like to run the dropbox as – in our case we create the user – backup
Log in to your server as user backup so you obtain a shell prompt, and change to your home directory.
cd ~
wget -O dropbox.tar.gz "http://www.dropbox.com/download/?plat=lnx.x86"
If you need the 64 bit version:
wget -O dropbox.tar.gz "http://www.dropbox.com/download/?plat=lnx.x86_64"
Sanity check to make sure we’re not going to clog our home directory.
tar -tzf dropbox.tar.gz
Extract
tar -xvzf dropbox.tar.gz
Run dropboxd
~/.dropbox-dist/dropboxd
You should see output like this:
This client is not linked to any account... Please visit https://www.dropbox.com/cli_link?host_id=7d44a557aa58f285f2da0x67334d02c1 to link this machine.
Copy and paste that link and open it in a browser – make sure that you dont stop the process.
After you have opened that link you should see the message in your shell change and say that your account has been linked.
dropboxd will create a ~/Dropbox folder and start synchronizing it after this step! Go to the URL given; you should see a success message at the top of your screen.
NOTE: If you want to change the account it is linked to, unlink it from the first account, then kill the running dropbox process, start it up again (with “~/.dropbox-dist/dropboxd &”) and obtain the new host_id with dbreadconfig.py . If you don’t restart the dropbox client, it will give the same host_id (which for some reason cause me to be unable to change the account it is linked to).
It is recommended to download the official Dropbox CLI to start the dropbox daemon (as an unprivileged user) and get its status.
mkdir -p ~/bin
wget -O ~/bin/dropbox.py "http://www.dropbox.com/download?dl=packages/dropbox.py"
chmod 755 ~/bin/dropbox.py
~/bin/dropbox.py help
If you get an – SyntaxError: invalid syntax error then you need to have python 2.6 installed.
You will need the EPEL repo to install python26. The package installs Python 2.6 in parallel to the distribution default version. This way YUM will not be effected by the newer version
yum install python26
After that you should be able the command as follows:
python2.6 ~/bin/dropbox.py help
You can use the Dropbox CLI for start,status, stop, exclude or many other things.
Exclude Usage
List usage: dropbox.py exclude list
Example ~/bin/dropbox.py exclude
Example ~/bin/dropbox.py exclude list
Add exclusion usage dropbox.py exclude add DIRECTORY
Example ~/bin/dropbox.py exclude add ~/Dropbox/MyExcludedFolder
Remove exclusion usage dropbox.py exclude remove DIRECTORY
Example ~/bin/dropbox.py exclude remove ~/Dropbox/MyReincludedFolder
See this page for more info: http://www.dropboxwiki.com/Using_Dropbox_CLI
Make sure that Dropbox is running – create some files and check on the Dropbox site that they are syncing and vice versa.
Use this command to see some information on what Dropbox is doing now:
python2.6 ~/bin/dropbox.py status
Now we need to make sure Dropbox starts on startup:
So lets create a startup script:
vim /etc/init.d/dropbox
And paste the following into that file:
# chkconfig: 345 85 15 # description: Startup script for dropbox daemon # # processname: dropboxd # pidfile: /var/run/dropbox.pid # # Source function library. . /etc/rc.d/init.d/functions DROPBOX_USERS="user1 user2" prog=dropboxd lockfile=${LOCKFILE-/var/lock/subsys/dropbox} RETVAL=0 start() { echo -n $"Starting $prog" for dbuser in $DROPBOX_USERS; do daemon --user $dbuser /bin/sh -c "/home/$dbuser/.dropbox-dist/dropboxd &" done RETVAL=$? echo [ $RETVAL = 0 ] && touch ${lockfile} return $RETVAL } status() { for dbuser in $DROPBOX_USERS; do dbpid=`pgrep -u $dbuser dropbox | grep -v grep` if [ -z $dbpid ] ; then echo "dropboxd for USER $dbuser: not running." else echo "dropboxd for USER $dbuser: running (pid $dbpid)" fi done } stop() { echo -n $"Stopping $prog" for dbuser in $DROPBOX_USERS; do killproc /home/$dbuser/.dropbox-dist/dropbox done RETVAL=$? echo [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile} } # See how we were called. case "$1" in start) start ;; status) status ;; stop) stop ;; restart) stop start ;; *) echo $"Usage: $prog {start|status|stop|restart}" RETVAL=3 esac exit $RETVAL
Make sure to replace user1
with the users that you want Dropbox to run as – backup in our case
Then run these commands:
chmod +x /etc/init.d/dropbox
/sbin/chkconfig --add dropbox
chmod 755 /etc/init.d/dropbox
So, at this point, you should have a working Dropbox installation on your CentOS server.
Make sure you can start and stop it and see the status – make sure that it can sync files to and from the server using the users account on the Dropbox website.
Once you are sure it is running well also make sure that you disable lan sync as you wont need this on a server:
To disable lan sync:
python2.6 ~/bin/dropbox.py lansync n
Now we are ready to move on to setting up the virtualmin backups to the Dropbox folder
3. Setup Virtualmin to Dropbox Folders
We created a folder under the users Dropbox folder where the downloads will go.
mkdir ~/Dropbox/server_backups/virtualmin
Then we have to setup a Virtualmin Backup Schedule to Backup our virtual servers every day.
Dropbox will then backup keep a 30 day backup/snapshots of these backups for us.
Play around with the settings that you would like but make sure that you backup to the users directory:
/home/backup/Dropbox/server_backups/virtualmin
**You will also need to make sure that the backup files have to correct permissions as root will be doing the backups and then the backup user will not be able to access the files
Add this command to the – Command to run after backup
chown -fR backupp:backup /home/backup/Dropbox
This command with chown the complete Dropbox folder to backup:backup after every backup.
Let me know if anything is unclear.
And please remember to use my Dropbox referral link: http://db.tt/YT1fc4Rk
Some more links:
http://www.dropboxwiki.com/Text_Based_Linux_Install
http://www.dropboxwiki.com/Using_Dropbox_CLI
http://riley.dutton.us/2010/06/05/database-backup-on-centos-using-dropbox.html
I was looking for a good solution to back up my virtualmin website to dropbox. While looking for a solution, i came across your blog. It is great to know a documented solution exists. Thanks for the detailed instructions. I will try it out.
I am glad you found my post about backing up virtualmin to dropbox. Let me know if you need any help setting it up. Peace.
Tnx, your guide worked like a charm.
Glad I could help you set up Dropbox on Virtualmin! Let me know if there is anything else I can help with!
thanks heaps for all the steps…
Glad I could help you set up Dropbox to Backup your CentOS Virtualmin server!
thanks for the help.
Glad I could help with your Dropbox Virtualmin needs!
thank's for information.
I am glad I could help you with your Dropbox installation! Let me know if you have any other Dropbox, Virtualmin or CentOS problems I can help with!