You Got A Question? Ask    GNOME Community!


What is the best backup tool for 2012? What else, Virtual Box!

This post was made with an older stylesheet

Gnome Boxes

Gnome Boxes solves the problem of “complication” and with a few straight forward “next, next clicks” you have a running virtual machine.

This is how a boot loader should look like in the future. Power On your PC and you have 4-5 OS to work with simultaneously. While Gnome Boxes had a major revamp in version 3.6, isn’t ready yet to be used as a backup tool. However is perfect to try things on it, like distros and alpha software, but it isn’t recommended to use it for “work”.

Backup files with Vbox

In this post I’ ll show you how to:

  • Access a virtual box with network
  • Share folders of the Host (your machine) with the Client/Guest (Virtual Machine)
  • Share folders of the Client/Guest with the host (the reverse)

By sharing folders you can store your backup in your virtual box. If you run the VBOX with an external disk, you can just move it, and use it in every other machine. However to access your data you need another VBox host. But this isn’t real an issue.

The real advantage of using Virtual Box as a backup solution comes when we do development. In my case I use a CentOS that I have setup various Rails environments with some databases. If had these in my real machine and I had to upgrade it or change distro (that I actually did), to backup and then restore all these would taken days. Also, it is a safer way to keep your data in case that you do experiments in your machine.

I recently deleted (twice inside 1 month!!) my hard disk drive!  VBox actually saved my life :)

It sounds very strange to me when people prefer to run their web-development on their machines without virtualbox. Anyway..

Virtual Box Installation.

Having a running Virtual Box is pretty much the same as having a real machine. There aren’t serious limitations or constraints and actually it saves you money and physical space. Visit Virtual Box download section and pick your distro. By the way a useful hint; below are the VB repos that you can access and download any version for every Operating System. VB is under GPL license.

http://download.virtualbox.org/virtualbox/

Ubuntu users can add in /etc/apt/sources.list

deb http://download.virtualbox.org/virtualbox/debian your-ubuntu-version contrib

You should replace your-ubuntu-version with your Ubuntu version. quantal, precise, natty ..and so on.

Then add the signature key

wget -q http://download.virtualbox.org/virtualbox/debian/oracle_vbox.asc -O- | sudo apt-key add -

and then install it

sudo apt-get update
sudo apt-get install virtualbox-4.2

To run the rest of the tutorial you also need to install the extension pack.  Download and double click it to install.

Set up a Virtual Machine

First you have to download the distro of your preference. In this tutorial I use Ubuntu 12.04 64bit, Server Edition, which hasn’t graphical interface. Not good choice :) By the way the rest of my system is an Ubuntu Gnome 12.10 and Virtual Box 4.2.

Just go with the defaults (next next next..). When you finish, press start and select the ISO image. Then installation begins and everything is like in a real box.

Install Guest Additions

You need to install the guest additions from the Vbox Devices Menu.

A Graphical install should start. If not, you have to mount the virtual cd-rom on your own. Inside VB in a terminal

sudo mount /dev/sr0 /mnt/

Then go into /mnt and run the VBoxLinuxInstaller.sh. The installer script might failed and ask some additional packages. These are dkms, gcc and linux-headers. 

After installation reboot the VB Client. On Settings->Display check the 3d Acceleration option to enable the 3d support in client.

You have also add your user to the vboxusers group in Host machine

sudo usermod -a -G vboxusers Your_Username

You have to logout/login for this change to take effect! I did it some fast, but setup a virtual box is easy anyway, so no reason to go through every step.

1. Set up a network connection

Files are shared over a network, in other words, you access remote files. The Network here is virtual since the two boxes (guest and host) are on the same real machine. But the steps for a connection is pretty much the same as in real networks.

I have installed a Lamp and SSH server in Guest. So I just connected with SSH. I also can hit my browser in 192.168.1.3 and see the apache running. So the network connection is working out of box. You can set up and an FTP server and move files, but that would be stupid :)

2. Share Files from Host to the Guest

Instead of using FTP to transfer files from Host to Guest, lets try to share a folder.

This is the folders structure I have setup in the two machines. The goal here is to move files into Host{local} and can access them from Guest{remote}.

Open Virtual Machine Settings and go to Shared Folders tab (or by Devices->Shared Folders.. Menu). Here I picked my Host{local} (~/Shared/vbox/local) directory and I named it local. You can make this also with the terminal:

VBoxManage sharedfolder add "Ubuntu Server" -name "local" -hostpath /home/alex/Shared/vbox/local

Where “Ubuntu Server” is the name of the virtual machine in VirtualBox, and “local” is the name of the share as the guest machine will see it. The hostpath must be a fully-qualified path.

 

