This commit is contained in:
Slava Rogozhkin 2024-10-22 11:11:36 +03:00
parent 1e020f0999
commit f82bbf4b8a
3 changed files with 69 additions and 0 deletions

22
poweroff-vbox Executable file
View File

@ -0,0 +1,22 @@
#!/bin/bash
if [[ -z $1 ]]; then
echo 'all or vm-name'
fi
typeset -a basename=( 'sudcm_osse18' 'sufs_osse18' 'suac_osse18' 'sudcs_osse18' 'susrv_osse18' 'fidcm_osse18' 'fidcr1_osse18' 'fidcr2_osse18' 'fisrv_osse18' 'fiac_osse18' 'samdc_osse18' 'samac_osse18' 'samfs_osse18' )
typeset -a machines
if [[ $1 = 'all' ]]; then
machines=$(vboxmanage list runningvms | awk '{print $1}' | sed 's/"//g' )
else
machines=("$@")
fi
for i in ${machines[@]}; do
for j in ${basename[@]}; do
if [[ $i = $j ]]; then
vboxmanage controlvm $i poweroff
fi
done
done

21
revert-libvirt Executable file
View File

@ -0,0 +1,21 @@
#!/bin/bash
if [[ -z $1 ]]; then
echo 'all or vm-name'
fi
if [[ $1 = 'all' ]]; then
machine=$(virsh -c qemu:///system list --name)
else
machine=("$@")
fi
for i in ${machine[@]}; do
snapshot=$(virsh -c qemu:///system snapshot-list $i | sed -n 3p | awk '{print $1}')
virsh -c qemu:///system destroy $i
virsh -c qemu:///system snapshot-revert $i $snapshot
if [[ $2 = 'stop' ]]; then
true
else
virsh -c qemu:///system start $i
fi
done

26
revert-vbox Executable file
View File

@ -0,0 +1,26 @@
#!/bin/bash
if [[ -z $1 ]]; then
echo 'all or vm-name'
fi
typeset -a machines
if [[ $1 = 'all' ]]; then
machines=$(vboxmanage list runningvms | awk '{print $1}' | sed 's/"//g' )
else
machines=("$@")
fi
for i in ${machines[@]}; do
snapshot=$(vboxmanage snapshot $i list | sed -n 1p | awk '{print $2}')
echo -e " \033[0;36m \n vm ${i} snapshot ${snapshot} \033[0m "
if [[ $2 = 'stop' ]]; then
vboxmanage controlvm $i poweroff
sleep 1
else
vboxmanage controlvm $i poweroff
sleep 2
vboxmanage snapshot $i restore "$shapshot"
sleep 2
vboxmanage startvm $i
fi
done