Categories
Device

How to backup and move virtualbox machines

How to backup and move virtualbox machines

VirtualBox is a well-known tool that offers numerous features for effective virtualization. The program offers an amazingly simple interface with plenty of advanced functions for every need, including ability to copy or backup a virtual machine. Although you are the beginner or experienced user, you might wonder on how to backup VirtualBox virtual machine quickly and with minimum efforts.

How can you export virtual machine in VirtualBox?

The process of backup of your VM may require you a couple of minutes.

First of all, switch off your virtual machine and make sure to delete any off its snapshots.

Than Select your VM and choose on “Snapshots”.

How to backup and move virtualbox machines

Now select the needed snapshot and press the delete button. The process may last several seconds, so be ready to wait a bit.

After you`ve successfully deleted your snapshots, go to File – Virtual Media Manager. Here you will find a list of different media that you’ve used on your machines.

How to backup and move virtualbox machines

Choose which virtual machine you would like to move and press “Release” icon. In our case, we`ll be moving W7.vdi file from the home directory to another hard drive.

Then close VirtualBox and visit its default settings directory, usually located at /home/user/.VirtualBox/

How to backup and move virtualbox machines

You may also copy your .vdi file from inside the HardDisks directory in case you want to back it up, or you are free to move it. Wait for a while for the changes to come into effect.

Than you will need to change the VirtualBox.xml file. To perform the operation, open it in gedit.

How to backup and move virtualbox machines

Scroll down to find the needed lines.

If you’re changing the location of your VM, search for the xml tags for “MachineEntry” and edit the source path. In case you’re moving your virtual disk images, search for the xml tags for “HardDisk” and edit its location.

Every machine is linked to a disk image by its unique UUID, which must not be edited. If you’re moving VM to a PC, make sure you`ve copied this file and replace the previous configuration file.

In our case, we are going to move the disk image to another drive, so we do not need any additional changes.

How to backup and move virtualbox machines

Note: If you’re changing hosts from Windows to Linux operating systems, you will need to change the version declaration for “windows” instead of “linux”.

Once you’ve moved the needed .vdi file, fire up VirtualBox and visit File – Virtual Media Manager.

How to backup and move virtualbox machines

Remove an old .vdi file. Choose “Add,” search its new location, and choose “Open.”

Now we need to attach the new .vdi to your virtual machine. Choose it at the main app`s screen, go to “Settings,” and choose “Storage”.

How to backup and move virtualbox machines

Click “Add Attachment” under the needed IDE controller. Click it and choose the correct .vdi file under “Hard Disk”.

How to backup and move virtualbox machines

All these steps will help you to export virtual machine in VirtualBox easily and absolutely quickly. In case you`ve faced any problems, make sure you`ve been using the correct paths.

Need to move a virtual machine, only to find that copying and pasting doesn’t work? Perhaps you just want to know what to backup? Take a look at this quick guide on the process to get a better understanding of VirtualBox

First things first: be sure that your virtual machine is shut down and powered off. Next, make sure you get rid of any snapshots you have. There isn’t a fool-proof and safe way to do this without getting rid of them, unfortunately. Select your virtual machine and click on the “Snapshots” tab.

How to backup and move virtualbox machines

Select your snapshot and click the delete button. Be prepared to wait a while as VirtualBox merges differences with your machine’s current state. The machine’s state won’t actually change, though, so don’t worry. Now that the prep stuff is out of the way, we can start the moving process.

Once that’s done, go to File > Virtual Media Manager. You’ll see a list of media that you’ve used or have attached to your machines.

How to backup and move virtualbox machines

Select which virtual machine you want to move, then click on the “Release” icon above. In my case, I’ll be moving W7.vdi from my home directory to another hard drive.

Once you have it released, close VirtualBox go to its default settings directory, /home/user/.VirtualBox/

How to backup and move virtualbox machines

You can copy your .vdi file from inside the HardDisks directory if you want to just back it up, or you can move it. Be patient, as this can take a while depending on your configuration.

