
Automated MySQL Backups with automysqlbackup
Learn how to set up automated MySQL database backups using the powerful automysqlbackup tool
Database backups are a critical part of any system administration strategy. When it comes to MySQL databases, one of the most reliable and feature-rich backup solutions is the automysqlbackup
tool. This article will guide you through setting up and configuring this powerful backup solution.
Why automysqlbackup?
automysqlbackup
stands out for several reasons:
- Automatic rotation: Creates daily, weekly, and monthly backups with automatic rotation
- Compression: Automatically compresses backup files to save space
- Email notifications: Can be configured to send email notifications about backup status
- Flexible configuration: Highly configurable to meet specific backup requirements
- Multiple database support: Can backup all databases or specific ones
Installation
You can install automysqlbackup
in two ways:
- Clone from my GitHub repository:
git clone git@github.com:mattanja/automysqlbackup.git
- Or download from the original source:
wget http://sourceforge.net/projects/automysqlbackup/
After obtaining the files, run the setup script:
cd automysqlbackup
./install.sh
This will install:
- The executable script in
/usr/local/bin/automysqlbackup
- Default configuration in
/etc/automysqlbackup
Configuration
The tool uses two main configuration files:
/etc/automysqlbackup/automysqlbackup.conf
- Default configuration/etc/automysqlbackup/myserver.conf
- Server-specific settings
Key configuration options include:
- Backup directory location
- Database selection (all or specific databases)
- Compression settings
- Email notification settings
- Retention policies
Setting up Automated Backups
To set up automated daily backups, use the provided cron example:
# Create a new cron file
sudo cp /etc/automysqlbackup/example-cron-file /etc/cron.d/automysqlbackup
# The cron file will contain:
# Run the mysql backup scripts every morning at 4.30 h:
30 4 * * * root /etc/automysqlbackup/run
Backup Structure
The backup system creates a structured hierarchy:
backup_dir/
├── daily/
│ └── [database_name]/
│ └── [date]_[database_name].sql.gz
├── weekly/
└── monthly/
Additional Features
- Multiple backup types: Full, incremental, and differential backups
- Pre/post backup hooks: Execute custom scripts before or after backups
- Logging: Detailed logging of backup operations
- Error handling: Automatic error detection and notification
Security Considerations
- Store backup files in a secure location
- Use appropriate file permissions
- Consider encrypting sensitive backup data
- Implement proper access controls
Note on Current Relevance (2025)
Despite being originally written in 2014, this backup solution remains highly relevant in 2025 because:
- Proven Reliability: The tool has been battle-tested for over a decade
- Simplicity: Its straightforward approach makes it easy to maintain
- Compatibility: Continues to work with modern MySQL versions
- Flexibility: Can be integrated with modern backup solutions
- Low Resource Usage: Efficient operation makes it suitable for various environments
While newer backup solutions exist, automysqlbackup
remains a solid choice for many use cases, especially for those who value simplicity and reliability over cutting-edge features.