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!
    • Related Articles

    • Ibdata is eating up my disk space

      In a previous life, when I first started using MySQL, we only had MyISAM table space in MySQL. This was not ACID compliant, which meant it was very error prone with crashes and so on. Things changed when MySQL added the InnoDB storage engine. But ...
    • SSH Tips for Professionals

      SSH is one of the most used tools by us and by most developers. In this blog we share a number of tips that make SSH both more secure and efficient. These tips are not only applicable to our high performance web servers, but also to your own internal ...
    • Preventing simultaneous cron jobs with Flock

      Cronjobs are tasks that are executed periodically and can be set via the crontab command. It is an easy way to execute tasks automatically. The basic explanation of cronjobs can be found in an earlier blog post on our website. However, a cronjob can ...
    • Suppress SSH login notifications

      We regularly see that the so-called deploy services suffer from output that we generate when logging in via SSH (e.g. pre-login/motd). This output has the function to show the user important information, but in the case of automatic processes this is ...
    • Set up email Workspace (Google) and Office 365 (Microsoft)

      Since each control panel works slightly differently, we would like to show you how to correctly set up G Suite (Google) and Office 365 (Microsoft) email within the LinQhost Portal. General When you use any of the above services, you should take at ...