Meanwhile, let’s edit the VirtualBox.xml file to our liking. This is the step most people don’t really know much about, but it’s pretty vital in making sure things work smoothly. Open it up in gedit.

How to backup and move virtualbox machines

Scroll down a bit and you’ll get to the parts we need to edit.

If you’re changing the location of your virtual machines, find the xml tags for “MachineEntry” and change the source path. If you’re changing the location of your virtual disk images, find the xml tags for “HardDisk” and change the location there. As you can see, each machine is tied to a disk image by its UUID, which should not be changed. If you’re moving virtual machines to a new computer, be sure to copy these this file over and replace the previous configuration file.

In my particular case, I just wanted to move the disk image to a more spacious drive, so I left the other things intact.

How to backup and move virtualbox machines

If you’re changing hosts between Windows and Linux, be sure to change the version declaration at the top of the file to say “windows” instead of “linux” as well.

Once you’ve moved the .vdi file, fire up VirtualBox and go to File > Virtual Media Manager.

How to backup and move virtualbox machines

Click on the old .vdi file and click remove. Now, click “Add,” navigate to its new location, and click “Open.” Click “OK.”

Now that the new .vdi is added to VirtualBox’s list, we have to attach it to your virtual machine. At the main screen select it, go to “Settings,” and click on the “Storage” panel.

How to backup and move virtualbox machines

Under the appropriate IDE controller, click the “Add Attachment” button. You’ll see a hard disk get added automatically, but it probably won’t be the correct one.

Click it and on right side, under “Hard Disk,” choose the correct .vdi file. Click “OK.”

How to backup and move virtualbox machines

If you followed all the steps and you edited the VirtualBox.xml correctly you should be able to start up the machine without any problems! There are a few hairy areas, so if things aren’t working, be sure you’re using the correct paths and you’ve edited only the relevant areas of VirtualBox.xml.

The overall process is a bit more intricate than just copying and pasting, but it’s still relatively quick and painless. Share your backup stories about VirtualBox in the comments!

End user forums for VirtualBox

  • Board indexGeneralVirtualBox on Mac OS X Hosts
  • Change font size
  • Print view
  • FAQ
  • Login

Best way to backup a VM?

Best way to backup a VM?

by PeterNosko » 9. Dec 2013, 04:31

Could someone tell me the best way to back up individual guest machines? I exclude my machines folder from Time Machine backups because of the size (and because the machine might be active during such backups).

If I do an appliance export, could I delete my current machine and re-import from this .ova w/o issues like a duplicate disk ID, etc?

Re: Best way to backup a VM?

by ChipMcK » 9. Dec 2013, 08:38

The guest OS should be ShutDown when you copy the V4-VBox folder/directory [containing the virtual machine] to a directoryfolder on a backup (external) hard drive.

The file structure of Version 4 of VirtualBox defaults to having all files pertaining to a virtual machine in a single folder/directory.

Re: Best way to backup a VM?

by socratis » 9. Dec 2013, 08:39

Re: Best way to backup a VM?

by PeterNosko » 9. Dec 2013, 17:13

Re: Best way to backup a VM?

by Rootman » 9. Dec 2013, 19:40

The above work just fine, they take up as much disk space as your VDI file is for each backup though. I take a lightly different tack. I back mine up just like I back up my physical boxes.

It is fairly involved and has a rather steep learning curve though. I boot each VM to an ISO file with a Windows PE (built with WinBuilder – Google it) and then use Symantec Ghost to ghost each machine over the network to the hosts storage. This backs up only the data and can compress it fairly well too. There is no real advantage other than space savings. I can restore the image to a larger or smaller VDI or recreated VM as well without much effort. It’s just how I do it.

Re: Best way to backup a VM?

by PeterNosko » 9. Dec 2013, 19:45

Re: Best way to backup a VM?

by Rootman » 10. Dec 2013, 16:53

I find that the way I do it, after mounting the learning curve – also allows me the ability to restore individual files / folders as well, being a type of true backup rather than just a copy of the VDI file. I’ve also used it to resize disks and clone the OS without having to mess around much at the host level beyond just creating a new VDI.

