Skip to content

How to restore MySQL database backup

Daniel Speichert edited this page Apr 25, 2021 · 3 revisions

In case you need to restore your MySQL database from a backup, first identify which file you want to restore. Your backups are located in /var/lib/automysqlbackup/ directory, in a subdirectory named after the frequency of rotation (daily, weekly, monthly, etc). The file name includes date and time of the backup.

Note: if you restore a backup, you are restoring a full database. If you want to restore a single table (which may lead to database corruptions), you have to manually inspect the dump file. How to do it is not explained in this article.

For the purpose of this article, we assume the database we want to restore is called forgottenserver.

  1. First, you should take a backup of the existing state of database - just in case you want to go back.
    mysqldump forgottenserver > current-forgottenserver.sql

  2. Secondly, drop the database and create it again - this makes forgottenserver an empty database.
    mysql -e "drop database forgottenserver; create database forgottenserver;"

  3. Finally, restore the database from backup (change the path to point to the backup file you want to restore):
    gunzip -c /var/lib/automysqlbackup/daily/forgottenserver/forgottenserver_2015-12-20_00h50m.Sunday.sql.gz | mysql forgottenserver

You are done! Unless you see some errors, backup is now restored.

Clone this wiki locally