Tutorial: Comprehensive Guide to Full and Incremental MySQL Backups Using MySQL Enterprise Backup
Ensuring the safety of your database is a top priority for any organization. With MySQL Enterprise Backup, you can take consistent full and incremental backups to protect your data against unexpected failures. In this article, we will walk through creating backups and restoring them step-by-step.
By the end of this guide, you’ll have a clear understanding of:
Let’s dive in!
1. Taking a Full Backup
A full backup captures the entire database—all tables, logs, and configurations—at a specific point in time. This serves as the foundation for incremental backups.
Here’s how to create a full backup:
mysqlbackup \
--defaults-file=/etc/my.cnf \
--user=your_user \
--password='your_password' \
--port=3306 \
--backup-dir=/your/path/to/full_$(date +%Y-%m_%d_%H_%M_%S) \
backup
Explanation:
After running this command, a full backup will be stored in a directory named something like:
/your/path/to/full_2025-01_13_14_44_59/
2. Taking an Incremental Backup
An incremental backup captures only the changes made to the database since the last successful backup (full or incremental). This is efficient and saves storage space.
To create an incremental backup:
mysqlbackup \
--defaults-file=/etc/my.cnf \
--user=your_user \
--password='your_password' \
--port=3306 \
--incremental \
--incremental-base=history:last_backup \
--incremental-backup-dir=/your/path/to/incremental_$(date +%Y-%m_%d_%H_%M_%S) \
backup
Explanation:
Example output directory:
/your/path/to/incremental_2025-01_13_14_47_34/
3. Restoring Backups
Step 1: Stop the MySQL Server
Before restoring, the MySQL server must be stopped to prevent data corruption:
sudo systemctl stop mysqld
Step 2: Prepare the Data Directory
To restore the database, clear the MySQL data directory:
rm -rf /var/lib/mysql/*
Ensure proper permissions:
chown -R mysql:mysql /var/lib/mysql
Step 3: Apply Logs to the Full Backup
Before restoring, ensure the logs in the full backup are applied:
Recommended by LinkedIn
mysqlbackup \
--backup-dir=/mysql_backups/full/full_2025-01_13_14_44_59 \
apply-log
Step 4: Restore the Full Backup
Restore the full backup to the data directory:
mysqlbackup \
--backup-dir=/your/path/to/full_2025-01_13_14_44_59/ \
copy-back
Fix permissions for the restored files:
chown -R mysql:mysql /var/lib/mysql
Step 5: Apply Incremental Backups
Apply each incremental backup in sequence to the full backup directory:
First Incremental:
mysqlbackup \
--incremental-backup-dir=/your/path/to/incremental_2025-01_13_14_47_34 \
--backup-dir=/your/path/to//full_2025-01_13_14_44_59 \
apply-incremental-backup
Second Incremental:
mysqlbackup \
--incremental-backup-dir=/your/path/to/incremental_2025-01_13_14_49_12 \
--backup-dir=/your/path/to/full_2025-01_13_14_44_59 \
apply-incremental-backup
Third Incremental:
mysqlbackup \
--incremental-backup-dir=/your/path/to/incremental_2025-01_13_14_52_41 \
--backup-dir=/your/path/to/full_2025-01_13_14_44_59 \
apply-incremental-backup
Each incremental backup applies changes to the full backup, progressively updating it to the latest state.
Step 6: Fix Ownership and Start MySQL
Ensure proper permissions:
chown -R mysql:mysql /var/lib/mysql
Start the MySQL service:
systemctl start mysqld
Step 7: Verify the Restoration
Log into MySQL and verify the databases:
mysql -u your_user -p
SHOW DATABASES;
4. Best Practices
Final Thoughts
With this step-by-step guide, you’re now equipped to handle full and incremental backups using MySQL Enterprise Backup. Whether you're protecting against data loss or preparing for disaster recovery, a robust backup strategy is essential.
Start implementing these practices today and ensure your data is always secure! Enjoy reading and Let me know your thoughts or experiences with MySQL backups in the comments below.
Contact me