---
- name: Create archive directory
  file: path={{ offen_root_dir }}/archives/{{ offen_current_version }} state=directory mode=700
  tags: offen

- name: Archive previous version
  copy: src={{ offen_root_dir }}/bin/offen dest={{ offen_root_dir }}/archives/{{ offen_current_version }} remote_src=True
  tags: offen

- name: Archive the database
  mysql_db:
    state: dump
    name: "{{ offen_db_name }}"
    target: "{{ offen_root_dir }}/archives/{{ offen_current_version }}/{{ offen_db_name }}.sql.xz"
    login_host: "{{ offen_db_server | default(mysql_server) }}"
    login_user: sqladmin
    login_password: "{{ mysql_admin_pass }}"
    quick: True
    single_transaction: True
  environment:
    XZ_OPT: -T0
  tags: offen
