tags:

views:

2267

answers:

7

We have a live MySQL database that is 99% INSERTs, around 100 per second. We want to archive the data each day so that we can run queries on it without affecting the main, live database. In addition, once the archive is completed, we want to clear the live database.

What is the best way to do this without (if possible) locking INSERTs? We use INSERT DELAYED for the queries.

A: 

Could you keep two mirrored databases around? Write to one, keep the second as an archive. Switch every, say, 24 hours (or however long you deem appropriate). Into the database that was the archive, insert all of todays activity. Then the two databases should match. Use this as the new live db. Take the archived database and do whatever you want to it. You can backup/extract/read all you want now that its not being actively written to.

Its kind of like having mirrored raid where you can take one drive offline for backup, resync it, then take the other drive out for backup.

Doug T.
A: 

If you can't find a solution within MYSQL (I don't know anything about MySQL) and you are running on Windows, you may want to look into Hobocopy. It uses Window's Volume Shadow Service to take a consistent snapshot of the disk to allow backing up live files.
I use it to backup live Virtual Machines and I have found it works very well.

Darrel Miller
+4  A: 

http://www.maatkit.org/ has mk-archiver

archives or purges rows from a table to another table and/or a file. It is designed to efficiently “nibble” data in very small chunks without interfering with critical online transaction processing (OLTP) queries. It accomplishes this with a non-backtracking query plan that keeps its place in the table from query to query, so each subsequent query does very little work to find more archivable rows.

Another alternative is to simply create a new database table each day. MyIsam does have some advantages for this, since INSERTs to the end of the table don't generally block anyway, and there is a merge table type to being them all back together. A number of websites log the httpd traffic to tables like that.

With Mysql 5.1, there are also partition tables that can do much the same.

Alister Bulman
mk-archiver does exactly what I want!
DavidM
+2  A: 

MySQL replication would work perfectly for this.
Master -> the live server.
Slave -> a different server on the same network.

Seun Osewa
+1  A: 

Sounds like replication is the best solution for this. After the initial sync the slave gets updates via the Binary Log, thus not affecting the master DB at all.

More on replication.

Jacob
+1  A: 

I use mysql partition tables and I've achieve wonderful results in all aspects.

Eduardo Xavier
+1  A: 

MK-ARCHIVER is a elegant tool to archive MYSQL data.

http://www.maatkit.org/doc/mk-archiver.html