How to Easily Make a Database Backup | LinQhost

Creating a database backup

Before you make any changes to your web application, it is always a good idea to make a backup of your database first. If something goes wrong, you can easily go back to the original situation. Fortunately, making a database backup is quite easy, as long as you have the correct login details such as your username, password and the name of the database at hand.

Make a backup

Do you have a small database? Then you can make a backup (dump) via PHPMyAdmin. This works fine, but you will quickly run into limits with larger databases. That is why we recommend making a backup via the shell (SSH). Use the following command for this:

mysqldump -u <user> -h localhost -p <database> | gzip -9 > <filename>.sql.gz

This command makes a backup and compresses it to a .sql.gz file. This compressed file is much smaller than a normal backup, which saves disk space.

Points of attention:

  1. Always place backups outside the web root of your website.
  2. For large databases, it may take some time to back up.
  3. Make sure there is enough disk space available to store the backup.

Restore: Restoring from a backup

If you want to restore the backup, there are several ways to do this. In all cases, you have to be careful, because there are risks involved. We advise you to delete the existing database and then restore the backup with the following command:

zcat <filename>.sql.gz | mysql -u <user> -h localhost -p <database>

Restoring a database can take longer than making a backup. Sometimes it seems like nothing is happening, but patience is very important in this case!