backup.yml 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. ---
  2. - set_fact:
  3. l_etcd_backup_dir: "{{ etcd_data_dir }}/openshift-backup-{{ r_etcd_common_backup_tag }}{{ r_etcd_common_backup_sufix_name }}"
  4. # TODO: replace shell module with command and update later checks
  5. - name: Check available disk space for etcd backup
  6. shell: df --output=avail -k {{ etcd_data_dir }} | tail -n 1
  7. register: l_avail_disk
  8. # AUDIT:changed_when: `false` because we are only inspecting
  9. # state, not manipulating anything
  10. changed_when: false
  11. # TODO: replace shell module with command and update later checks
  12. - name: Check current etcd disk usage
  13. shell: du --exclude='*openshift-backup*' -k {{ etcd_data_dir }} | tail -n 1 | cut -f1
  14. register: l_etcd_disk_usage
  15. when: r_etcd_common_embedded_etcd | bool
  16. # AUDIT:changed_when: `false` because we are only inspecting
  17. # state, not manipulating anything
  18. changed_when: false
  19. - name: Abort if insufficient disk space for etcd backup
  20. fail:
  21. msg: >
  22. {{ l_etcd_disk_usage.stdout }} Kb disk space required for etcd backup,
  23. {{ l_avail_disk.stdout }} Kb available.
  24. when: (r_etcd_common_embedded_etcd | bool) and (l_etcd_disk_usage.stdout|int > l_avail_disk.stdout|int)
  25. # For non containerized and non embedded we should have the correct version of
  26. # etcd installed already. So don't do anything.
  27. #
  28. # For containerized installs we now exec into etcd_container
  29. #
  30. # For embedded non containerized we need to ensure we have the latest version
  31. # etcd on the host.
  32. - name: Detecting Atomic Host Operating System
  33. stat:
  34. path: /run/ostree-booted
  35. register: l_ostree_booted
  36. - name: Install latest etcd for embedded
  37. package:
  38. name: etcd
  39. state: latest
  40. when:
  41. - r_etcd_common_embedded_etcd | bool
  42. - not l_ostree_booted.stat.exists | bool
  43. - name: Generate etcd backup
  44. command: >
  45. {{ r_etcd_common_etcdctl_command }} backup --data-dir={{ etcd_data_dir }}
  46. --backup-dir={{ l_etcd_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 }}"