MySQL Backup Breaks a Table Every Time – Solutions

MySQLmysql-5.5mysqldump

I've a MySQL Server 5.1.58-1ubuntu1 installed on an Ubuntu 12.04 LTS.

Every night we do a backup of all the databases with this script:

rm -rf /var/backup/mysql/ *
for i in $(echo 'SHOW DATABASES;' | mysql -u root -p'password' |grep -v '^Database$'); do
mysqldump \
-u root -p'password' \
-Q -c -C --add-drop-table --add-locks --quick --lock-tables \
$i > /var/backup/mysql/$i.sql;
tar -cpzf /var/backup/mysql/$i.sql.tar.gz /var/backup/mysql/$i.sql;
rm -rf /var/backup/mysql/$i.sql
done;

Every time the backup is executed a particular MySQL table is broken (the MYD and MYI files are deleted, while the FRM remains).

We have many databases and tables, only this one is broken.

Any idea?

Best Answer

This might seem too obvious but:

rm -rf /var/backup/mysql/ *

Space between / and * means there's two seperate deletes. So you're deleting the contents of /var/back/mysql/ and the contents of *. i.e. Everything in the current location. Could that be doing it?