1. Freebies
  2. Tutorial
  3. Dropbox Database Sync for Testing
Dropbox Database Sync for Testing
Tweet Like

Dropbox Database Sync for Testing

Database management is very important, but it's always presented a problem for developers using Dropbox with local files. That's why we've written a quick tutorial for setting up a Dropbox database sync for testing your websites locally.

Keeping computers in a local testing environment in sync can be a nightmare. Creating a Dropbox database sync is an ingenious, often overlooked approach to this daunting problem.

We will start off assuming your testing environment is already established. If you haven't gotten to that step yet, please refer to our MAMP tutorial. MAMP (much like LAMP or XAMP) is simply an acronym for Apache, MySQL, PHP and it's important to keep that in mind while we push forward. What we're looking to address in this tutorial is your MySQL database. More specifically - We will be creating a SQL database on Dropbox then tricking MAMP into using that (instead of the default /db folder).

Signup For Dropbox

Dropbox is an amazing tool, even if you're not a dev nerd. You can get started by setting up a free account at https://www.dropbox.com/, but put simply - Dropbox is online storage that is easily accessible through multiple devices. As long as your account is setup, we can move forward and create the Dropbox database sync that you will know be using.

Create your Dropbox Database

Open your Terminal application from the "Applications/Utilities/" folder. Make sure you're MAMP server is off, then we'll be doing the following tasks inside Terminal…

  1. Set your directory to Dropbox
  2. Move the current MAMP database to Dropbox
  3. Remove the old MAMP database folder
  4. Create a symbolic link in your MAMP folder to your Dropbox database folder

Each of those steps can be achieved with the corresponding Terminal commands below...

cd ~/Dropbox/
cp -r /Applications/MAMP/db MAMP_DATABASE
rm -rf /Applications/MAMP/db
ln -s ~/Dropbox/MAMP_DATABASE/db /Applications/MAMP/db 

As with everything in Terminal, be deliberate and take your time. Also note that the name "MAMP_DATABASE" is arbitrary. If you prefer a different name feel free, just make sure you use the exact same name in both lines (2nd & 4th) and adhere to the normal naming rules (alphanumeric and underscores). Once you've got everything setup, clear your browser cache, and start your MAMP application. I'd suggest making sure you click on your PHP admin tab at the top, since most errors will result in a missed connection there.

As long as everything is up and running, we can give one last sync, back everything up, and then add additional computers to the mix...

Sync Your Dropbox Files

MAMP Error ScreenshotThat's the easy part! Make sure your Dropbox server is off (you obviously don't want to sync while you're using a database) then start your Dropbox application. Since your SQL database is in your Dropbox folder, simply sync Dropbox, and you're good to go. The only issue's I've run into using this setup are the normal "conflicting" errors that you occasionally get with any syncing application (see image). As long as you only sync one computer at a time, this shouldn't be a problem. If you do see those errors, just make sure you delete the appropriate "conflicting" files, and you're good. Which brings me to the final step...

Adding Computers to your Dropbox Database sync setup

The Terminal commands we used earlier are useful in this situation, but we certainly don't want to just overwrite the existing Dropbox database - We want to use it. This can be achieved with the following steps…

  1. Set your directory to Dropbox
  2. Remove the old MAMP database folder
  3. Create a symbolic link in your MAMP folder to your Dropbox database folder

Each of those steps can be achieved with the corresponding Terminal commands below...

cd ~/Dropbox/
rm -rf /Applications/MAMP/db
ln -s ~/Dropbox/MAMP_DATABASE/db /Applications/MAMP/db 
Enjoy Your Cutting Edge Testing Environment

Dropbox Database Sync ScreenshotThat's it - Not as tricky as you thought right? If you do run into any issues (and if you're a newbie, you will) make sure you take a look at your error logs and the structure of your folders. One thing you can do to confirm that your Terminal commands were entered properly is to simply look at your Applications/MAMP folder. You should see the small folder icon with the arrow underneath (see image) where your db folder used to be. In your Dropbox folder you should see your new database folder, which in this example would be named MAMP_DATABASE. If anything looks wonky in these places, adjust your approach.

Now throw a stranger a high-five because you have an AWESOME tool for your testing environment. No more importing, exporting, and ending up with spare database backups everywhere… It's all in one place! We've got a few ways to expand on this concept (that we'll be posting soon), but as for a solid method of keeping your databases synced - this is a dead simple and rock solid approach. If you have any questions or ideas on how to build on this concept please leave them below and if you like this tutorial share it on your favorite social network… and congrats! Now go have fun.

Related Articles
  • 20+ Top Free Ghost Themes
  • 10 Responsive Frameworks You Need
  • Dropbox
  • MAMP Basics - Build a Local Environment
  • Mobile Editing Apps - iOS Code Editors
  • Optimizing Development Workflows
Written By:
Matthew Haeck
Raleigh, NC

Matthew Haeck is the lead designer and developer at Haeck Design. His educational background in both Graphic Design and Economics prepared him perfectly to operate the design firm which bares his name. When not working, Matthew enjoys curating his growing vinyl collection, hitting the beach, and supporting his beloved hometown of Raleigh, NC.