backup.yml 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. ---
  2. # set the etcd backup directory name here in case the tag or sufix consists of dynamic value that changes over time
  3. # e.g. openshift-backup-{{ lookup('pipe', 'date +%Y%m%d%H%M%S') }} value will change every second so if the date changes
  4. # right after setting l_etcd_incontainer_backup_dir and before l_etcd_backup_dir facts, the backup directory name is different
  5. - set_fact:
  6. l_backup_dir_name: "openshift-backup-{{ r_etcd_common_backup_tag }}{{ r_etcd_common_backup_sufix_name }}"
  7. - set_fact:
  8. l_etcd_data_dir: "{{ etcd_data_dir }}{{ '/etcd.etcd' if r_etcd_common_etcd_runtime == 'runc' else '' }}"
  9. - set_fact:
  10. l_etcd_incontainer_data_dir: "{{ etcd_data_dir }}"
  11. - set_fact:
  12. l_etcd_incontainer_backup_dir: "{{ l_etcd_incontainer_data_dir }}/{{ l_backup_dir_name }}"
  13. - set_fact:
  14. l_etcd_backup_dir: "{{ l_etcd_data_dir }}/{{ l_backup_dir_name }}"
  15. # TODO: replace shell module with command and update later checks
  16. - name: Check available disk space for etcd backup
  17. shell: df --output=avail -k {{ l_etcd_data_dir }} | tail -n 1
  18. register: l_avail_disk
  19. # AUDIT:changed_when: `false` because we are only inspecting
  20. # state, not manipulating anything
  21. changed_when: false
  22. # TODO: replace shell module with command and update later checks
  23. - name: Check current etcd disk usage
  24. shell: du --exclude='*openshift-backup*' -k {{ l_etcd_data_dir }} | tail -n 1 | cut -f1
  25. register: l_etcd_disk_usage
  26. when: r_etcd_common_embedded_etcd | bool
  27. # AUDIT:changed_when: `false` because we are only inspecting
  28. # state, not manipulating anything
  29. changed_when: false
  30. - name: Abort if insufficient disk space for etcd backup
  31. fail:
  32. msg: >
  33. {{ l_etcd_disk_usage.stdout }} Kb disk space required for etcd backup,
  34. {{ l_avail_disk.stdout }} Kb available.
  35. when: (r_etcd_common_embedded_etcd | bool) and (l_etcd_disk_usage.stdout|int > l_avail_disk.stdout|int)
  36. # For non containerized and non embedded we should have the correct version of
  37. # etcd installed already. So don't do anything.
  38. #
  39. # For containerized installs we now exec into etcd_container
  40. #
  41. # For embedded non containerized we need to ensure we have the latest version
  42. # etcd on the host.
  43. - name: Detecting Atomic Host Operating System
  44. stat:
  45. path: /run/ostree-booted
  46. register: l_ostree_booted
  47. - name: Install latest etcd for embedded
  48. package:
  49. name: etcd
  50. state: latest
  51. when:
  52. - r_etcd_common_embedded_etcd | bool
  53. - not l_ostree_booted.stat.exists | bool
  54. - name: Check selinux label of '{{ l_etcd_data_dir }}'
  55. command: >
  56. stat -c '%C' {{ l_etcd_data_dir }}
  57. register: l_etcd_selinux_labels
  58. - debug:
  59. msg: "{{ l_etcd_selinux_labels }}"
  60. - name: Make sure the '{{ l_etcd_data_dir }}' has the proper label
  61. command: >
  62. chcon -t svirt_sandbox_file_t "{{ l_etcd_data_dir }}"
  63. when:
  64. - l_etcd_selinux_labels.rc == 0
  65. - "'svirt_sandbox_file_t' not in l_etcd_selinux_labels.stdout"
  66. - name: Generate etcd backup
  67. command: >
  68. {{ r_etcd_common_etcdctl_command }} backup --data-dir={{ l_etcd_incontainer_data_dir }}
  69. --backup-dir={{ l_etcd_incontainer_backup_dir }}
  70. # According to the docs change you can simply copy snap/db
  71. # https://github.com/openshift/openshift-docs/commit/b38042de02d9780842dce95cfa0ef45d53b58bc6
  72. - name: Check for v3 data store
  73. stat:
  74. path: "{{ l_etcd_data_dir }}/member/snap/db"
  75. register: l_v3_db
  76. - name: Copy etcd v3 data store
  77. command: >
  78. cp -a {{ l_etcd_data_dir }}/member/snap/db
  79. {{ l_etcd_backup_dir }}/member/snap/
  80. when: l_v3_db.stat.exists
  81. - set_fact:
  82. r_etcd_common_backup_complete: True
  83. - name: Display location of etcd backup
  84. debug:
  85. msg: "Etcd backup created in {{ l_etcd_backup_dir }}"