MySQL --- Database backup and restore

1. The concept of database backup

Database backup is to copy data or log records from the SQL Server database or its transaction log to the corresponding device to create a data copy or transaction log copy. Data restoration is used to copy all the data and logs in the specified SQL Server backup to the specified database, and then apply the recorded changes to move the data forward in time to roll back all the things recorded in the backup. Designing a good backup and restoration strategy requires consideration of many factors, including backup content, backup plan, backup media, backup equipment, backup type, and recovery mode. In the SQL Server 2012 system, common backup types include full backup, differential backup, transaction log backup, file and file group backup.

The "recovery model" is a database attribute that controls how transactions are recorded, whether the transaction log requires or allows backups, and what types of restore operations can be used. There are three recovery models: simple recovery model, full recovery model and bulk-logged recovery model. Normally, the database uses the simple recovery model or the full recovery model.

① Simple recovery model: The database records most transactions, but not all transactions. After the database is backed up, the transaction log is automatically truncated, that is, the inactive transaction log is deleted. Therefore, transaction log backup is not supported, and it cannot be restored to the point in time when the failure occurred. It has a high security risk. It is recommended to use this mode only for databases that do not require high data security.

② Complete recovery model: The database completely records all transactions and keeps detailed logs of all transactions. Supports recovery to the point in time when the failure occurred. This mode can prevent data loss in the event of a failure to the maximum extent, and provides comprehensive protection for data security. It is recommended to use this recovery mode for databases that require high data security and reliability.

③ Bulk log recovery model: The database does not record all transactions in full and detailed, but only records the minimum of large-volume operations. Under normal circumstances, the recovery mode is used only before the large-capacity operation is to be performed, and the original recovery mode is set back after the large-capacity operation is completed.

2. Create a backup device

Use the SSMS tool to create a backup device

Use SQL to create a backup device

3. Complete backup and restore

Complete backup and restore using SSMS tool

4. Restore the database

Delete the database classDB, and then restore the database operation

Full backup and restore using SQL

Restore the database

5. Differential backup and restore database

Verification: delete the database, and then restore the database

Use SQL differential backup and restore

6. Transaction log backup and restore

Use SSMS tool transaction log backup and restore

Verification: delete the created database, use transaction log backup to restore the database

Use SQL mode transaction log backup and restore

7. Delete the backup device

Guess you like

Origin blog.csdn.net/C_huid/article/details/104031406