infra-generale/blockcommit_all.sh

39 lines
1.4 KiB
Bash
Raw Normal View History

2022-05-21 00:18:32 +02:00
#!/bin/bash
2022-05-20 22:13:38 +02:00
count=$1
VMs=$(sudo virsh list --state-running --name | sort -R)
#sudo aa-teardown
for vm in $VMs
do
2022-05-22 00:45:46 +02:00
path_vda=$(sudo virsh domblklist $vm | grep vda | cut -d" " -f 8)
path_vdb=$(sudo virsh domblklist $vm | grep vdb | cut -d" " -f 8)
2022-05-20 22:13:38 +02:00
if [ ! -z "$path_vda" ] && [[ ! "$path_vda" =~ ".raw" ]]
2022-05-20 22:13:38 +02:00
then
2022-05-22 00:45:46 +02:00
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 --pivot --info
echo "-- BLOCKCOMMITTING $vm ..."
sudo virsh blockcommit $vm vda --active --verbose --pivot --delete 2>&1
fi
2022-05-20 22:13:38 +02:00
fi
if [ ! -z "$path_vdb" ] && [[ ! "$path_vda" =~ ".raw" ]]
2022-05-20 22:13:38 +02:00
then
2022-05-22 00:45:46 +02:00
echo "-- BLOCKCOMMITTING $vm disk vdb ..."
2022-05-22 00:51:41 +02:00
retour=$(sudo virsh blockcommit $vm vdb --active --verbose --pivot --delete 2>&1 | tee /dev/tty)
2022-05-22 00:45:46 +02:00
if [[ "$retour" =~ 'block copy still active' ]]
then
echo "-- Finishing blockjob for $vm ..."
sudo virsh blockjob $vm $path_vdb --pivot --info
echo "-- BLOCKCOMMITTING $vm ..."
2022-05-22 00:51:41 +02:00
sudo virsh blockcommit $vm vda --active --verbose --pivot --delete 2>&1
2022-05-22 00:45:46 +02:00
fi
2022-05-20 22:13:38 +02:00
fi
done
#sudo systemctl restart apparmor.service