backup.yml 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. ---
  2. # INPUT r_etcd_backup_sufix_name
  3. # INPUT r_etcd_backup_tag
  4. # OUTPUT r_etcd_upgrade_backup_complete
  5. - set_fact:
  6. # ORIGIN etcd_data_dir etcd_common.defaults
  7. l_etcd_backup_dir: "{{ etcd_data_dir }}/openshift-backup-{{ r_etcd_backup_tag | default('') }}{{ r_etcd_backup_sufix_name }}"
  8. # TODO: replace shell module with command and update later checks
  9. - name: Check available disk space for etcd backup
  10. shell: df --output=avail -k {{ etcd_data_dir }} | tail -n 1
  11. register: avail_disk
  12. # AUDIT:changed_when: `false` because we are only inspecting
  13. # state, not manipulating anything
  14. changed_when: false
  15. # TODO: replace shell module with command and update later checks
  16. - name: Check current etcd disk usage
  17. shell: du --exclude='*openshift-backup*' -k {{ etcd_data_dir }} | tail -n 1 | cut -f1
  18. register: etcd_disk_usage
  19. when: r_etcd_upgrade_embedded_etcd | bool
  20. # AUDIT:changed_when: `false` because we are only inspecting
  21. # state, not manipulating anything
  22. changed_when: false
  23. - name: Abort if insufficient disk space for etcd backup
  24. fail:
  25. msg: >
  26. {{ etcd_disk_usage.stdout }} Kb disk space required for etcd backup,
  27. {{ avail_disk.stdout }} Kb available.
  28. when: (r_etcd_upgrade_embedded_etcd | bool) and (etcd_disk_usage.stdout|int > avail_disk.stdout|int)
  29. # For non containerized and non embedded we should have the correct version of
  30. # etcd installed already. So don't do anything.
  31. #
  32. # For containerized installs we now exec into etcd_container
  33. #
  34. # For embedded non containerized we need to ensure we have the latest version
  35. # etcd on the host.
  36. - name: Install latest etcd for embedded
  37. package:
  38. name: etcd
  39. state: latest
  40. when:
  41. - r_etcd_upgrade_embedded_etcd | bool
  42. - not l_ostree_booted.stat.exists | bool
  43. - name: Generate etcd backup
  44. command: >
  45. {{ 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: 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: v3_db.stat.exists
  58. - set_fact:
  59. r_etcd_upgrade_backup_complete: True
  60. - name: Display location of etcd backup
  61. debug:
  62. msg: "Etcd backup created in {{ l_etcd_backup_dir }}"