A powerful, flexible tool for automating MySQL database backups from Docker containers across multiple servers.
- Multi-server support: Configure and back up databases from multiple servers
- Zero dependencies: Just Bash and SSH (plus optional sshpass for passwordless operation)
- Secure: Support for password or SSH key authentication
- Container-aware: Works directly with Docker containers
- Customizable: Flexible configuration for each server
git clone https://github.com/developerabdan/mysql-docker-backup-automation.git
cd mysql-docker-backup-automation
chmod +x backup.sh
# Create configs directory if it doesn't exist
mkdir -p configs
# Copy the example config file and edit for your server
cp config.example.cfg configs/myserver.cfg
nano configs/myserver.cfg # Edit with your details
# Generate SSH key if you don't have one
ssh-keygen -t rsa -b 4096
# Copy your public key to the server
ssh-copy-id username@your-server.com
# macOS (using Homebrew)
brew install hudochenkov/sshpass/sshpass
# Ubuntu/Debian
sudo apt-get install sshpass
# CentOS/RHEL
sudo yum install sshpass
# List available server configurations
./backup.sh
# Backup a specific server
./backup.sh myserver
# Create a scheduled backup (cron job) - backs up daily at 2:00 AM
crontab -e
0 2 * * * /path/to/mysql-docker-backup-automation/backup.sh myserver
Backups are stored inside the Docker container at the path specified in your configuration:
/var/lib/mysql/dbname_YYYYMMDD_HHMMSS.sql
You can modify the backup script to download the files locally if needed.
Simply add new configuration files to the configs/
directory:
cp config.example.cfg configs/another-server.cfg
nano configs/another-server.cfg # Edit with the new server details
- SSH Connection Issues: Ensure your SSH credentials are correct and that SSH access is permitted
- Container Not Found: Verify the container name in your config and that the container is running
- Backup Permission Errors: Check that the MySQL user has permissions to execute dumps
This project is licensed under the MIT License - see the LICENSE file for details
If you find this tool useful, please give it a star on GitHub! Your support helps maintain and improve the project.
⭐ Star this repo if you found it helpful! ⭐
@abdansyakuro.id