项目作者: dilantha

项目描述 :
Backup multiple MySQL databases over multiple hosts with Ansible
高级语言:
项目地址: git://github.com/dilantha/ansible-backup-mysql.git
创建时间: 2020-05-24T08:08:49Z
项目社区:https://github.com/dilantha/ansible-backup-mysql

开源协议:MIT License

下载


Ansible Backup MySQL

Backup multiple MySQL databases over multiple hosts with Ansible.

Requirements

You will need Ansible installed and shell access to your servers.

Setup

Next setup an Ansible inventory file. Personally I use a simple hosts file in a project like this.

  1. host1
  2. host2

Each server needs a set of host variables. Setup your host variables in a host_vars folder like this host_vars/host1.yaml, host_vars/host2.yaml.

Here is a sample configuration file. Make sure you don’t push these files up to git since they have sensitive data.

  1. backup_root: ~/Backup/Databases
  2. user: database user
  3. pass: database password
  4. databases:
  5. - db1
  6. - db2

backup_root is the backup root folder for backups. A subfolder will be created for each host you add like this.

  1. ├── host1
  2. ├── host2

dump_pass is your MySQL password for taking the backup. Its probably a good idea to create a separate backup user that has read and lock table access to your databases on each server.

databases is a list of databases you want to dump.

Running the script

Run the script with a local hosts file like below or with your own Ansible inventory configuration.

  1. ansible-playbook -i hosts backup_databases.yaml

This will dump each database to an sql file on the server and sync them back to your machine.

  1. host1
  2. ├── db1.sql
  3. ├── db2.sql
  4. host2
  5. ├── db3.sql
  6. ├── db4.sql