📜 ⬆️ ⬇️

Synchronization of MySQL databases using Dropbox service

On duty, I have to work a lot and in different places. At work, at home and on business trips, I have an obsession with my work. I work in a small web-studio and my tasks include layout of sites and designing GUI for intranet projects. I can not fail to mention the invaluable help of my faithful friends, their names iMac, Mac Pro and MacBook. In my work, I use a gentleman's set of a web maker in Mac OS X: Coda for editing HTML / JavaScript and MAMP for launching a local web server. But it will not be about installing and configuring the above products, but about how to make life easier for developers who have in their fleet two or more computers running Mac OS X.

Once upon a time, when multi-megabit Internet channels existed in an ordinary man in the street only in fantasy, we all were content with the simple way of transferring data from one computer to another - a flash drive or external hard drive. Over the past year, my flash keychain, who faithfully and faithfully served me for more than four years, peacefully rests on a bookshelf. It was replaced by a Dropbox account - the well-known service for storing and synchronizing data. A free 2GB account is enough for me to synchronize all the work projects between my workhorses.

If with synchronization of regular files, HTML-templates and scripts, most likely, none of you have any questions, then with the synchronization of MySQL databases, everything is not so simple. Not. I'm lying ..! In fact, everything is very simple! There are two (free) options:
  1. At the end of the working session, unload the dump of modified databases (of course in Dropbox) and then import the dump into MySQL on the next machine
  2. Fully store bases in Dropbox

It is not difficult to guess that the second option is ideal, and its implementation will take you no more than five minutes. So let's start:

First, find out where MySQL is running using MAMP to store its data. Run phpmyadmin and go to the "Variables" tab. In the list we find the variable datadir and its value. The variable indicates the location of the database files on disk. In my case - / Library / Application Support / appsolute / MAMP PRO / db / mysql /
')
1. Turn off the MySQL server, open the terminal and start to shamanize.
2. Create a folder to store the database MySQL:
mkdir -p ~/Dropbox/database
3. Go to the folder with the base directory (do not forget about escaping spaces)
cd /Library/Application\ Support/appsolute/MAMP\ PRO
4. On the computer with the current database, move the folder with the local copy of the MySQL database to the Dropbox storage. On all subsequent computers, this step is skipped.
mv db ~/Dropbox/database/db
5. Delete the folder with the local copy of the MySQL database:
rm -rf db
6. Create a symbolic link to the Dropbox repository
ln -s ~/Dropbox/database/db db
7. Everything is ready! Now you can run MySQL server.

Actions on the specified algorithm must be performed on all synchronized machines.

For correct synchronization, you must disable the mysql server at the end of the working session. This is due to the fact that running mysql locks files with which it works and synchronization of such files is impossible until they are unlocked. You can simplify the procedure for terminating a work session by creating a script in Automator .

I hope my little note will benefit you.

Source: https://habr.com/ru/post/78324/


All Articles