Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Let's say I backup a database like this:

mysqldump -u usrname -p pass dbname > dbbackup.sql 

Then I delete a pile of rows from dbname.

Then new rows are inserted into dbname. However, I decide I want to 'undelete' the rows I deleted. How can I restore the dbbackup without overwriting the new rows?

share|improve this question

2 Answers 2

If that is a feature you requrire it will take require a datatbase schema specifically designed to support that.

Just doing that on any random database is almost certainly going to result in a serious mess.

share|improve this answer

Best thing you can do is restore the backup to a new database, and then run queries (which will depend on the application(s) using the tables) to identify the rows you want and transfer this data across.

Remember to keep taking backups as you go through this process to limit possible data loss, and make sure the backups aren't overwriting each other as you go.

pt-table-sync could well be of help to you, but you'll need to read up on it thoroughly, specifically the parts about Bi-directional syncing. I haven't used it except to sync master/slave but from what I can see it could well work in your situation (if you restore your backup to another database).

http://www.percona.com/doc/percona-toolkit/2.0/pt-table-sync.html

Just remember, take backups before you do any step. Even the restore of the backup to another name. Nothing is going to ruin your day faster than restoring over the top of your current DB.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.