Re: Best way to backup a VM?

by PeterNosko » 10. Dec 2013, 19:49

Re: Best way to backup a VM?

by Rootman » 10. Dec 2013, 21:16

Yep, I treat the VM just like I treat any physical PC. On a “real” PC I stick my thumbdrive in a USB slot, boot to it via Easy2Boot (a SUPERB set of scripts that uses Greb4DOS to make booting damn near ANY ISO as simple as drag and drop) to Windows PE and back up / reimage or work on the drive. I do the same for VMs just by mounting the ISO to the same PE and boot to it and cut a Ghost image of the OS to a network resource. I’ve restored complete OS’s or just damaged parts using Ghost Explorer and just drag and drop what I need back to the drive.

Sometimes people forget that you can treat these VMs just like any other machine and fix ’em or abuse ’em the same ways. Including running Timemachine or any other such util on them.

Re: Best way to backup a VM?

by noteirak » 12. Dec 2013, 00:55

@Rootman: so you backup the content of the VM, but not all the extra metadata associated with it? That would also cause the same issues as physical PC : you will encounter issue if you try to restore that ghost image to a new VM, since the UUIDs are different. I can see reactivation issues in Windows and booting issue in Linux.
Your way is also a lot more overhead and downtime to perform a backup.
Finally if the VM is properly maintened, I don’t see where you can gain space : the VDI should be compacted regularly to keep the size as close as possible as the real data.

To me it looks like you loose all the advantages of having a *virtual* machine and get all the disadvantages of physical ones.

Re: Best way to backup a VM?

by Rootman » 14. Dec 2013, 18:11

noteirak wrote: @Rootman: so you backup the content of the VM, but not all the extra metadata associated with it? That would also cause the same issues as physical PC : you will encounter issue if you try to restore that ghost image to a new VM, since the UUIDs are different. I can see reactivation issues in Windows and booting issue in Linux.
Your way is also a lot more overhead and downtime to perform a backup.
Finally if the VM is properly maintened, I don’t see where you can gain space : the VDI should be compacted regularly to keep the size as close as possible as the real data.

To me it looks like you loose all the advantages of having a *virtual* machine and get all the disadvantages of physical ones.

Well to each his own. I boot to PE, chkdsk and defrag the VM and then back it up, takes 30 minutes and I get a clean backed up OS I can restore files or folders from. It take minutes to create a new VM in VBOX, boot to the same PE and use ghost to make a clone. It works quite well for me. It’s just another option.

How to backup and move virtualbox machines

How to backup and move virtualbox machines

VirtualBox is one of the most widely used software for running virtual machines on lots of systems. Developed by Oracle, VirtualBox is truly a piece of work that can help anyone in lots of situations. For running virtual machines, Linux is often used as it’s a lightweight system with extremely powerful features.

If you’re a VirtualBox user, you obviously have to know how to backup a virtual system from the VirtualBox. It’s really useful in lots of situations, for example, exporting the virtual system to others or for development purpose etc.

How to make the backup

Snapshots

There are several ways you can make a backup of a virtual system on VirtualBox. For Linux, it’s the easiest method to use the “snapshot” feature. The benefit is, it allows saving the instant state of the VM and restore the same state at any time.

How to take a snapshot

  • Open VirtualBox.
  • Start the virtual system you wish to take backup.
  • Once opened, go to Machines >> Take snapshot.

How to backup and move virtualbox machines

  • Enter a name for the snapshot. You can also add snapshot description and other information.

How to backup and move virtualbox machines

Restoring snapshots

  • Open VirtualBox main window.
  • Click the arrow next to the “Machine Tools” button.

How to backup and move virtualbox machines

  • Select the snapshot you want to restore from the “snapshot manager”.
  • Click “Restore”.

How to backup and move virtualbox machines

It’s done! You can easily create and restore snapshots as you like.

Exporting VMs

VirtualBox also allows you export and import VMs just like a file. However, this will make a backup copy of the VM’s files and operating system; no snapshots. The virtual machine, then, can be deployed into any other virtual system.

  • Open VirtualBox.
  • Go to File >> Export Appliance.

