summaryrefslogtreecommitdiffstats
path: root/roles/etcd_upgrade/tasks/backup.yml
blob: 1ea6fc59f6069cd823ef8dbfa651b94a8b26d2b8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
---
# INPUT r_etcd_backup_sufix_name
# INPUT r_etcd_backup_tag
# OUTPUT r_etcd_upgrade_backup_complete
- set_fact:
    # ORIGIN etcd_data_dir etcd_common.defaults
    l_etcd_backup_dir: "{{ etcd_data_dir }}/openshift-backup-{{ r_etcd_backup_tag | default('') }}{{ r_etcd_backup_sufix_name }}"

# TODO: replace shell module with command and update later checks
- name: Check available disk space for etcd backup
  shell: df --output=avail -k {{ etcd_data_dir }} | tail -n 1
  register: avail_disk
  # AUDIT:changed_when: `false` because we are only inspecting
  # state, not manipulating anything
  changed_when: false

# TODO: replace shell module with command and update later checks
- name: Check current etcd disk usage
  shell: du --exclude='*openshift-backup*' -k {{ etcd_data_dir }} | tail -n 1 | cut -f1
  register: etcd_disk_usage
  when: r_etcd_upgrade_embedded_etcd | bool
  # AUDIT:changed_when: `false` because we are only inspecting
  # state, not manipulating anything
  changed_when: false

- name: Abort if insufficient disk space for etcd backup
  fail:
    msg: >
      {{ etcd_disk_usage.stdout }} Kb disk space required for etcd backup,
      {{ avail_disk.stdout }} Kb available.
  when: (r_etcd_upgrade_embedded_etcd | bool) and (etcd_disk_usage.stdout|int > avail_disk.stdout|int)

# For non containerized and non embedded we should have the correct version of
# etcd installed already. So don't do anything.
#
# For containerized installs we now exec into etcd_container
#
# For embedded non containerized we need to ensure we have the latest version
# etcd on the host.
- name: Install latest etcd for embedded
  package:
    name: etcd
    state: latest
  when:
  - r_etcd_upgrade_embedded_etcd | bool
  - not l_ostree_booted.stat.exists | bool

- name: Generate etcd backup
  command: >
    {{ etcdctl_command }} backup --data-dir={{ etcd_data_dir }}
    --backup-dir={{ l_etcd_backup_dir }}

# According to the docs change you can simply copy snap/db
# https://github.com/openshift/openshift-docs/commit/b38042de02d9780842dce95cfa0ef45d53b58bc6
- name: Check for v3 data store
  stat:
    path: "{{ etcd_data_dir }}/member/snap/db"
  register: v3_db

- name: Copy etcd v3 data store
  command: >
    cp -a {{ etcd_data_dir }}/member/snap/db
    {{ l_etcd_backup_dir }}/member/snap/
  when: v3_db.stat.exists

- set_fact:
    r_etcd_upgrade_backup_complete: True

- name: Display location of etcd backup
  debug:
    msg: "Etcd backup created in {{ l_etcd_backup_dir }}"