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
  tasks:
     - name: backup  DB
       mysql_db:
        name: wordpress_db
        state: dump
        target: /opt/backup.sql
        login_host: 192.168.10.22
        login_user: root
        login_password: 'password'
      - name: start the importing
        mysql_db:
         name: restoredb
         state: import
         target: /opt/backup.sql"
         login_host: 192.168.10.2
         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 192.168.10.22 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.

#1
#2
#3
Questions Answered
Articles Written
Overall Points

Prabhin Prabharkaran

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

0 Comments

Leave a Reply

Keep ahead of COVID-19

Follow the below safety measures as precautionary steps to avoid COVID-19 1. Use face mask in public Places 2. Use Hand sanitizers 3. Maintain Social Distancing 4. Avoid going to crowded places 5. Avoid touching eyes, nose and mouth