Gracefully shutdown (and backup) Virtualbox guest

written by Admin


Posted on 2013-04-18


Problem

I must gracefully shutdown some Oracle VirtualBox guests for a nightly backup.

Solution

If the guest-os is Linux, first install acpid:
#apt-get install acpid

This is my backup script:
vboxmanage --nologo guestcontrol execute "Guest VM Name" "shutd.bat" --username Administrator --password my_passwd --verbose

#if the host is running on Windows uncomment these lines
#choice /n /t 60 /d 0 /c:0 /m "Waiting 1 min"
#choice /n /t 60 /d 0 /c:0 /m "Waiting 2 min"
#choice /n /t 60 /d 0 /c:0 /m "Waiting 3 min"

#if the host is running on Linux uncomment these lines
#echo "Waiting 1 min"
#sleep 60
#echo "Waiting 2 min"
#sleep 60
#echo "Waiting 2 min"
#sleep 60

#If the first script fails...
VboxManage controlvm "Guest VM Name" acpipowerbutton

#if the host is running on Windows uncomment these lines
#choice /n /t 60 /d 0 /c:0 /m "Waiting 1 min"
#choice /n /t 60 /d 0 /c:0 /m "Waiting 2 min"
#choice /n /t 60 /d 0 /c:0 /m "Waiting 3 min"

#if the host is running on Linux uncomment these lines
#echo "Waiting 1 min"
#sleep 60
#echo "Waiting 2 min"
#sleep 60
#echo "Waiting 2 min"
#sleep 60

#...just to be sure
vboxmanage --nologo controlvm "Guest VM Name" poweroff

#Now do your backup

#Restart the guest-os
vboxmanage --nologo startvm "Guest VM Name"

Feedback


Leave a Comment:


Search

Categories

android x 1
apache x 1
apple x 4
backup x 2
cygwin x 1
dns x 1
dos x 1
drupal x 3
ftp x 1
iis x 1
imap x 1
linux x 22
mail x 4
mysql x 3
oracle x 1
pop3 x 1
print x 2
proxy x 1
rsync x 1
shell x 8
smtp x 1
squid x 1
ssh x 1
storage x 2
web x 3
windows x 15

Welcome

We need collaboration and a real boost from our community: write us an email for every trick you find!

This website is a sysadmin swiss-knife for every-day Windows, Linux and Mac administration and troubleshooting

Our database grows if YOU send us your tips and trick as soon as you find them every day!