how backup and restore mysql database using ansible1 min read

We need your support!!
Other Amount:
techrunnr.com:
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
  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.

We need your support!!
Other Amount:
techrunnr.com:
#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!!

You may also like...

Leave a Reply

Please wait...

Subscribe to our newsletter

Want to be notified when our article is published? Enter your email address and name below to be the first to know.
Exit mobile version