ich hab im Netz ein Script gefunden (und etwas bearbeitet), um eine laufende VM zu exportieren.
Leider schaffe ich es nicht, dass nur eine bestimmte VM (Debian8_1) exportiert wird.
Genauer gesagt ist es diese Zeile, die ja dann alle laufenden VMs auflistet
Code: Alles auswählen
for VMNAME in $(vboxmanage list runningvms | cut -d " " -f 1 | sed -e 's/^"//' -e 's/"$//')
Habt ihr vielleicht eine Idee?
Code: Alles auswählen
#!/bin/bash
# This scripts loops through all the user's VirtualBox vm's, pauses them,
# exports them and then restores the original state.
#
# VirtualBox's snapshot system is not stable enough for unmonitored use yet.
#
# Vorkbaard, 2012-02-01
# =============== Set your variables here ===============
EXPORTDIR=/media/*****
MYMAIL=*****
VBOXMANAGE="/usr/bin/VBoxManage -q"
DATE=$(date +%Y-%m-%d_%H-%M)
# =======================================================
# Generate a list of all vm's; use sed to remove the double quotes.
# Note: better not use quotes or spaces in your vm name. If you do,
# consider using the vms' ids instead of friendly names:
# for VMNAME in $(vboxmanage list vms | cud -t " " -f 2)
# Then you'd get the ids in your mail so you'd have to use vboxmanage
# showvminfo $id or something to retrieve the vm's name. I never use
# weird characters in my vm names anyway.
for VMNAME in $(vboxmanage list runningvms | cut -d " " -f 1 | sed -e 's/^"//' -e 's/"$//')
do
ERR="nothing"
SECONDS=0
# Get the vm state
VMSTATE=$(vboxmanage showvminfo Debian8_1 --machinereadable | grep "VMState=" | cut -f 2 -d "=")
echo "$VMNAME's state is: $VMSTATE."
# If the VM's state is running or paused, save its state
if [[ $VMSTATE == \"running\" || $VMSTATE == \"paused\" ]]; then
echo "Saving state..."
vboxmanage controlvm "Debian8_1" acpipowerbutton
if [ $? -ne 0 ]; then ERR="saving the state"; fi
fi
# Export the vm as appliance
if [ "$ERR" == "nothing" ]; then
echo "Exporting the VM..."
sleep 10
vboxmanage export "Debian8_1" --ovf20 --output /media/*****/Debian8_$DATE.ova
if [ $? -ne 0 ]; then
ERR="exporting"
else
# Get file size
FILESIZE=$(du -h $EXPORTDIR/Debian8_$DATE.ova | cut -f 1)
fi
else
echo "Not exporting because the VM's state couldn't be saved."
fi
# Resume the VM to its previous state if that state was paused or running
if [[ $VMSTATE == \"running\" || $VMSTATE == \"paused\" ]]; then
echo "Resuming previous state..."
vboxmanage startvm "Debian8_1" --type headless
#vboxmanage import /media/*****/Debian8_$DATE.ova
if [ $? -ne 0 ]; then ERR="resuming"; fi
if [ $VMSTATE == \"paused\" ]; then
vboxmanage controlvm $VMNAME pause
if [ $? -ne 0 ]; then ERR="pausing"; fi
fi
fi
done
Code: Alles auswählen
Debian8_1's state is: "running".
Saving state...
Exporting the VM...
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
Successfully exported 1 machine(s).
Resuming previous state...
Waiting for VM "Debian8_1" to power on...
VM "Debian8_1" has been successfully started.
Debian8_pyload's state is: "running".
Saving state...
Exporting the VM...
0%...
Progress state: VBOX_E_FILE_ERROR
VBoxManage: error: Appliance write failed
VBoxManage: error: Could not create OVA file '/media/*****/Debian8_2016-08-16_05-00.ova' (VERR_ALREADY_EXISTS)
VBoxManage: error: Details: code VBOX_E_FILE_ERROR (0x80bb0004), component Appliance, interface IAppliance
VBoxManage: error: Context: "int handleExportAppliance(HandlerArg*)" at line 1121 of file VBoxManageAppliance.cpp
Resuming previous state...
VBoxManage: error: The machine 'Debian8_1' is already locked by a session (or being locked or unlocked)
VBoxManage: error: Details: code VBOX_E_INVALID_OBJECT_STATE (0x80bb0007), component Machine, interface IMachine, callee nsISupports
VBoxManage: error: Context: "LaunchVMProcess(a->session, sessionType.raw(), env.raw(), progress.asOutParam())" at line 592 of file VBoxManageMisc.cpp