Comnplete backup and restore of running VMs

This is for discussing general topics about how to use VirtualBox.
Post Reply
Notorand.IT
Posts: 77
Joined: 14. Nov 2013, 12:47
Primary OS: Other
VBox Version: OSE other
Guest OSses: ArchLinux x86_64
Location: Regnum Utriusque Siciliae

Comnplete backup and restore of running VMs

Post by Notorand.IT »

Hi all.
I have a main headless host (host1) running a VM (vm1) with VB v5.1 .
I have a backup headless host (host2) where I also have installed VB v5.1 .
Once or twice a day I need to create a backup of vm1 without stopping it.
I need to be able to restore the backup of vm1 on host2.

I have found this interesting blog entry but it's not yet clear to me:

1. what i need to copy from host1 to host2 (just the snapshot? the whole vm folder?)
2. how to restore the execution of vm1 on host2.

Is there anyone who already addressed a similar case and is willing to share the knowledge?
I am not afraid to deviate from the linked recipe, anyway.

TALIA!

P.S.
"headless" means that I need to do it with command line tools like vboxmanage, not the GUI.
# rm -fr /
scottgus1
Site Moderator
Posts: 20945
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: Comnplete backup and restore of running VMs

Post by scottgus1 »

Yes, this has been discussed before. The linked blog involves taking a snapshot of a guest while it is running, copying the base vdi (now static because the snapshot file is active) to the backup location, then removing/merging the snapshot (I forget what the exact command is to merge the snapshot back into the main disk). Note that the re-merging part is theoretical - I have not tried it and I don't know if Virtualbox allows it.

The problem with this is what exactly is copied in the base vdi while the snapshot is active. Most operating systems need to do stuff to the disk even when shutting down: write memory data, close databases and files, flush caches, etc. Even my Raspberry Pi recommends using the official shutdown commands before pulling the power so the disk can be unmounted. If an OS that needs to prepare itself for power off doesn't get a chance, then the disk would be in a crashed, "pulled the plug" state: possibly lost data, crashed databases that have to be scanned and rebuilt, etc.

The snapshot backup routine essentially causes a guest to start writing its data on a new disk without the guest OS knowing. The original disk had active files, databases, missing data in memory etc. Now that disk is copied. The backup will be a disk with a running OS on it with active files, databases, missing data etc. When you start the backup, the data will be in a "pulled the plug" state. The guest OS will have to recover same as if it were powered off without being allowed to shut down peacefully. Maybe a problem, maybe not.

You would do better to have in-the-guest live backup software to copy the appropriate data or take a complete disk image of the guest from within the running guest OS to restore in the other guest. Then you will be able to have good backups without copying around crashed guests.

Don't forget that just a vdi does not a full guest make. There's other files too. The best way to copy or backup a guest is when it is shut down, see Moving a VM and re-interpret it as "Backing Up a VM".

If you really want to go the snapshot route via command line, see the manual, section 8.16
Notorand.IT
Posts: 77
Joined: 14. Nov 2013, 12:47
Primary OS: Other
VBox Version: OSE other
Guest OSses: ArchLinux x86_64
Location: Regnum Utriusque Siciliae

Re: Comnplete backup and restore of running VMs

Post by Notorand.IT »

Everything is almost working.
This is how I do it.

On the main host:

1. Create a first snapshot called "0" so the VDIs become static.
2. Create a second snapshot called "1" so snapshot 0 becomes static as well.
3. Backup the original .vbox and .vdi as well as the whole Snapshots folder
4. delete the second snapshot "1"
5. restore the forst snapshot "0" (*)

When needed, on the backup host I would:

1. delete the snapshot "1" (it's unreliable as it's been copied whle in use)
2. restore the snapshot "0"
3. start the vm

The point is (*) that I cannot restore (aka re-merge) the snapshot "0" on the main host while the vm is running or is suspended.
I could leave that vm running ove the snapshot that will become larger and larger.
Also the "linked" suggestion is supposed to run over the "current" snapshot.
Is there any way to restore a snapshot without stopping the vm?
The documentation doesn't mention this limitation, though.
# rm -fr /
Post Reply