GNU Info

Info Node: (mysql.info)Backing up

(mysql.info)Backing up


Next: Moving Prev: Adding and removing Up: InnoDB
Enter node , (file) or (file)node

Backing up and recovering an InnoDB database
--------------------------------------------

The key to safe database management is taking regular backups.  To take
a 'binary' backup of your database you have to do the following:

   * Shut down your MySQL database and make sure it shuts down without
     errors.

   * Copy all your data files into a safe place.

   * Copy all your InnoDB log files to a safe place.

   * Copy your `my.cnf' configuration file(s) to a safe place.

   * Copy all the `.frm' files for your InnoDB tables into a safe place.

There is currently no on-line or incremental backup tool available for
InnoDB, though they are in the TODO list.

In addition to taking the binary backups described above, you should
also regularly take dumps of your tables with `mysqldump'. The reason
to this is that a binary file may be corrupted without you noticing it.
Dumped tables are stored into text files which are human-readable and
much simpler than database binary files. Seeing table corruption from
dumped files is easier, and since their format is simpler, the chance
for serious data corruption in them is smaller.

A good idea is to take the dumps at the same time you take a binary
backup of your database. You have to shut out all clients from your
database to get a consistent snapshot of all your tables into your
dumps. Then you can take the binary backup, and you will then have a
consistent snapshot of your database in two formats.

To be able to recover your InnoDB database to the present from the
binary backup described above, you have to run your MySQL database with
the general logging and log archiving of MySQL switched on. Here by the
general logging we mean the logging mechanism of the MySQL server which
is independent of InnoDB logs.

To recover from a crash of your MySQL server process, the only thing
you have to do is to restart it. InnoDB will automatically check the
logs and perform a roll-forward of the database to the present.  InnoDB
will automatically roll back uncommitted transactions which were
present at the time of the crash. During recovery, InnoDB will print
out something like the following:

     ~/mysqlm/sql > mysqld
     InnoDB: Database was not shut down normally.
     InnoDB: Starting recovery from log files...
     InnoDB: Starting log scan based on checkpoint at
     InnoDB: log sequence number 0 13674004
     InnoDB: Doing recovery: scanned up to log sequence number 0 13739520
     InnoDB: Doing recovery: scanned up to log sequence number 0 13805056
     InnoDB: Doing recovery: scanned up to log sequence number 0 13870592
     InnoDB: Doing recovery: scanned up to log sequence number 0 13936128
     ...
     InnoDB: Doing recovery: scanned up to log sequence number 0 20555264
     InnoDB: Doing recovery: scanned up to log sequence number 0 20620800
     InnoDB: Doing recovery: scanned up to log sequence number 0 20664692
     InnoDB: 1 uncommitted transaction(s) which must be rolled back
     InnoDB: Starting rollback of uncommitted transactions
     InnoDB: Rolling back trx no 16745
     InnoDB: Rolling back of trx no 16745 completed
     InnoDB: Rollback of uncommitted transactions completed
     InnoDB: Starting an apply batch of log records to the database...
     InnoDB: Apply batch completed
     InnoDB: Started
     mysqld: ready for connections

If your database gets corrupted or your disk fails, you have to do the
recovery from a backup. In the case of corruption, you should first
find a backup which is not corrupted. From a backup do the recovery
from the general log files of MySQL according to instructions in the
MySQL manual.

InnoDB checkpoints
Checkpoints

automatically generated by info2www version 1.2.2.9