B&R: Add playbook to restore user images
Add role for restoring registry images from docker archive. Import user images from docker archive to docker. Push the images referencing local registry. After the push the images tags will be deleted. If there are no tags pointing to the same image unique id the image will be deleted from the docker filesystem thus recovering the space. Partition where archive is located, docker partition, local registry partition must all be big enough. The archive can be bigger than available space before bootstrap playbook is played. Restore platform procedure needs to be called before restoring docker images so that bootstrap playbook is called and space allocated. For local plays there are 2 key variables, while for remote play there are 4. Var `initial_backup_dir` points to the directory where the backup file is located. Var `backup_filename` points to the file in the directory. Var `backup_dir` is used for remote plays and is the destination folder on the remote where the file will be copied. Var `ansible_remote_tmp` points to a temporary directory on the remote that ansible `copy` module will use to transfer the file. Directories pointed to by `initial_backup_dir, `backup_dir` and `ansible_remote_tmp` must be mounted where free space exceeds backup size. Example call: restor_user_images.yml \ -e "initial_backup_dir=/host1/sufficient/space1/" \ -e "backup_filename=example.tar" \ -e "ansible_remote_tmp=/host2/sufficient/space1/" \ -e "backup_dir=/host2/sufficient/space1/" Closes-Bug: 1886152 Depends-On: I4644784ea4164134f163d218e69dc4ceb148985a Change-Id: I0a7dcf9d174fbc07af85ef51bb4068d0dc16c560 Signed-off-by: Dan Voiculeasa <dan.voiculeasa@windriver.com>
This commit is contained in:
parent
8345f30dfa
commit
b8e84bb5d0
19
playbookconfig/src/playbooks/restore_user_images.yml
Normal file
19
playbookconfig/src/playbooks/restore_user_images.yml
Normal file
@ -0,0 +1,19 @@
|
||||
---
|
||||
#
|
||||
# Copyright (c) 2020 Wind River Systems, Inc.
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
- hosts: all
|
||||
gather_facts: no
|
||||
|
||||
vars_files:
|
||||
- host_vars/backup-restore/default.yml
|
||||
|
||||
roles:
|
||||
- { role: common/prepare-env }
|
||||
- { role: restore-user-images/prepare-env, become: yes }
|
||||
- { role: backup-restore/prepare-env }
|
||||
- { role: backup-restore/transfer-file }
|
||||
- { role: restore-user-images/restore-local-registry-images, become: yes,
|
||||
docker_images_backup: "{{ target_backup_dir }}/{{ backup_filename }}" }
|
@ -0,0 +1,43 @@
|
||||
---
|
||||
#
|
||||
# Copyright (c) 2020 Wind River Systems, Inc.
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
# ROLE DESCRIPTION:
|
||||
# This role verifies if user images restore should proceed
|
||||
#
|
||||
- name: Fail if backup_filename is not defined or set
|
||||
fail:
|
||||
msg: "Mandatory configuration parameter backup_filename is not defined or set."
|
||||
when: backup_filename is not defined or backup_filename is none
|
||||
|
||||
- name: Fail if initial_backup_dir is not defined or set
|
||||
fail:
|
||||
msg: "Mandatory configuration parameter initial_backup_dir is not defined or set."
|
||||
when: initial_backup_dir is not defined or initial_backup_dir is none
|
||||
|
||||
- name: Check if restoring user images is already in progress
|
||||
stat:
|
||||
path: "{{ restore_user_images_in_progress_flag }}"
|
||||
register: restore_user_images_in_progress
|
||||
|
||||
- name: Fail if restoring user images is already in progress
|
||||
fail:
|
||||
msg: "Restoring user images is already in progress!"
|
||||
when: restore_user_images_in_progress.stat.exists
|
||||
|
||||
- name: Create {{ restore_user_images_in_progress_flag }} flag file
|
||||
file:
|
||||
path: "{{ restore_user_images_in_progress_flag }}"
|
||||
state: touch
|
||||
|
||||
- name: For remote play set target_backup_dir to {{ backup_dir }}
|
||||
set_fact:
|
||||
target_backup_dir: "{{ backup_dir }}"
|
||||
when: inventory_hostname != "localhost"
|
||||
|
||||
- name: For local play set target_backup_dir to initial_backup_dir
|
||||
set_fact:
|
||||
target_backup_dir: "{{ initial_backup_dir }}"
|
||||
when: inventory_hostname == "localhost"
|
@ -0,0 +1,43 @@
|
||||
---
|
||||
#
|
||||
# Copyright (c) 2020 Wind River Systems, Inc.
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
# ROLE DESCRIPTION:
|
||||
# This role exists to import container images from an archive.
|
||||
# It pushes images starting with `registry.local:9001`, thus
|
||||
# the images meant to be pushed to local registry.
|
||||
#
|
||||
|
||||
- block:
|
||||
- name: Check that backup archive exists
|
||||
stat:
|
||||
path: "{{ docker_images_backup }}"
|
||||
register: file_result
|
||||
|
||||
- block:
|
||||
- name: Import docker images
|
||||
command: docker load -i {{ docker_images_backup }}
|
||||
|
||||
- name: Get image list to push to local registry
|
||||
shell: docker image ls | grep -s '^registry.local:9001' | awk -F' ' '{print($1":"$2)}'
|
||||
register: image_list_query
|
||||
|
||||
- debug: var=image_list_query.stdout_lines
|
||||
|
||||
- name: Push to local registry if any image tagged as such
|
||||
script: >
|
||||
roles/common/push-docker-images/files/push_pull_local_registry.py push \
|
||||
"{{ image_list_query.stdout_lines | join(',') }}"
|
||||
when: image_list_query.stdout_lines|length > 0
|
||||
|
||||
when: file_result.stat.exists
|
||||
|
||||
when: docker_images_backup is defined
|
||||
|
||||
always:
|
||||
- name: Remove the {{ restore_user_images_in_progress_flag }} file
|
||||
file:
|
||||
path: "{{ restore_user_images_in_progress_flag }}"
|
||||
state: absent
|
@ -0,0 +1,10 @@
|
||||
---
|
||||
#
|
||||
# Copyright (c) 2019 Wind River Systems, Inc.
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
|
||||
# Flag file to indicate if user images restore is in progress
|
||||
#
|
||||
restore_user_images_in_progress_flag: /etc/platform/.restore_user_images_in_progress
|
Loading…
x
Reference in New Issue
Block a user