Mysql – Cannot overwrite file: /var/lib/thesql/ibdata1 when using Percona xtrabackup

backupMySQLpercona

I am receiving an error when I am trying to restore from a percona backup to my local mysql server.

Cannot overwrite file: /var/lib/mysql/ibdata1 at /usr/bin/innobackupex
line 2128.

sudo innobackupex --copy-back --force-non-empty-directories /home/fazlan/Desktop/2015-05-25_09-59-31/

I had also shut down the mysql service prior to executing this command using

sudo service mysql stop

How do I fix this error?

I am using Ubuntu 14.04.

Best Answer

You should be restoring to a completely empty folder - you need to remove all the content (files and folders) from the target folder before doing the restore. Xtrabackup contains the entire system, not just a particular database. As always, test the restore on your test environment before attempting on production! And remember to shut down MySQL before attempting the restore or cleaning the target folder...