SHARE
TWEET

Untitled

a guest Mar 20th, 2016 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. - hosts: localhost
  2.  
  3.   vars:
  4.     remote_host: '...'
  5.     dump_name: '{{ ansible_date_time.date }}_{{ ansible_date_time.epoch }}_ansible_dump.sql'
  6.     remote_dump_path: '.../{{ dump_name }}'
  7.     local_dump_path: '/var/www/var/database/{{ dump_name }}'
  8.     local_db_config: 'login_user=root login_password=password encoding=utf8'
  9.     local_db_name: '...'
  10.     remote_db_name: '...'
  11.     remote_db_config: '-u... -p... {{ remote_db_name }}'
  12.  
  13.   tasks:
  14.     - name: Install/update packages
  15.       apt: name={{ item }} state=latest
  16.       with_items:
  17.         - python-dev
  18.         - libmysqlclient-dev
  19.         - python-pip
  20.       become: yes
  21.  
  22.     - name: Install the Python MySQLB module
  23.       pip: name=MySQL-python
  24.       become: yes
  25.  
  26.     - name: Create remote db dump
  27.       command: ssh {{ remote_host }} 'mysqldump {{ remote_db_config }} > {{ remote_dump_path }}'
  28.  
  29.     - name: Compress dump
  30.       command: ssh {{ remote_host }} 'gzip {{ remote_dump_path }}'
  31.  
  32.     - name: Get remote dump
  33.       command: scp {{ remote_host }}:'{{ remote_dump_path }}.gz' '{{ local_dump_path }}.gz'
  34.  
  35.     - name: Remove remote dump
  36.       command: ssh {{ remote_host }} 'rm {{ remote_dump_path }}.gz'
  37.  
  38.     - name: Unpack remote dump
  39.       command: gzip -d '{{ local_dump_path }}.gz'
  40.  
  41.     - name: Backup local db
  42.       mysql_db: state=dump name={{ local_db_name }} target='{{ local_dump_path }}_bak.sql' {{ local_db_config }}
  43.  
  44.     - name: Restore dump
  45.       mysql_db: state=import name={{ local_db_name }} target={{ local_dump_path }} {{ local_db_config }}
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top