#!/bin/bash # Script to commit blocks of vm disks # # Copyright (C) 2023 Adrien 'neox' Bourmault # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . count=$1 VMs=$(sudo virsh list --state-running --name | sort -R) sudo aa-teardown for vm in $VMs do path_vda=$(sudo virsh domblklist $vm | grep vda | cut -d" " -f 8) path_vdb=$(sudo virsh domblklist $vm | grep vdb | cut -d" " -f 8) if [ ! -z "$path_vda" ] && [[ ! "$path_vda" =~ ".raw" ]] then echo "-- BLOCKCOMMITTING $vm disk vda ..." retour=$(sudo virsh blockcommit $vm vda --active --verbose --pivot --delete 2>&1 | tee /dev/tty) if [[ "$retour" =~ 'block copy still active' ]] then echo "-- Finishing blockjob for $vm ..." sudo virsh blockjob $vm $path_vda --info sudo virsh blockjob $vm $path_vda --pivot echo "-- BLOCKCOMMITTING $vm ..." sudo virsh blockcommit $vm vda --active --verbose --pivot --delete 2>&1 fi fi if [ ! -z "$path_vdb" ] && [[ ! "$path_vda" =~ ".raw" ]] then echo "-- BLOCKCOMMITTING $vm disk vdb ..." retour=$(sudo virsh blockcommit $vm vdb --active --verbose --pivot --delete 2>&1 | tee /dev/tty) if [[ "$retour" =~ 'block copy still active' ]] then echo "-- Finishing blockjob for $vm ..." sudo virsh blockjob $vm $path_vdb --info sudo virsh blockjob $vm $path_vdb --pivot echo "-- BLOCKCOMMITTING $vm ..." sudo virsh blockcommit $vm vda --active --verbose --pivot --delete 2>&1 fi fi done sudo systemctl restart apparmor.service