-
Notifications
You must be signed in to change notification settings - Fork 30
How to restore MySQL database backup
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.
-
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
-
Secondly, drop the database and create it again - this makes forgottenserver an empty database.
mysql -e "drop database forgottenserver; create database forgottenserver;"
-
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.
Powered by Spigu.net Team | Get OTS Hosting Service with support | Visit our Otland Thread