Last active
February 8, 2018 23:57
-
-
Save remoteur/d81045b0e6098a3076bc617cf4364831 to your computer and use it in GitHub Desktop.
backup-restore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- name: register image files | |
find: | |
path: /var/lib/libvirt/images/ | |
pattern: "{{ vm_name }}.*qcow2$" | |
use_regex: yes | |
register: vm_images | |
- command: "cp --sparse=always {{ item.path }} {{ item.path }}.{{ restore_point }}" | |
with_items: "{{ vm_images.files }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- name: register image files | |
find: | |
path: /var/lib/libvirt/images/ | |
pattern: "{{ vm_name }}.*qcow2$" | |
use_regex: yes | |
register: vm_images | |
- command: "cp --sparse=always {{ item.path }}.{{ restore_point }} {{ item.path }}" | |
with_items: "{{ vm_images.files }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- name: vms backup/restore actions | |
hosts: localhost | |
gather_facts: false | |
vars: | |
action: noop | |
restore_point: orig | |
backup_items: '.' | |
tasks: | |
- name: register vms | |
shell: | | |
virsh list --all | grep -v Name | awk {'print $2'} | grep -v ^$ | grep {{ backup_items }} | |
register: vms | |
- block: | |
- name: destroy vms | |
command: virsh destroy {{ item }} | |
with_items: "{{ vms.stdout_lines }}" | |
- include: disks_backup.yaml | |
with_items: "{{ vms.stdout_lines }}" | |
loop_control: | |
loop_var: vm_name | |
- name: power on vms | |
command: virsh start {{ item }} | |
with_items: "{{ vms.stdout_lines }}" | |
when: action == 'backup' | |
- block: | |
- name: destroy vms | |
command: virsh destroy {{ item }} | |
with_items: "{{ vms.stdout_lines }}" | |
- include: disks_restore.yaml | |
with_items: "{{ vms.stdout_lines }}" | |
loop_control: | |
loop_var: vm_name | |
- name: power on vms | |
command: virsh start {{ item }} | |
with_items: "{{ vms.stdout_lines }}" | |
when: action == 'restore' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment