DEV Community

Harsh Mange
Harsh Mange

Posted on • Originally published at harshmange.hashnode.dev on

Understanding Incremental Backup: The Key to Efficient Database Backup and Recovery

There are three types of incremental backup approaches: differential, cumulative, and mixed. Here are detailed SQL commands and flags for each type of incremental backup:

  1. ## Differential incremental backup

A differential incremental backup backs up only the changes made to the database since the last full backup. Here's an example of how to perform a differential incremental backup using MySQL:

mysqldump -u username -p --databases database_name --where="update_time >= '2022-03-01'" > differential_backup.sql

Enter fullscreen mode Exit fullscreen mode

Explanation of the flags used:

  • -u username: Specifies the username to connect to the MySQL server.

  • -p: Prompts for the password of the MySQL user.

  • --databases database_name: Specifies the name of the database to backup.

  • --where="update_time >= '2022-03-01'": Specifies the condition to filter the rows that have been updated since the last full backup.

  1. ## Cumulative incremental backup

A cumulative incremental backup backs up the changes made since the last full backup, as well as the changes made since the last cumulative backup. Here's an example of how to perform a cumulative incremental backup using MySQL:

mysqldump -u username -p --databases database_name --where="update_time >= '2022-03-01'" --no-create-info --skip-triggers --skip-lock-tables --skip-add-locks > cumulative_backup.sql

Enter fullscreen mode Exit fullscreen mode

Explanation of the flags used:

  • -u username: Specifies the username to connect to the MySQL server.

  • -p: Prompts for the password of the MySQL user.

  • --databases database_name: Specifies the name of the database to backup.

  • --where="update_time >= '2022-03-01'": Specifies the condition to filter the rows that have been updated since the last full backup.

  • --no-create-info: Excludes the table creation statements from the backup.

  • --skip-triggers: Excludes the triggers from the backup.

  • --skip-lock-tables: Disables table locking during the backup process.

  • --skip-add-locks: Disables adding LOCK TABLES statements to the backup.

  1. ## Mixed incremental backup

A mixed incremental backup is a combination of differential and cumulative incremental backups. It backs up the changes made since the last full backup, as well as the changes made since the last differential backup. Here's an example of how to perform a mixed incremental backup using MySQL:

mysqldump -u username -p --databases database_name --where="update_time >= '2022-03-01'" --no-create-info --skip-triggers --skip-lock-tables --skip-add-locks --master-data=2 > mixed_backup.sql

Enter fullscreen mode Exit fullscreen mode

Explanation of the flags used:

  • -u username: Specifies the username to connect to the MySQL server.

  • -p: Prompts for the password of the MySQL user.

  • --databases database_name: Specifies the name of the database to backup.

  • --where="update_time >= '2022-03-01'": Specifies the condition to filter the rows that have been updated since the last full backup.

  • --no-create-info: Excludes the table creation statements from the backup.

  • --skip-triggers: Excludes the triggers from the backup.

  • --skip-lock-tables: Disables table locking during the backup process.

  • --skip-add-locks: Disables adding LOCK TABLES statements to the backup.

  • --master-data=2: Adds binary log coordinates to the backup, which are used during the restore process. (Read more about --master-data flag: https://harshmange.hashnode.dev/what-is-the-binary-log-coordinates-aka-master-data-flag-in-db)

It's important to note that the backup and restore process may differ depending on the database management system

Top comments (0)