Veeam Backup & Replication Best Practice Guide
MySQL Backup
This section describes how to protect MySQL database servers that run on Linux. It covers two Veeam integrations:
- Veeam Agent for Linux with native application-aware processing for MySQL or snapshot scripts.
- Veeam Backup & Replication VM-level backup of Linux VMs, using pre-freeze and post-thaw scripts.
Veeam Backup & Replication does not process MySQL natively in VM-level backup jobs. To get a consistent backup of MySQL in a VM, use scripts or database dumps as described in the Script-Based Options section below.
Backup Options
| Option | Applies to | How it works | Impact on the database |
|---|---|---|---|
| Application-aware processing | Veeam Agent for Linux | Veeam Agent locks MyISAM tables while it creates the snapshot. InnoDB tables do not require locking. Support for other storage engines depends on the version of Veeam Agent, so check the limitations. | Short lock on non-transactional tables only, no lock on InnoDB tables. |
| Hot backup: database online dump | Snapshot scripts | A pre-freeze script dumps the databases to a file before the snapshot. | Database stays online, dump adds load and disk usage. |
| Hot backup: database freeze | Snapshot scripts | A pre-freeze script blocks writes until the snapshot is created. | Writes blocked during the freeze. |
| Cold backup: database shutdown | Snapshot scripts | A pre-freeze script stops the MySQL service, a post-thaw script starts it. | Downtime during the snapshot. |
| Dump to a staging server or Application Backup Repository | Any backup job | Dumps are written to a staging server, which Veeam backs up. | No impact at backup time. |
Considerations for Selecting the Right Option
- Veeam Agent for Linux: start with application-aware processing if all requirements are met. It needs no scripts.
- VM-level backup: choose between the script-based options and a dump to a staging server.
- Dump: gives a logical copy, but adds load, space and time.
- Freeze: short write block, no extra space, relies on crash recovery.
- Cold backup: use it only if the downtime is acceptable.
- Large environments: MySQL is typically managed by database administrators (DBAs) who already run their own scripts to dump databases to file. This is still a valid approach. Veeam protects the dump files, and the DBAs keep control of the dump logic, credentials and retention.
Veeam Agent for Linux: Application-Aware Processing
If a computer protected with Veeam Agent for Linux runs a MySQL database system, you can enable Application-Aware Processing to create a consistent backup.
Requirements and Limitations
There are a number of limitations with this approach. Check the limitations before you use this option: Considerations and Limitations
Most important ones:
- The nosnap Veeam Agent for Linux does not support application-aware processing.
- Veeam locks only tables that use the MyISAM storage engine. Tables that use other storage engines are not processed.
- Veeam Agent does not support backing up MySQL transaction logs periodically. The recovery point is the time of the backup. If you need a more granular recovery point, coordinate with the DBAs.
Best Practices with Application-Aware Processing
- Use a dedicated MySQL account with minimum privileges, not
root. - Protect the password file on filesystem level.
- Choose “Require successful processing” if consistency is mandatory.
Using Scripts with Veeam Agent for Linux
Veeam Agent for Linux also supports custom scripts, which you can use for the script-based options described in the next section. Choose one approach per database server: either native application-aware processing or freeze and dump scripts.
Script-Based Options
The pre-freeze and post-thaw scripts prepare MySQL for the VM snapshot or Agent for Linux volume snapshot. The pre-freeze script brings the database to a consistent state before the snapshot is created. After the snapshot is created, the post-thaw script returns the database to its normal state (Pre-Freeze and Post-Thaw Scripts).
Example Scripts
Example scripts for all script-based options are available in the VeeamHub applications repository.
Important The example scripts have not been updated for some time. They might not work as expected with current versions of Linux distributions and MySQL. Review every script and test it in a lab before you use it in production.
Hot Backup: Database Online Dump
In this option, the pre-freeze script dumps all databases hosted on the server to a single file with the native mysqldump command. The dump runs before the snapshot is created. The post-thaw script deletes the dump after the snapshot is created.
| Script | VeeamHub Link |
|---|---|
| Pre-freeze | mysqldumppre.sh |
| Post-thaw | mysqldumppost.sh |
Consider the following:
- The dump is part of the backup. It increases the backup size and the amount of changed data.
- Make sure that enough space is available in the dump location.
- The dump reflects the state at the time of the pre-freeze script, not the time of the snapshot.
- Check the
mysqldumpoptions in the script. For example, the options define whether the dump blocks writes to InnoDB tables while it runs.
Hot Backup: Database Freeze
In this option, the pre-freeze script flushes the tables to disk and blocks writes with a global read lock. The post-thaw script releases the lock after the snapshot is created. The database is read-only in between.
| Script | VeeamHub Link |
|---|---|
| Pre-freeze | mysqlfreezepre.sh |
| Post-thaw | mysqlfreezepost.sh |
Tip The sample pre-freeze script waits up to 300 seconds to acquire the lock, and releases the lock automatically after this timeout (plus 10 seconds). Adjust the timeout if creating the snapshot takes longer.
Cold Backup: Database Shutdown
In this option, the pre-freeze script stops the MySQL service and the post-thaw script starts it again. The database is unavailable while the snapshot is created.
| Script | VeeamHub Link |
|---|---|
| Pre-freeze | mysqlstoppre.sh |
| Post-thaw | mysqlstoppost.sh |
The stop script calls init.d by default. Adapt the scripts to systemctl and your service name if your Linux distribution uses systemd.
Dump to a Staging Server
In this option, a database dump is written to a staging server, and the staging server is protected with a Veeam backup job. No pre-freeze or post-thaw script is needed on the database server.
Consider the following:
- Target: the dump target can be a dedicated VM, a file server or an NFS or SMB share that is protected by a Veeam backup job, e.g. Veeam Application Backup Repository.
- Schedule: the dump must be complete before the backup of the staging server starts. Schedule the jobs accordingly, or start the backup job after the dump with a script.
- Credentials: do not pass passwords on the command line. Use an options file with restricted permissions.
- Retention: define the retention of the dump files on the staging server and in the backup job.
- Security: dump files contain production data. Restrict access to them and use backup encryption.
- Monitoring: make sure that failed dumps are detected, so that the backup does not protect an empty or incomplete dump.
Restore
Restore the data with the standard Veeam restore options, for example entire VM restore, volume restore or file-level restore. After the restore, follow the standard MySQL recovery procedures:
- Application-aware processing and freeze: start MySQL and check the MySQL error log. For InnoDB tables, the backup is crash-consistent. After a restore, MySQL performs crash recovery when it starts.
- Online dump: if the restored database is not usable, restore the data from the dump file that is part of the restored VM.
- Dump to a staging server: restore the dump file from the staging server backup and import it into MySQL.
- Cold backup: MySQL was shut down cleanly, so just start the service.
Test restores regularly.
References
- Veeam Agent for Linux User Guide: MySQL Backup
- Veeam Agent for Linux User Guide: Preparing Password File for MySQL Processing
- Veeam Backup & Replication User Guide: Application-Aware Processing for Veeam Agent for Linux
- Veeam Backup & Replication User Guide: Backup of Database Systems (Considerations and Limitations)
- Veeam Backup & Replication User Guide: Backup Job and Snapshot Script Settings
- Veeam Backup & Replication User Guide: Pre-Freeze and Post-Thaw Scripts
- Veeam Backup & Replication User Guide: Pre-Freeze and Post-Thaw Scripts (Requirements and Limitations)
- MySQL scripts on VeeamHub
- Veeam Application Backup Repository