Then I mount the Host{local} to Guest {remote}

sudo mount -t vboxsf local remote

Local is the name I gave in VBox, and remote is the folder in Guest. Now every file I can create in Host{local} (ie, test, test1, test4), I can see it in Guest{remote}. Also I can move files from Guest to Host this way. This is a remote directory, so if we break the connection the data are lost from Guest (but the remain in Host). So we have to copy them in another folder if we want to keep them.

We can place this inside fstab if we want an auto-mount.

3. Share Files from Guest to the Host

Lets try the other way around, view in the Host files from the Guest. That is more useful because we can work directly to Guest from our Host system seamlessly. That means we can open an IDE like Aptana in the Host and editing files in our Lamp at Guest. Isn’t web-developing better this way? But you can also edit video like that, store and view your movies, etc etc..

Virtual Box does not support this reverse connection, so I will make it with Samba. Ubuntu Server doesn’t have a graphical interface so I have to use terminal. First install samba server.

sudo apt-get install smbfs samba

Then on Guest system I will add the user (alex) to samba accounts. Samba accounts are separated  from main accounts

sudo smbpasswd -a alex

Now we have to edit the samba configuration and add the sharing point

sudo vi /etc/samba/smb.conf

In the very end of the file add:

[remote]
path = /home/alex/Shared/remote
available = yes
valid users = alex
read only = no
browsable = yes
public = yes
writable = yes

[remote] is the name that network will see our file share. Obviously you have to use your own info :)
Then restart samba server and test if it is working

sudo restart smbd
sudo testparm

We are set! That (samba setup) was a bit useless because with graphical interface sharing files is just two clicks procedure in Nautilus. So it is better to install a Guest machine with some kind of desktop. The “real” Linux-ers of course prefer the console :)

So we can now share files recursively :)

Use Virtualization!

Even if you have a spare old computer that you use it for a server is recommended to work inside a virtual box. Moving a virtual box it just involves to copy the VDI file, and that makes back ups easier!


 
  We can't watch comments unless G+ provides an API or if you send a notification, e.g +World Of Gnome
     Sometimes is better to place your questions on GNOME Community
  • http://varemenos.com/ Adonis K. (Varemenos)

    But won’t that cause more stress to the server?

    • alex285

      If you have a second box as server, you won’t see any difference in speed. Besides you can open it only when you work in web-development.

  • http://www.facebook.com/brett.legree Brett Legree

    I have been doing this for years and it is a great way to work.

    You can play with your toys, break them, and then like magic they are new again! Since I spend a lot of time studying GNOME, I keep virtual machines for the latest releases of Fedora, openSUSE, and Ubuntu as well as experimental builds of those. It is interesting to see the subtle differences across the distros.

  • mythsmith

    I prefer the simpler, quicker, smaller, transparent old wild schroot: http://www.imsc.res.in/~kapil/goodies/schroot.html. You don’t need to virtualize anything as long as you just need to run many Linux boxes and easily backup.

  • opsokkebalje

    What’s with the title? Seriously, virtualization is not a backup tool and doesn’t make backups any easier.
    Perhaps it FEELS more convenient to have a diskimage file containing everything but those diskimages just
    needs to be backupped as normal files do. And the host on which virtualbox is running?
    Well, you need to backup that as well as in “how it’s been done since decades”. Yes, with conventional methods…

    • alex285

      Virtualization provides environments (from development to multimedia) that you can keep running for years while you can access it from any PC. You can’t “just” backup a Mail Server or Databases. I am not talking about “hardware failures” backups.

  • Beau Breon

    You might be interested in Vagrant for your development VMs, check it out if you haven’t heard of it before… http://vagrantup.com/

    • alex285

      Thanks I didn’t know this, I will try it asap.

  • http://www.facebook.com/CubedRoot Lynn Dixon

    What the hell kind of backup solution is this? Only from the warped minds that comes Gnome-Shell would something like this be a “good idea”. This needs to be removed from the internet before some poor pitiful Linux newbie actually begins to think this is a good idea.

    • alex285

      A Virtual Machine is exactly the same as having a second PC just for backups and development. How this is bad solution? I know plenty of companies that use virtualization to backup their systems and files.

  • Pingback: VirtualBox as backup « 0ddn1x: tricks with *nix

  • Pingback: My Own Cloud, My Own Gnome Files! | woGue

  • sllih

    Thank you for the article, which is a great tip for web developers. A typical desktop distro (latest Ubuntu or Fedora) is usually not a good one for a production web server (Debian, Ubuntu LTS, CentoOS). Now we can work in preferred desktop distro and test code changes in different one. Shared folders are crucial feature here.

  • Pingback: Links 30/9/2012: Slackware 14.0 is Out | Techrights