---

- name: Create the archive dir
  file: path={{ kimai_root_dir }}/archives/{{ kimai_current_version }} state=directory
  tags: kimai

- name: Archive current version
  synchronize:
    src: "{{ kimai_root_dir }}/app"
    dest: "{{ kimai_root_dir }}/archives/{{ kimai_current_version }}/"
    compress: False
    delete: True
  delegate_to: "{{ inventory_hostname }}"
  tags: kimai

- name: Install mariadb client
  package:
    name:
      - mariadb
  tags: kimai

- name: Dump the database
  mysql_db:
    state: dump
    name: "{{ kimai_db_name }}"
    target: "{{ kimai_root_dir }}/archives/{{ kimai_current_version }}/{{ kimai_db_name }}.sql.xz"
    login_host: "{{ kimai_db_server }}"
    login_user: "{{ kimai_db_user }}"
    login_password: "{{ kimai_db_pass }}"
    quick: True
    single_transaction: True
  environment:
    XZ_OPT: -T0
  tags: kimai
