Kubernetes cronjob: Automated MySQL Database Backups
Update: This project has been renamed to kubernetes-s3-mysql-backup, which better describes its function. The remainder of the post remains accurate.
As mentioned in my last post about my Kubernetes Architecture. I recently started investigating how I could perform regular backups of the MySQL database that sits behind this blog.
The goal was to have an automated backup taken at least once every 24 hours, saved to a durable location external to my current hosting provider. I also wanted to keep these database backups for at least a year and wanted to be able to re-use the solution for other services that I run in my environment.
To meet my requirements, I made aws-database-backup. This is a relatively simple Docker Container based on Alipine Linux. It is designed to be scheduled using Kubernetes Cronjobs. When executed, the container connects to a MySQL database specified by environment variables, performs a full dump of the database, and uploads it to S3.
You can read some more about my setup in my post on my Kubernetes Architecture, but for now, aws-database-backup is available on GitHub and Docker Hub if you're looking for a simple way to backup your MySQL databases.