How to backup and move virtualbox machines

  • Select the virtual machine you want to back up.
  • Choose the backup file path and format.

How to backup and move virtualbox machines

How to backup and move virtualbox machines

The exported file can be deployed in any system.

I have several virtual machines running on Virtualbox. I want to take a backup of these virtual machines and store in source control for disaster recover. From what I understand, snapshots of these virtual machines aren’t going to do the trick as far as disaster recovery is concerned.

These backups will be taken periodically, and I’m going to automate them using Jenkins automation server. I have been using an article from TechRepublic as a resource for operating VirtualBox from command line as far as exporting virtual appliances.

My thoughts on the process executed by the Jenkins job are as follows (all actions performed from command line):

    Power down the particular virtual machine to be backed up (and leave virtualbox running).

Run the VirtualBox export command:

Run command to bring the virtual machine back up.

  • CD into the directory where VirtualBox virtual appliances are stored.
  • Copy the newly created virtual appliance (.ova format), to a local backup directory.
  • Compress (tar), the copied .ova file in the local backup directory.
  • Remove the uncompressed copy of the .ova file in the local backup directory.
  • Git commit the compressed virtual appliance, and Git push to BitBucket.
  • Some questions I have about using this approach:

    • Where are VirtualBox’s virtual appliances stored by default?
    • What would the shell command look like to power down the virtual machine pre backup?
    • What would the shell command look like to power on the virtual machine post backup?

    Hi folks. So I’ve come to really appreciate the snapshot feature of virtualbox, and in general just the idea of sandboxing an environment I can play in, and recover from any I do (goof) on the system. Well my only problem is remembering to take the actual snapshots. So here’s a quick dirty tutorial on how to set up the VBoxManage feature to do this for me!

    So first what is a snapshot? From the VirtualBox “Man Page”

    “This command is used to control snapshots from the command line. A snapshot consists of a complete copy of the virtual machine settings, copied at the time when the snapshot was taken, and optionally a virtual machine saved state file if the snapshot was taken while the machine was running. After a snapshot has been taken, VirtualBox creates differencing hard disk for each normal hard disk associated with the machine so that when a snapshot is restored, the contents of the virtual machine’s virtual hard disks can be quickly reset by simply dropping the pre-existing differencing files.”

    I’m assuming you’ve installed Virtualbox to your machine. And I’m assuming you’re using Windows as the host machine. (Don’t judge me! I *DO* have a machine with a dedicated Bunsen install!)

    1. First you should add the C:\Program Files\Oracle\VirtualBox path to your Windows Machine. To do this:
    A. Click on the Windows Button.
    B. Click on Control Panel.
    C. Click on System.
    D. Click on Advanced System Settings. (maybe on the left menu)
    E. This will bring up the System Properties menu. Click on the Advanced tab.
    F. At the bottom, click the “Environment Variables” button
    G. Look under the System Variables scroll box and scroll down to where it says Path.
    H. Select it, and click Edit.
    I. Under the Variable value add the addition of: C:\Program Files\Oracle\VirtualBox
    J. Make sure you separate the last path with the ; character. Make sure not to delete the other path options already there.
    2. Okay so that will let you now run commands from the VirtualBox directory without having to CD over to it, or specify the full path
    just for convenience. So now we’ll use Microsoft’s Task Scheduler to set up a simple task to create the snapshot.
    Click on Start, and either search for “Task Scheduler” or go to control panel> administrative tools > task scheduler.
    3. The main menu has lots of options but don’t be daunted, it’s simple once you’re familiar with it. On the left window, right click
    on the “Task Scheduler Library”, and select New Folder.
    4. Name the folder something like VirtualBox. Once it’s created, right click on that newly created directory and create one more new directory. Name this one something
    specific to which VM you want to have the task run for. For example if you have 3 VM’s, you can create three separate directories, under the main “VirtualBox” directory.
    5. So let’s walk through the task creation for one. Select one of the VM specific folders you made and on the right “Actions” pane, select
    “Create Task”
    6. When opened, You’ll be on the “General” tab. Type a name for your task. Because I’m doing snapshots, I named mine SnapShot (so original).
    Make sure the Author is your logged user. Type a description if you’d like. (may help, keeping the different VM’s unique)
    7. Just as a failsafe, I would check the “Run with highest privileges”.
    8. Make sure the “Configure For” dropdown has the OS you’re running selected.
    9. We’re all done here, so click “Triggers” tab, and click new. On the top of the menu you’ll see a drop down labled “Begin the task” This is all manner of triggers that we can
    specify how you want your snapshot task to begin. I put mine on a schedule, but other options include “On Logon”, “On Startup” or “On Event” etc. and even more exist.
    You can really delve deep and specify very precisely how you want this snapshot to be triggered. A lot of it has to do with Event ID’s that I don’t really even want to be
    bothered with. To keep things simple, I’d just go for “On a Schedule”.
    10. Choose how often you want it to run, and how often you want it to repeat, etc.
    11. Once you have the schedule of it’s running worked out, move to the Actions tab. The only actions that I have on mine were “Run a Program”, “Send an Email” and “Display a Message”Welp.
    Run a program sounds about right. It gives you a browse option as to what program you want to start. So, for our backups we need to select the VBoxManage.exe.
    It’s by default, located in C:\Program Files\Oracle\VirtualBox\VBoxManage.exe Select this.
    12. Below, you need to specify a few specific options. The main command to take the snap shot is VBoxManage snapshot “

    “I have not failed, I have found 10,000 ways that will not work” -Edison

    Advertisement:
    Canagon.com – Website for $499, beautiful premade designs, high-performance hosting on all continents, dedicated support team. Learn more >

    Following procedure I have tried and I practice on VirtualBox version > 4, I have Windows 7 64, Ubuntu 12.04 64 hosts and all kinds of guests from DOS, Windows, Linux to Chromium OS.

    I have never used official Import / Export appliance, in our company we use this easy technique.

    Backup

    To create backup of your VirtualBox machine, you need to find out, where is the default directory with virtual machines, in Ubuntu it is /home/$user/VirtualBox VMs, in Windows 7 it is C:\Users\$Username\VirtualBox VMs.

    In this directory, there are subdirectories with names of the virtual machines, select the directory with machine you want to backup and copy it all to your backup location.

    In Linux, if you use command line, do not forget to use quotes with name of the directory “VirtualBox VMs”, there is a blank space after x. In cp command, use -a (archive) options to preserve all attributes including file’s groups ownership.

    Restore

    Beware of

    Before running your guest VM on different host computer, make sure your host meets hardware requirements for guest OS, common mistake is to leave too much RAM reserved for guest VM, but also double-check number of CPU cores or shared folders section.

    You may use this method to switch between hosts, in our company, we use this method to move one particular machine between number of host OSes and all host machines have different hardware, still no problem, on Windows host, you need to restart the guest machine once or twice after detecting new hardware, changing screen resolution or installing Guest Additions.

    To achieve best performance and prevent unexpected problems, you should always try simulation first in test environment before switching to production environment. You may want to prefer same version of VirtualBox installed on guest OS’s, in our company we don’t and it still works all fine, but we try to always have the most recent version of VirtualBox installed.

    Once you are done, manage .vdi size and defragment

    Once you have finished backing up, you may find your backup .vdi file little bit oversize. This happens a lot on VMs that are used to work with larger files, or large file volumes. In expandable drives, large file copied or downloaded to virtual machine can take space even if deleted, because deleting does not compact the virtual hard drive afterwards. If you have VDI expandable size hard drive (.vdi), you are in luck, because there is an easy way to shrink the .vdi volume size using vboxmange command, acts as de-fragmentation tool too.

    In this article, we will show you how to export the virtual machine from one Oracle VM VirtualBox and then import it to another Oracle VM VirtualBox. You can do it between two Windows machines or you can import it to the same machine for the purpose of testing and learning more. This article consists of two parts, the first one is about exporting the virtual machine and the second one about the importing of the virtual machine. So, let’s start with the first part.

    Export the Virtual Machine to the Oracle VM VirtualBox

    1. Log on the Windows 10
    2. Open Oracle VM VirtualBox
    3. Shutdown the virtual machine that you want to export. Right click on the virtual machine, click Close and then Power Off. The virtual machine will be powered off in a few seconds.
    4. Click on the File in the main menu and then click Export Appliance. You can also export the virtual machine by pressing CTRL + E on the keyboard.How to backup and move virtualbox machines
    5. Under Virtual Machines to export select the virtual machine that you want to export and then click Next. At the bottom of the window, you can choose Expert Mode which will provide you with more information to export the virtual machine. We will use Guide Mode.How to backup and move virtualbox machines
    6. Under Appliance settings choose the format of the virtual machine, create file name and location. Under Format, there are three different options including Open Virtualization Format 0.9, 1.0 and 2.0. The Open Virtualization Format supports only ovf or ova extensions. If you use the ovf extension, several files will be written separately. If you use the ova extension, all the files will be combined into one Open Virtualization Format archive. We will keep the default format: Open Virtualization Format 1.0.How to backup and move virtualbox machines
    7. Under Virtual system settings write the descriptive information which will be added to the virtual machine and then click Export. You can change it by double clicking on individual lines. If you don’t want to add descriptive information just click on Export. In our case, we will not add any descriptive informationHow to backup and move virtualbox machines
    8. Wait until Oracle VM VirtualBox finishes exporting of the virtual machineHow to backup and move virtualbox machines
    9. Congratulations. You have successfully exported your virtual machine.

    Import the virtual machine to the Oracle VM VirtualBox

    In the second part, we will import the virtual machine that we exported in the previous step. As already mentioned, you can import the virtual machine into Oracle VM VirtualBox on another Windows machine or on the same machine as in the purpose of the testing.

    1. If you have closed the Oracle VM VirtualBox, please open it again
    2. Click on the File and then click on Import Appliance. You can also import the virtual machine by pressing CTRL + I on the keyboard.How to backup and move virtualbox machines
    3. Under Appliance to import choose the source to import the virtual machine from. This can be a local system to import the OVF archive or one of the known cloud service providers to import cloud VM from. Under File choose the file that you have exported in the previous partHow to backup and move virtualbox machines
    4. Under Appliance settings perform the initial configuration such as the name of the virtual machine, guest operating system and resources (CPU, RAM, DVD, USB, Sound Card, Network Adapter, Storage Controller) and then click Import.How to backup and move virtualbox machines
    5. Wait until Oracle VM VirtualBox finishes the procedure of importing the virtual machineHow to backup and move virtualbox machines
    6. Congratulations. You have successfully imported your virtual machine.
    7. Right click on the virtual machine, click Start and then click Normal StartHow to backup and move virtualbox machines

    How to backup and move virtualbox machines

    If you use VirtualBox to run different operating systems on your computer, you may be wondering how to copy text from your host machine into the guest machine and vice versa. You may have thought that VirtualBox Guest Additions provides this feature, but it doesn’t.

    VirtualBox Guest Additions provides several useful features, such as shared folders and improved performance, and we do recommend installing the Guest Additions. However, to enable copying text between the host machine and guest machine, you must change a setting in VirtualBox for the virtual machine.

    To enable copying text between the host and guest machines, first make sure the virtual machine for which you want to enable the setting is powered off. Then, select the virtual machine in the list in the VirtualBox Manager (if it’s not already selected) and click Settings on the toolbar.

    How to backup and move virtualbox machines

    On the Settings dialog box, make sure General is selected in the left pane. Select the Advanced tab on the right and select Bidirectional from the Shared Clipboard drop-down list. This will allow you to copy text in both directions, from the host to the guest and vice versa. Click OK to accept the change and close the dialog box.

    How to backup and move virtualbox machines

    You can also select Bidirectional from the Drag’n’Drop drop-down list. This allows you to drag and drop files between the host and guest machines.