Table of Contents

New Solutions – MySQL Cold Backup, Hot Backup & Warm Backup

MySQL Cold Backup, Hot Backup & Warm Backup

In database management, backup is an important part of maintaining data security and integrity. In the MySQL database, backups are mainly divided into three types: cold backup, hot backup and warm backup.

It is very important for database administrators to understand these three backup types, MySQL cold backup, hot backup and warm backup, and how to choose and implement an appropriate backup strategy based on the actual situation.

What is MySQL Cold Backup?

Cold backup is also a backup performed when the database is closed. Unlike warm backup, cold backup usually only backs up data files and does not include log files. Since no log files are involved, cold backups are generally faster than warm backups, but may also result in an increased risk of data loss.

To perform a cold backup, you can copy the data files to another location. This backup method can be completed in a shorter period of time, but it should be noted that since there is no log file support, you may not be able to fully restore the data if the data file is damaged or lost.

What is Hot Backup?

Hot backup is a backup performed while the database is running. This backup method can back up data without affecting the normal read and write operations of the database. Using a hot backup reduces the risk of data loss because it does not require shutting down the database to perform the backup. However, since data modification may still occur during the backup process, hot backup usually requires additional log files to ensure data consistency.

To perform a hot backup, you can use the physical copy tools provided by MySQL, such as mysqldump or mysqlhotcopy. These tools can copy data files and log files to another location while the database is running.

What is Warm Backup?

Warm backup is a backup performed when the database is closed, also known as cold backup. During this backup process, the database is shut down so no data modifications occur. This makes warm backup a relatively safe and reliable backup method. However, warm backups can cause service interruptions because the database needs to be shut down for the backup to take place.

To perform a warm backup, you can copy the entire database directory to another location. This backup method can ensure data integrity and consistency, but requires shutting down the database, which may affect service availability.

Why Choose Cold Backup and How to Operate It

Choosing cold backup is usually performed when the database has been shut down normally. The consistency and integrity of the data will not be affected during the backup process. A cold backup is a backup that takes place after the database is shut down, so no data modifications occur while the data is being backed up.

The advantages of cold backup include:

  • It is a very fast backup method (just copy files).
  • Easy to archive (just copy).
  • Easy to restore to a certain point in time (just copy the files back).
  • Can be combined with archiving methods to restore the “latest state” of the database.

It should be noted that cold backup must be performed when the database is closed. When the database is open, performing database file system backup is invalid.

After the database has been shut down normally, you can start to perform the following cold backup steps:

  1. Close the instance to be backed up normally.
  2. Back up the entire database to a directory.
  3. Start the database.

Why Choose Hot Backup and How to Operate It

In MySQL, hot backup is usually chosen when the database needs to remain up and running. Hot backup is simple to operate and can better maintain data consistency. When performing hot backup, MySQL will first copy the data files, and then modify the copied data files, so the consistency of the data can be guaranteed.

The steps for hot backup are as follows:

  1. Find the MySQL configuration file my.cnf.
  2. Open the my.cnf file and find the [mysqld] section.
  3. Add the following in the [mysqld] section:
    • log-bin=mysql-binbinlog_format=row
    • sync_binlog=0
    • binlog_cache_size=4M
    • max_binlog_cache_size=2M
    • max_binlog_size=100M
    • expire_logs_days=7
  4. Save and close the my.cnf file.
  5. Restart the MySQL service.
  6. Log in to the MySQL console and execute the following command:
    • mysql> FLUSH TABLES WITH READ LOCK;
    • mysql> SHOW MAIN STATUS;
    • mysql> SELECT * FROM information_schema.innodb_trx;
  7. After executing the above command, you can perform hot backup. You can use tools such as mysqldump for backup.
  8. After the backup is completed, the MySQL table needs to be unlocked. Execute the following command:
    • mysql> UNLOCK TABLES;

Why Choose Warm Backup and How to Operate It

The database needs to be kept running normally and data updated frequently. The backup system has been installed and configured to the same or similar system and network operating environment as the currently used system, and the application system business has been installed to back up data regularly.

The following are the steps for warm backup:

  1. Find the MySQL configuration file my.cnf.
  2. Open the my.cnf file and find the [mysqld] section.
  3. Add the following in the [mysqld] section:
    • log-bin=mysql-bin
    • binlog_format=row
    • sync_binlog=0
    • binlog_cache_size=4M
    • max_binlog_cache_size=2M
    • max_binlog_size=100M
    • expire_logs_days=7
  4. Save and close the my.cnf file.
  5. Restart the MySQL service.
  6. Log in to the MySQL console and execute the following command: flush tables with read lock.
  7. After executing the above command, you can perform warm backup. You can use tools such as mysqldump for backup.
  8. After the backup is completed, the MySQL table needs to be unlocked. Execute the following command: unlock tables.

Conclusion

Here are the three backup types, MySQL cold backup, hot backup and warm backup, and how to choose and implement an appropriate backup strategy. Choose an appropriate backup strategy based on your needs and environment. If you have high requirements on data integrity and consistency, or need to avoid service interruption, you can consider using hot backup or warm backup. If your tolerance for data loss is high or you need a quick backup, consider using a cold backup.

Regularly test and restore: Regularly test and restore your backups to verify their availability and integrity. This can help you detect and resolve problems in a timely manner, while also allowing you to quickly restore data in the event of a failure.