backup.yml 2.8 KB

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