infra-generale/blockcommit_all.sh

59 lines
2.2 KiB
Bash
Raw Normal View History

2022-05-21 00:18:32 +02:00
#!/bin/bash
2023-11-21 13:19:03 +01:00
# Script to commit blocks of vm disks
#
# Copyright (C) 2023 Adrien 'neox' Bourmault <neox@a-lec.org>
#
# 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 <https://www.gnu.org/licenses/>.
2022-08-02 17:09:57 +02:00
2022-05-20 22:13:38 +02:00
count=$1
VMs=$(sudo virsh list --state-running --name | sort -R)
2022-08-02 17:09:57 +02:00
sudo aa-teardown
2022-05-20 22:13:38 +02:00
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 ..."
2022-08-05 14:56:36 +02:00
sudo virsh blockjob $vm $path_vda --info
sudo virsh blockjob $vm $path_vda --pivot
2022-05-22 00:45:46 +02:00
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 ..."
2022-08-05 14:56:36 +02:00
sudo virsh blockjob $vm $path_vdb --info
sudo virsh blockjob $vm $path_vdb --pivot
2022-05-22 00:45:46 +02:00
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
2022-08-02 17:09:57 +02:00
sudo systemctl restart apparmor.service