MySQL database copy/sync in less than 6 hours per table?
Linux - ServerThis forum is for the discussion of Linux Software used in a server related context.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
MySQL database copy/sync in less than 6 hours per table?
I've been trying to use Percona Toolkit's pt-table-sync tool to synchronize a test database against a production one, but it's just too damned slow.
A single, albeit-large table (880,000 rows) took over six hours to sync. I literally don't have the days that it would take to use this approach.
(It also routinely causes a slave to stop syncing with its master, when I use it as a source. But I have to do that, because it brings the production database to its knees.)
My original process consisted of doing a mysqldump on the host, splitting the file into per-table files (for restartability), then reloading the tables one at a time using a script, but (for various purely political reasons that need not be discussed here), the remote server no longer has sufficient disk-space to hold these dumps. However, when it worked, it did the complete job in a few hours.
So, I basically need a script that will do table-copies between databases. (Dropping and rebuilding the tables in the remote, please). And, let it be one that I do not have to write!
I'd like for it to be able to know that if the number-of-rows are the same already, the table should not be automatically copied.
What might you suggest?
Last edited by sundialsvcs; 10-25-2017 at 07:23 AM.
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195
Rep:
I don't have script for you but it seems very simple.
Assuming:
The "remote" server is your target
The local server is your source
You don't want to store the dumps on the remote
Then a few commands like this would produce your script:
Code:
tables="footable bartable baztable"
for table in $tables
do
mysqldump localdatabase $table > /tmp/${table}.sql
mysql -h remotehost remotedatabase < /tmp/${table}.sql
done
Untested code, consider it pseudo code.
900,000 records is nothing for MySQL, provided you don't have multi-megabytes of blobs. Imports of several GB and 9,000,000 record take a few minutes on a 1 CPU VPS for me.
If your tables contain relations to other tables be careful with the per-table copying.
I've been trying to use Percona Toolkit's pt-table-sync tool to synchronize a test database against a production one, but it's just too damned slow.
A single, albeit-large table (880,000 rows) took over six hours to sync. I literally don't have the days that it would take to use this approach. (It also routinely causes a slave to stop syncing with its master, when I use it as a source. But I have to do that, because it brings the production database to its knees.)
My original process consisted of doing a mysqldump on the host, splitting the file into per-table files (for restartability), then reloading the tables one at a time using a script, but (for various purely political reasons that need not be discussed here), the remote server no longer has sufficient disk-space to hold these dumps. However, when it worked, it did the complete job in a few hours.
So, I basically need a script that will do table-copies between databases. (Dropping and rebuilding the tables in the remote, please). And, let it be one that I do not have to write!
I'd like for it to be able to know that if the number-of-rows are the same already, the table should not be automatically copied. What might you suggest?
First, I'd go with what jlinkels suggested; I'm doing something similar with good results. I'm doing it to/from a hosted site, so the link isn't the greatest in the world, but I can dump a pretty good sized DB in a few minutes, and load speed is similarly good. Political issues are another story.
That said, if you want to know if the number of rows is the same, you could just do a fairly simple script, and do a "select max(RecordID)" (or whatever you have as your primary key/record ID/SOMETHING that increments), on both tables and compare them. If less, dump..if not, carry on.
I'm basically looking for a simple script – e.g. "if the number of records is the same, skip this table, and if the number of records has simply increased, copy the new ones."
I could write the damn thing, of course, but I'm a lazy sot.
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195
Rep:
Even a sample script requires testing and debugging so I am giving you the idea:
Code:
$remoterows=$(echo "SELECT COUNT(*) FROM $remotetable" | mysql -h remotehost -s -q remotedb)
$localrows=$(echo "SELECT COUNT(*) FROM $localtable" | mysql -h localhost -s -q localdb)
if [ $localrows -gt $remoterows ]
then
#do the tabledump & copy
fi
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.