summaryrefslogtreecommitdiff
path: root/remove_stale_vms
diff options
context:
space:
mode:
Diffstat (limited to 'remove_stale_vms')
-rwxr-xr-xremove_stale_vms18
1 files changed, 18 insertions, 0 deletions
diff --git a/remove_stale_vms b/remove_stale_vms
new file mode 100755
index 0000000..dbcc159
--- /dev/null
+++ b/remove_stale_vms
@@ -0,0 +1,18 @@
+#!/bin/sh
+#
+# removes all libvirt domains older than 1 day matching given regex
+
+
+VM_REGEX='$test_'
+
+remove_domain () {
+ echo "Destroying and undefining $vm"
+ virsh destroy "$1"
+ virsh undefine --remove-all-storage --snapshots-metadata "$1"
+}
+
+for vm in $(find /etc/libvirt/qemu -maxdepth 1 -type f -mmin +1440 -exec basename -s .xml {} \;)
+do
+ [[ "$vm" =~ "$VM_REGEX" ]] && remove_domain $vm
+done
+