Skip to content

Commit c8e51b7

Browse files
authored
Qemu (#506)
1 parent 5573c74 commit c8e51b7

File tree

13 files changed

+363
-3
lines changed

13 files changed

+363
-3
lines changed

Ansible/inventory

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# Server types
12
[bare]
23
core01.rc reboot_async=true
34
core02.rc
@@ -8,7 +9,7 @@ web02.rc
89
[rasp]
910
rasp01.rc
1011

11-
[lxc:children]
12+
[lxc_containers:children]
1213
lxc_core01
1314
lxc_core02
1415

@@ -25,10 +26,19 @@ dns01b.rc
2526
dhcp01b.rc
2627
web01b.rc
2728

29+
# Services
30+
[lxc]
31+
core01.rc
32+
core02.rc
33+
2834
[podman]
2935
core01.rc
3036
web02.rc
3137

38+
[qemu]
39+
core01.rc
40+
41+
# Other
3242
[antiz_fr]
3343
web01a.rc branch=dev
3444
web01b.rc branch=dev
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
2-
- name: "Backup lxc containers"
3-
hosts: bare
2+
- name: "Backup LXC containers"
3+
hosts: lxc
44
become: true
55
roles:
66
- role: "backup_lxc_containers"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
- name: "Backup Qemu VMs"
3+
hosts: qemu
4+
become: true
5+
roles:
6+
- role: "backup_qemu_vms"
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Backup Qemu VMs
2+
3+
Backup all qemu virtual machines.
4+
5+
## Variables
6+
7+
The following variable is defined in `defaults/main.yml`:
8+
9+
- backup_retention: `3` (numbers of backups to keep).
10+
11+
The following variables are defined in `vars/main.yml`:
12+
13+
- source_dir: `/data/qemu/vms/` (directory containing the qemu vms to backup).
14+
- backup_base_dir: `/backup/qemu/` (base directory to store backups).
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#SPDX-License-Identifier: MIT-0
2+
---
3+
# defaults file for backup_qemu_vms
4+
5+
backup_retention: 3
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#SPDX-License-Identifier: MIT-0
2+
---
3+
# handlers file for backup_qemu_vms
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#SPDX-License-Identifier: MIT-0
2+
galaxy_info:
3+
author: your name
4+
description: your role description
5+
company: your company (optional)
6+
7+
# If the issue tracker for your role is not on github, uncomment the
8+
# next line and provide a value
9+
# issue_tracker_url: http://example.com/issue/tracker
10+
11+
# Choose a valid license ID from https://spdx.org - some suggested licenses:
12+
# - BSD-3-Clause (default)
13+
# - MIT
14+
# - GPL-2.0-or-later
15+
# - GPL-3.0-only
16+
# - Apache-2.0
17+
# - CC-BY-4.0
18+
license: license (GPL-2.0-or-later, MIT, etc)
19+
20+
min_ansible_version: 2.2
21+
22+
# If this a Container Enabled role, provide the minimum Ansible Container version.
23+
# min_ansible_container_version:
24+
25+
galaxy_tags: []
26+
# List tags for your role here, one per line. A tag is a keyword that describes
27+
# and categorizes the role. Users find roles by searching for tags. Be sure to
28+
# remove the '[]' above, if you add tags to this list.
29+
#
30+
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
31+
# Maximum 20 tags per role.
32+
33+
dependencies: []
34+
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
35+
# if you add dependencies to this list.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#SPDX-License-Identifier: MIT-0
2+
---
3+
# tasks file for backup_qemu_vms
4+
5+
- name: "Create backup directory"
6+
ansible.builtin.file:
7+
path: "{{ backup_base_dir }}{{ ansible_facts['date_time']['date'] }}"
8+
state: directory
9+
mode: "0750"
10+
11+
- name: "Backup qemu vms via RSYNC" # noqa: command-instead-of-module
12+
ansible.builtin.shell:
13+
cmd: rsync -aAXHv --numeric-ids --delete "{{ source_dir }}" "{{ ansible_facts['date_time']['date'] }}"
14+
changed_when: true
15+
args:
16+
chdir: "{{ backup_base_dir }}"
17+
18+
- name: "Get backup directories list"
19+
ansible.builtin.find:
20+
paths: "{{ backup_base_dir }}"
21+
file_type: directory
22+
register: list_backup_dirs
23+
24+
- name: "Delete old backup directories"
25+
ansible.builtin.file:
26+
path: "{{ item.path }}"
27+
state: absent
28+
loop: "{{ (list_backup_dirs.files | sort(attribute='ctime'))[:-backup_retention] }}"
29+
when: list_backup_dirs.files | length > backup_retention
30+
31+
- name: "List backup directories"
32+
ansible.builtin.shell:
33+
cmd: ls -ltrh "{{ backup_base_dir }}"
34+
register: ls_backup_dirs
35+
changed_when: false
36+
37+
- name: "Show backup directories"
38+
ansible.builtin.debug:
39+
msg: "{{ ls_backup_dirs.stdout_lines }}"
40+
when: ls_backup_dirs.stdout_lines | length > 0
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#SPDX-License-Identifier: MIT-0
2+
localhost
3+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#SPDX-License-Identifier: MIT-0
2+
---
3+
- hosts: localhost
4+
remote_user: root
5+
roles:
6+
- backup_qemu_vms

0 commit comments

Comments
 (0)