---
# Tasks to restore the database, configs and other important directories

- name: Cleanup restore directory if it exists
  shell: rm -rf {{restore_dir}} && mkdir -p {{restore_dir}}
- name: Ensure python MySQLdb module is present
  apt: name=python-mysqldb state=present
- name: Copy and extract the backup file contents
  unarchive: src={{restore_src}} dest={{restore_dir}}
- name: Drop the tatoeba schema if it already exists
  shell: echo "DROP DATABASE IF EXISTS {{mysql_db_name}}" | mysql -u {{mysql_user}} -p{{mysql_password}}
- name: Create the tatoeba schema
  shell: echo "CREATE DATABASE IF NOT EXISTS {{mysql_db_name}}" | mysql -u {{mysql_user}} -p{{mysql_password}}
- name: Restore mysql database
# The following command requires root privileges for importing the database (dump contains trigger statements)
  mysql_db: name={{mysql_db_name}} login_user=root login_password={{mysql_root_password}} state=import target={{restore_dir}}/{{mysql_db_name}}.sql
- name: Restore common directory
  command: cp -rf {{restore_dir}}/common {{code_dir}}
- name: Restore other important files/directories
  command: cp -rf {{restore_dir}}/other/{{item}} {{item}} removes={{restore_dir}}/other/{{item}}
  with_items: restore_items
  when: restore_items is defined
- name: Remove the restore directory from the server
  command: rm -rf {{restore_dir}}
---
# Tasks to restore the database, configs and other important directories

- name: Cleanup restore directory if it exists
  shell: rm -rf {{restore_dir}} && mkdir -p {{restore_dir}}
- name: Ensure python MySQLdb module is present
  apt: name=python-mysqldb state=present
- name: Copy and extract the backup file contents
  unarchive: src={{restore_src}} dest={{restore_dir}}
- name: Drop the tatoeba schema if it already exists
  shell: echo "DROP DATABASE IF EXISTS {{mysql_db_name}}" | mysql -u {{mysql_user}} -p{{mysql_password}}
- name: Create the tatoeba schema
  shell: echo "CREATE DATABASE {{mysql_db_name}}" | mysql -u {{mysql_user}} -p{{mysql_password}}
- name: Restore mysql database
# The following command requires root privileges for importing the database (dump contains trigger statements)
  mysql_db: name={{mysql_db_name}} login_user=root login_password={{mysql_root_password}} state=import target={{restore_dir}}/{{mysql_db_name}}.sql
- name: Restore common directory
  command: cp -rf {{restore_dir}}/common {{code_dir}}
- name: Restore other important files/directories
  command: cp -rf {{restore_dir}}/other/{{item}} {{item}} removes={{restore_dir}}/other/{{item}}
  with_items: restore_items
  when: restore_items is defined
- name: Remove the restore directory from the server
  command: rm -rf {{restore_dir}}
Remove a tautological condition for creating database
roles/restore: Remove a tautological condition for creating database
