I need to frequently duplicate one database on my MySQL server to a mirror database on the same MySQL server.
I am writing a bash script that makes a mirror of my web application (PHP/MySQL) on a separate subdomain. Users can use this mirror to try out all kinds of crazy things without affecting the production environment. The script is supposed to run automatically every night.
Duplicating the source code is easy. I just use rsync -a
to copy everything from the directory holding the production environment to the mirror directory and apply a patch to update a few configuration files. The problem is with duplicating the database, which has grown to nearly 3 GB in size.
When I use mysqldump live_db | mysql mirror_db
then it takes forever to duplicate the database. Also, during that time CPU usage peaks to 100% and my web application becomes unusably slow.
Database replication does not seem to be an option since I only have one MySQL server. Replication requires two servers.
What is the best way to duplicate the production database? It doesn't have to be fast, but it should not impact performance of the system too much. People should still be able to use my web application while the mirror script is running in the background.