Backing up a VM

This is for discussing general topics about how to use VirtualBox.
Post Reply
scottgus1
Site Moderator
Posts: 20965
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Backing up a VM

Post by scottgus1 »

At the end of this FAQ (viewtopic.php?f=24&t=8046), TerryE suggests this prcedure for a backup:

"If you can’t take your VMs offline for long then one good trick is to start a new snapshot. Only the latest snapshot VDIs are opened R/W, so you can then backup the second to last whilst still using the VM. To resync, you savestate, delete the second last snapshot which in effect merges its content into latest; and resume the VM."

I have a question regarding this advice in the light of Virtualbox 4's keeping everything in one folder:

If I take a snapshot of a VM, copy the base VDI while the VM is running as suggested, then save-state, I could then copy the entire VM folder contents, except for the base vdi which has already been copied. My backup will then be a save-stated VM with one snapshot, theoretically being completed with the machine being off-line for much less time. I start the VM again, "delete" the snapshot, which merges the snapshot data back into the base vdi (while the VM is running, yes?) and I'm back up quickly.

Now, if my host dies and I reinstall Virtualbox on a new processor-compatible host, and I copy over that backed-up VM folder, will the new install of Virtualbox be able to recognize the save-stated, snapshotted VM and restart using the save-state, and then allow me to delete the snapshot into the base vdi as before? In other words, will the "restore" part of this backup process work?
mpack
Site Moderator
Posts: 39156
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Re: Backing up a VM

Post by mpack »

I have to say that I don't much care for TerryE's suggestion - IMHO too tricky and possibly version specific. Plus of course it involves snapshots, and backing up VMs that are using snapshots, both of which I would want to avoid.

IMHO there are only two good, practical ways to backup a VM. One is using a live backup feature that runs inside the guest (backing up to a shared folder - otherwise a VBox crash would kill the backup as well!). The other is shutting down (not savestate) the VM, and copying the VM folder to a backup medium. I prefer the latter, because I personally have no need for a live backup, and because it's the most reliable method.
Suncat2000
Posts: 3
Joined: 21. Feb 2011, 02:54
Primary OS: Ubuntu other
VBox Version: PUEL
Guest OSses: Windows XP Pro

Re: Backing up a VM

Post by Suncat2000 »

Unfortunately, I found out the hard way that you can't just copy the VM folder, at least with any not created completely from scratch with VB 4.0 or later. You also must copy the Snapshots and the .vbox metadata file to get the complete VM. If you don't, you will get only the base disk.

I know because my backup method was to clone the partition my VM was stored in. Except I found out too late that it was only one of three separate folder hierarchies created: one for the root disk, one for the differencing disks, and a third for the .vbox metadata, stored on different (host) disks. :evil:
mpack
Site Moderator
Posts: 39156
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Re: Backing up a VM

Post by mpack »

I think you are describing the folder structure of v3.x or earlier - in fact I know you are. v4.0.0 introduced the new folder structure where everything belonging to a VM goes into a single folder - including the Snapshots subfolder and the .vbox file. In fact the .vbox file didn't exist at all prior to v4.0.0.

If you have a v4.x VM folder, and you copy the folder as intended, and do not fiddle around with individual files, then this will be a very complete and reliable backup.

[ Edit] If you don't have a v4.x VM, but you are now running VBox v4.1 or later, then cloning the VM creates a v4 folder layout for the clone [ but changes drive and VM UUIDs, which can cause problems ]. Alternatively you can do the v4 conversion manually, if you really know what you're doing.
Last edited by mpack on 27. Jan 2012, 17:01, edited 1 time in total.
scottgus1
Site Moderator
Posts: 20965
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: Backing up a VM

Post by scottgus1 »

Thinking about it some more, mpack, after your first response, I agree. It's probably not a good backup solution. The saved-state condition of the backup includes whatever state the processor(s) were in when the save-state happened, which locks the backup to that processor or an identical replacement, which may not be available. Best way still seems to be a total shut-down of the VM. Or imaging software in the guest.

Thanks for the thoughts.
Post Reply