A simple tool to automate backups flow for MySQL database.
All backups will be stored in S3 storage so you need to configure credentials in .env
(as in .env.example
).
By default all backup is made by mysqldump
, compressed by gzip
and named as backup-{id}.sql.gz
.
Backups are unified by ID which is date of the backup in format Y-m-d
(ex: 2021-09-01
).
Backups that are already exists in storage would be overwritten by a new backup. So no problem to made backups every hour, you would have the latest version in storage every time.
You can use it as standalone docker image or as a PHP project.
Configure credentials:
$ cp .env.example .env
Make sure you attach container to the same network of MySQL daemon.
$ docker run -d --name mysql-backup --env-file .env cashtrack/mysql-backup:latest
By default it starts with cron with crontab
took from the project root. Rebuild container if you need to change it.
To run commands:
$ docker run -d --name mysql-backup --env-file .env cashtrack/mysql-backup:latest php /app/app.php {command-with-arguments}
Requirements:
- PHP 7.3+
- Composer
- MySQL client (
mysql
andmysqldump
)
$ composer install
Then you can use simple CLI tool:
$ php app.php --help
$ php app.php list - Output a list of all backups in S3
$ php app.php backup - Make backup manually using today's date
$ php app.php restore 2019-03-01 - Restore backup with the given ID
$ php app.php clear --days=7 - Remove backups older than `--days` amount of days