Page 1 of 1

Help appreciated: Autorun & Autobackup

Posted: 13. Nov 2015, 17:45
by DamianN
Hi,

first of all, this is my first post so hello everyone!! :)

We are running VirtualBox 5 on a Windows Server 2012 host. Currently we are autostarting each vm guest using VBoxvmservice. So far, this works well (though I' rather like to be able to use the VirtualBox Gui). We have the need to backup the VMs each night. We'd just like to keep a snapshot of the whole VM, so that restoring is easily done by copying the backupped files to a new host and starting them.

Before hacking something together, I would like to hear your advice how this is done best. My current idea is: Create a batch file that shuts down all VMs using VmServiceControl.exe, use VBoxManage to snapshop the VMs, restart VMs using VmServiceControl.

I appreciate any recommendation!

Best regards
Damian

Re: Help appreciated: Autorun & Autobackup

Posted: 13. Nov 2015, 19:05
by Martin
Forget about snapshots, that is not a complete copy of the VM.
You need to backup the whole subdirectory of the VM.

Re: Help appreciated: Autorun & Autobackup

Posted: 13. Nov 2015, 19:34
by scottgus1
See this tutorial "Moving a VM": viewtopic.php?f=35&t=55003 and re-interpret it as "Backing Up a VM". The guest must be shut down for this, as you are planning.

Virtualbox does not have a way to do incremental backups, or live backups while the guest is running. Use a 3rd party in-the-guest program for that.

Re: Help appreciated: Autorun & Autobackup

Posted: 16. Nov 2015, 19:41
by DamianN
Thank you for the input.

I will then perform the backup basically like this:

VBoxManage.exe controlvm demoVM savestate
VBoxManage.exe clonevm --options keepallmacs demovm --name demoVM --basefolder Z:\demoVM
VBoxManage.exe startvm --type headless demoVM

Should be a legit backup, right?

About the autorun-question: I am thinking about just using Windows server's task management to start the VM guest upon the server start. Now I am thinking about what happens if the server is rebooted. Will the guest be shutdown correctly? What shutdown type will be applied? Can I somehow specify a default type, which will be applied then? (e.g. savestate)

TIA!

Kind regards
Damian

Re: Help appreciated: Autorun & Autobackup

Posted: 16. Nov 2015, 20:14
by scottgus1
Save-state is not a good backup, because the saved state is tied very specifically to the host. It basically contains the exact state of the processors the guest was using, as well as the memory contents and other things. Saved States are not reliably restorable to different hosts. And you need to be able to restore to a different host if your usual host disappears/walks off/burns up etc. Since you are turning off the guest in some fashion, a complete shutdown is best.

Additionally, a clone is not an exact copy for a backup. Clones are modified so they can be run concurrently with the original, meaning machine UUIDs are different and OSs & programs that require activation will require a re-activation when restoring the "backup". And depending on the version (OEM vs retail) of the OS or the policies of the maker of the programs you may not be allowed to re-activate without spending money.

The best way to back up a guest is to do a complete normal shut down of the guest, then copy the guest folder to another storage device or three, then restart the guest. This is all scriptable. We run such full-shutdown backups of our office server guest and copy the backups to another drive in the server itself, another host that can run the server if the regular host dies, and two off-site storage locations in my boss's & my basements.

Auto-run could be set up with the Task Scheduler, but there's a trick or two to get the Virtualbox GUI to see and interface with a Task-Scheduled guest. You need to search the forum for the tricks, I don't remember right off what they are. A host shutdown or reboot will kill the guests mercilessly if the guests aren't shut down first.

I run the office server guest this way: The host machine auto-logs-in on the desired account then locks itself. The script that starts the guests in the proper order is run from a shortcut in the Startup folder in the Start menu, so the logged-on account is the correct account to let the Virtualbox GUI and Vboxmanage see & interact with the guests. I have a good UPS on the host giving some half-hour of runtime in a power outage, giving me plenty of time to get the guests save-stated. I also have a script which the UPS software triggers when the power outage lasts a minute, which script controls the guest save-state commands through Vboxmanage. I have disabled the shutdown and log-off buttons in the start menu, so the host doesn't shut down easily. I have a shortcut on the desktop to a script that will shut down all the guests then shut down the host. I have Windows Updates set to "Notify before Download", so I can see that the updates are ready, then I have a script I got from the Microsoft website which downloads & applies the updates. The Windows-update script gets run as part of the backup script after all the guests are shut down and backed up by folder copy & fc to the other server drive as noted above. Then the host reboots. After reboot the host auto-logs-in and the Start-menu-Startup-folder script shortcut restarts the guests, then the guest backups on the other server drive get copied to the alternate-run PC and rsynced to the offsite backups. The guests also get sha256-hashed, so the offsite basement backups have a way to confirm they were copied properly.

Re: Help appreciated: Autorun & Autobackup

Posted: 16. Nov 2015, 20:34
by DamianN
Wow, thorough description, thanks!

Have you tried assigning shutdown scripts via gpedit?
https://technet.microsoft.com/en-us/lib ... 70300.aspx

I would like to have that process as automated as possible, especially updates have to be applied automatically (it is a server - usually no one logs in...).

Re: Help appreciated: Autorun & Autobackup

Posted: 16. Nov 2015, 20:46
by scottgus1
I have, and it has never worked for me. When the guest is launched in the logged-on account the guest has to be shut down or save-stated before the account is logged off or the guest will be killed. The shutdown scripts in Group Policy don't run until after the log-off has taken place. (I used to see the log-off script run in a cmd window after the desktop had completely disappeared and all the guests were gone.)

It may be possible to get a task-scheduled guest to shut down during the log-off script, but I don't think Windows will wait around for the guest to complete shutdown or save-state if a bit more time is required. I believe it's better to see that the guests are all completely dealt with while the desktop is active, then issue a "shutdown -s" all in a script.

Re: Help appreciated: Autorun & Autobackup

Posted: 17. Nov 2015, 14:12
by scottgus1
DamianN wrote:I would like to have that process as automated as possible, especially updates have to be applied automatically (it is a server - usually no one logs in...).
Keep in mind that occasionally Microsoft puts out an update that breaks the OSs it's updating. I use the command-line-launched script and wait to install updates for a few weeks to see if the internet blows up about a bunged Windows update before I apply it to our machines.

Our process is completely automatic: auto-log-in, run the guest startup script, run for a week. Early Sunday morning run the backup script via task scheduler, which shuts down all the guests, copies the guest folders then runs Windows Updates via script if I had previously decided to let them run, then reboot, auto-log-in, run startup script, etc...

The benefit of logging in to run guests, to me, is that they're all right there on the desktop to interact with fully if something needs to be done with them. No need to crack out Vboxmanage because some item needs to be tweaked on a headless guest. Remote Desktop access allows getting into the guest itself, but not the Virtualbox functions. Auto-log-in, so one doesn't have to be there Sunday morning to start the guests, is easy with Microsoft Sysinternals' Auto-Log-In program.