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

- name: Cleanup backup directory if it exists
  shell: rm -rf {{backup_dir}} && mkdir -p {{backup_dir}}
- name: Backup mysql database
  mysql_db: name={{mysql_db_name}} login_user=root login_password={{mysql_root_password}} state=dump target={{backup_dir}}/{{mysql_db_name}}.sql
- name: Backup configurations
  command: cp -r {{code_dir}}/common {{backup_dir}}
- name: Create directory for other important files/directories to backup
  command: mkdir -p {{backup_dir}}/other
- name: Copy other important files/directories
  command: cp -LR --parent "{{item|quote}}" "{{backup_dir|quote}}"/other/ removes={{item}}
  with_items: backup_items
  when: backup_items is defined
- name: Archive and compress the backup files
  shell: tar -czf {{backup_prefix}}-{{timestamp}}.tar.gz * chdir={{backup_dir}}
- name: Copy backup to the host's system
  fetch: src={{backup_dir}}/{{backup_prefix}}-{{timestamp}}.tar.gz dest={{backup_dest}} validate_md5=no flat=yes
- name: Remove the backup directory from the server
  command: rm -rf "{{backup_dir}}"
---
# Tasks to backup the database, configs and other important directories

- name: Cleanup backup directory if it exists
  shell: rm -rf {{backup_dir}} && mkdir -p {{backup_dir}}
- name: Backup mysql database
  mysql_db: name={{mysql_db_name}} login_user=root login_password={{mysql_root_password}} state=dump target={{backup_dir}}/{{mysql_db_name}}.sql
- name: Backup configurations
  command: cp -r {{code_dir}}/common {{backup_dir}}
- name: Create directory for other important files/directories to backup
  command: mkdir -p {{backup_dir}}/other
- name: Copy other important files/directories
  command: cp -LR --parent "{{item|quote}}" "{{backup_dir|quote}}"/other/ removes={{item}}
  with_items: backup_items
  when: backup_items is defined
- name: Archive and compress the backup files
  shell: tar -czf {{backup_prefix}}-{{timestamp}}.tar.gz * chdir={{backup_dir}}
- name: Copy backup to the host's system
  fetch: src={{backup_dir}}/{{backup_prefix}}-{{timestamp}}.tar.gz dest={{backup_dest}} validate_md5=yes flat=yes
- name: Remove the backup directory from the server
  command: rm -rf "{{backup_dir}}"
Enable md5 validation of downloaded backup
roles/backup: Enable md5 validation of downloaded backup
