how backup and restore mysql database using ansible1 min read

Prabhin Prabharkaran Administrator
DevOps Engineer

He is a Technical professional. He is a person who loves to share tricks and tips on the Internet. He Posts what he does!

follow me

Hi All, This document shows you how backup and restore MySQL database using ansible.
Ansible is a Provisioning and configuration management tool which can be used for both Linux and windows platform. Ansible has reached the best place under the best DevOps tools because it is very is easy and simple.
Ansible playbook is written in YAML file which is human readable and understandable which makes ansible popular.

Step 1: Create a YAML file
vi backup-restore.yml

Paste the below contents, explanations are given below.

- hosts: cloud-replica
  gather_facts: true
     - name: backup  DB
        name: wordpress_db
        state: dump
        target: /opt/backup.sql
        login_user: root
        login_password: 'password'
      - name: start the importing
         name: restoredb
         state: import
         target: /opt/backup.sql"
         login_user: root
         login_password: 'Password'   

First task perform DB backup to /opt/backup.sql file of wordpress_db with above mentioned DB username and password where is the DB host.

The second task restore database from /opt/backup.sql to restoredb database with above mentioned DB username and password.

© 2020, Techrunnr. All rights reserved.

Questions Answered
Articles Written
Overall Points

Related posts

Leave a Reply