1. Home
  2. Linux
  3. Backup a virtual machine on linux with virtualbox

How To Backup A Virtual Machine On Linux With VirtualBox

Linux is often used for virtualization, and one of the most popular virtualization tools that people use is Oracle’s VirtualBox. It’s a great tool that makes it very easy to virtualize all different types of operating systems. In this article today, we’ll cover all of the ways users can backup a virtual machine.

SPOILER ALERT: Scroll down and watch the video tutorial at the end of this article.

Keep in mind that though some of the instructions of this article focus on Linux, it is possible to accomplish roughly the same thing on other platforms. Learn more about VirtualBox for your operating system here.

Backups Inside A VM

A great way to backup a virtual machine with VirtualBox, especially on Linux is to use the snapshot feature. With this feature, you can instantly save the state of the OS you are virtualizing, and restore it at any time.

To create a snapshot, you’ll first need to start up the VM. Once it’s on, press right Ctrl + T on the keyboard to open up the snapshot dialog. Alternatively, select “Machine,” then “Take a snapshot” to start the backup process.

Under “Snapshot Name,” fill out the name of the snapshot. Be sure to use creative names, especially if you plan to create many different snapshots. Using poor naming techniques could make it hard to tell the difference between backups, and confuse you.

When you’ve filled out the name of the snapshot, go to “Snapshot Description.” Use this section to write out a brief, detailed description of the purpose of the backup. Using the description feature is a great way to ensure that you don’t forget and mix up backups. With all the information filled out, click “OK” to create the snapshot.

You can restore from different snapshots at any time. To do this, close the VM (right Ctrl + Q). Then, in the main VirtualBox window, look for the arrow next to “Machine Tools” and click on it. Inside of the snapshot manager, select any of the backups you’ve created and click the “restore” button to change the state of the VM. Alternatively, delete any of them by selecting a snapshot and clicking “delete.”

Exporting VMs

Need to back up a VM to send to a friend, co-worker, or just for safekeeping? If so, consider checking out the “Export Appliance” feature in VirtualBox. Keep in mind the VirtualBox tool will not let you export any virtual machine as an appliance if it is running. Save any data, and power down (right Ctrl + Q).

Note: exporting a VM as an appliance doesn’t save machine snapshots. If you need a complete backup, follow the archiving method instead.

Create a snapshot of your VM by clicking “File,” then “Export Appliance.” Doing so will open up a wizard tool that will walk you through the exporting process. Be sure to keep it in basic mode, and stay away from “Expert Mode,” as most users won’t find it useful.

Using the export tool, select the machine you’d like to export, and click the “next” button. From here, you’ll be asked to choose the location of the exported appliance. The default location is ~/Documents and should work fine. Click the folder icon, if you’d like to export it elsewhere.

The default format that VirtualBox exports VMs in is “Open Virtualization Format 1.0”. It goes with this option, as OVF 1.0 is the most compatible. Need newer version? Click the drop-down menu and select a different one.

When you’ve selected the correct format, click “Next,” “Next” and then “Export” to export the VM.

The exporting process can take a bit of time, depending on the speed of your hard drive, the size of the VM, etc. Be patient, and let it complete!

To import an exported VM to another instance of VirtualBox, open up the Linux file manager, right-click on the OVA file, and click “open with VirtualBox.” It should start the importing process instantly.

Archiving VMs

If exporting your Virtual Machine as an appliance isn’t enough, you may want to consider just backing it up in a compressable archive instead. The downside to this is that the archive is a lot larger than a single OVA file. However, if you can’t go without snapshots, and configuration files this is entirely the best way to go. To archive, your VM, open up a terminal window and use the CD command to navigate to the Virtualbox folder.

cd ~/VirtualBox\ \VMs/

Then use the LS command to view the folder names for the different virtual machines. Keep in mind that some of the folders may have a space in the title. Spaces give the CD command trouble, as it can’t read them without certain characters. To fix this follow this example:

/folder\ \name/

Compress your VM folder with the tar command to start the backup process.

tar -jcvf virtual-machine-test

Once the archive is compressed, move it to your home folder with:

mv virtual-machine-test.tar.bz2 ~/

Feel free to take this tar.bz2 archive and save it to a server, your Dropbox account and etc.

Restore the backup at any time with:

tar -xvf virtual-machine-test.tar.bz2

Comments are closed.