summaryrefslogtreecommitdiff
path: root/remove_stale_vms
blob: 74c63c0472eaa39c5c8225d271a3325aa71765fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/bin/bash
#
# 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
  #echo $vm
  [[ "$vm" =~ "$VM_REGEX" ]] && remove_domain $vm 
done