TECHIES WORLD

For Techs.... Techniques.... Technologies....

CpanelLinuxMysqlPython

How to backup and restore MySQL database using Ansible

Ansible mysql_db module can be used to take dump and restore MySQL databases.

Sample code to dump the MySQL database is given below.

- name: Dump  database
mysql_db:
    state: dump
    name: db
    target: /tmp/db.sql

Here we need to replace 'db' with the name of the database.

Sample code to restore MySQL database dump is given below.

- name: Restore database
mysql_db:
    name: db
    state: import
    target: /tmp/db.sql

Here we need to replace 'db' with the name of the database.

Please note that the target can be any folder according to the requirements.

That's all…

Leave a Reply