backup.yml 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. ---
  2. - include_tasks: vars.yml
  3. # TODO: replace shell module with command and update later checks
  4. - name: Check available disk space for etcd backup
  5. shell: df --output=avail -k {{ etcd_data_dir }} | tail -n 1
  6. register: l_avail_disk
  7. # AUDIT:changed_when: `false` because we are only inspecting
  8. # state, not manipulating anything
  9. changed_when: false
  10. # TODO: replace shell module with command and update later checks
  11. - name: Check current etcd disk usage
  12. shell: du --exclude='*openshift-backup*' -k {{ etcd_data_dir }} | tail -n 1 | cut -f1
  13. register: l_etcd_disk_usage
  14. # AUDIT:changed_when: `false` because we are only inspecting
  15. # state, not manipulating anything
  16. changed_when: false
  17. - name: Abort if insufficient disk space for etcd backup
  18. fail:
  19. msg: >
  20. {{ l_etcd_disk_usage.stdout|int*2 }} Kb disk space required for etcd backup,
  21. {{ l_avail_disk.stdout }} Kb available.
  22. when: l_etcd_disk_usage.stdout|int*2 > l_avail_disk.stdout|int
  23. # For non containerized we should have the correct version of
  24. # etcd installed already. So don't do anything.
  25. #
  26. # For containerized installs we now exec into etcd_container
  27. - name: Detecting Atomic Host Operating System
  28. stat:
  29. path: /run/ostree-booted
  30. register: l_ostree_booted
  31. - name: Check selinux label of '{{ etcd_data_dir }}'
  32. command: >
  33. stat -c '%C' {{ etcd_data_dir }}
  34. register: l_etcd_selinux_labels
  35. - debug:
  36. msg: "{{ l_etcd_selinux_labels }}"
  37. - name: Make sure the '{{ etcd_data_dir }}' has the proper label
  38. command: >
  39. chcon -t svirt_sandbox_file_t "{{ etcd_data_dir }}"
  40. when:
  41. - l_etcd_selinux_labels.rc == 0
  42. - "'svirt_sandbox_file_t' not in l_etcd_selinux_labels.stdout"
  43. - name: Generate etcd backup
  44. command: >
  45. {{ r_etcd_common_etcdctl_command }} backup --data-dir={{ l_etcd_incontainer_data_dir }}
  46. --backup-dir={{ l_etcd_incontainer_backup_dir }}
  47. # According to the docs change you can simply copy snap/db
  48. # https://github.com/openshift/openshift-docs/commit/b38042de02d9780842dce95cfa0ef45d53b58bc6
  49. - name: Check for v3 data store
  50. stat:
  51. path: "{{ etcd_data_dir }}/member/snap/db"
  52. register: l_v3_db
  53. - name: Copy etcd v3 data store
  54. command: >
  55. cp -a {{ etcd_data_dir }}/member/snap/db
  56. {{ l_etcd_backup_dir }}/member/snap/
  57. when: l_v3_db.stat.exists
  58. - set_fact:
  59. r_etcd_common_backup_complete: True
  60. - name: Display location of etcd backup
  61. debug:
  62. msg: "Etcd backup created in {{ l_etcd_backup_dir }}"