stancel.setup-mysql-backups
setup-mysql-backups
This is an Ansible role that copies a bash script to your machine. The script uses mysqldump
to back up one or more MySQL databases every night through a cron job. It saves the latest backup in the folder /backups/mysql/current
so that you can easily include it in an offsite backup system. Older backups are moved to the /backups/mysql
folder, and you can choose how many backups to keep using the setup_mysql_backups_num_db_backups_to_keep
variable (default is 30 backups).
Requirements
You need to have one or more MySQL databases on the server where you run this. Make sure MySQL and mysqldump
are installed on that server.
Role Variables
Here are the variables you can set:
List of databases to back up:
setup_mysql_backups_dbs_to_backup:
- "business"
MySQL root password:
setup_mysql_backups_mysql_root_password: "your password here"
Number of backups to keep:
setup_mysql_backups_num_db_backups_to_keep: 30
Dependencies
None
Example Playbook
Here's an example of how to use this role (with variables provided):
- hosts: your_server
vars_files:
- vars/main.yml
roles:
- { role: stancel.setup-mysql-backups }
Or
- hosts: your_server
vars:
setup_mysql_backups_num_db_backups_to_keep: 30
setup_mysql_backups_mysql_root_password: "some password here"
setup_mysql_backups_dbs_to_backup:
- 'db1'
- 'db2'
roles:
- stancel.apache-webserver
License
BSD
Author Information
Role to have a bash script run nightly on a cron job to backup a list of MySQL/MariaDB databases
ansible-galaxy install stancel.setup-mysql-backups