Backing up your Hyperledger virtual image and restoring it on another computer

Introduction

I have had a certain level of superstition about restoring from backups.

This week I found backing up my Hyperledger Fabric virtual image was easy but restoring it was not that simple.

In this post, I will back up my Hyperledger Fabric virtual image with Eclipse running on it from my desktop and restore it on my laptop.

It’s important to remember that our virtual image is special: it cannot be backed up and restored only with Oracle Virtualbox. Why? Because we have made extensive use of folders synced with the host OS via the Vagrant tool, to install IBM middleware, as well as the fabric-sdk-java. This is why we will have to jump through a couple of extra hoops to re-sync our vm with Vagrant after we have restored it on the laptop. We also have to backup and restore those synced folders on the host OS under C:\gocode. Finally, it also explains why we always launch our vm with the “vagrant up” command.

Assumptions

  • You’ve read my previous two posts about Hyperledger
  • On the target laptop, I already installed Vagrant, VirtualBox, Cygwin and Go as described in my first post “Java SDK for Hyperledger Fabric 1.0 (IBM Blockchain) — Setting Up the Environment” right up to and including “Test Go in Cygwin”
  • 7-Zip is installed on both thesource and target machines. You can download it from http://www.7-zip.org/download.html
  • A temporary folder named C:\Temp exists on both the source and destination Windows computers
  • You know how to copy from a Windows command prompt (hint: menu > Modify > Select > drag the mouse to select > hit ENTER key to copy)
  • You have Notepad++ installed

Steps we will follow

  • Backup C:\gocode and the virtual image on the desktop
  • Restoring the virtual image on the laptop
  • Check if the “.vagrant” folder still exists
  • Reassociate Vagrant with the correct virtual image identifier
  • Test: step through the code of the Java end-to-end integration test in Eclipse

Backup C:\gocode and the virtual image on the desktop

If the virtual image is open, exit any SSH connection with shortcut CTRL-D (the same used in all SSH clients) or, aleternately, with the exit command.

If it is up, stop the virtual image with the command:

vagrant halt

16.png

Close any Cygwin prompt.

To be on the safe side, log out of your Windows session and log back in.

The Hyperledger folders are deeply nested, it’s preferable to back them up using the 7-zip tool.

In Windows Explorer, right-click on folder C:\gocode and select 7-Zip > Add to archive…

17.png

On my machine, I can’t save a zip file to C: so click the button and choose C:\temp

18.png

Click the Open button.

I choose to add today’s date to my zip file name:

10

I finally click the OK button and my folder is zipped. It takes a while.

11.png

Next, we open Oracle Virtualbox:

12.png

It’s important NOT to start the virtual machine at this point.

14.png

Select the Hyperledger virtual machine by clicking on it, then do menu File > Export Appliance :

13.png

In the Virtual machines to export window that comes up, select the hyperledger vm and click the Next > button:

15.png

We’ll select to backup the image as  file “C:\Temp\2017-05-24 hyperledger-bert.ova” and click the Save button.

In the Storage Settings window that comes up, change nothing and click the Next > button:

16

In the Appliance Settings window that comes up, click the Export button:

17.png

It will take a while:

18.png

OK, bacup is done.

Now copy files “2017-05-24 hyperledger-bert.ova” and “2017-05-24 gocode.zip” from C:\Temp\ to a USB stick and then carry that USB stick to our laptop.

Restoring the virtual image on the laptop

First, copy file “2017-05-24 gocode.zip” to the C: drive.

If the C:\gocode folder already exists, rename it to C:\gocodeOLD

Open Windows Explorer, right-click on file  “2017-05-24 gocode.zip” and in the context menu select 7-Zip > Extract Here

This will restore C:\gocode as it exists on the desktop.

Next, copy the file “2017-05-24 hyperledger-bert.ova” to C:\Temp

Open VirtualBox:

12.png

VirtualBox appears (here it is empty, with no vms):

1

menu File > Import Appliance…

2

Select file “C:\Temp\2017-05-24 hyperledger-bert.ova” and click the Next button:

3.png

Change nothing in the Appliance Settings window that comes up and click the Import button:

4.png

This takes a while:

5.png

Now for a very important step: we need to start the virtual machine in Virtualbox without using Vagrant. This will create a VM identifier, which we will then associate with Vagrant by manually editing a configuration file Vagrant looks at.

Click on the image name:

6.png

Next, click the Start button:

7

Ignore the following warning and click OK:

8.png

Close the annoying messages that are preventing you from logging in by clicking the X buttons:

9

Now you can see the login prompt. Login as user “ubuntu”:

10.png

Next, do the command to launch the graphical user interface:

sudo startxfce4&

This will open up the graphical user interface. Click the X button to close the annoying message preventing us to get to the top navigation menu:

11.png

Now let’s log out:

12.png

In VirtualBox > menu File > Close > Power off the machine > OK button

13.png

Close VirtualBox.

Check if the “.vagrant” folder still exists

If in the previous steps you deleted a previous virtual image in Virtualbox before restoring, you might find that required vagrant files will be missing because thay also have been deleted. You can check to see if this happened by verifying the following folder still exists or not on Windows:

C:\gocode\fabric_java_latest\fabric\devenv\.vagrant

If it no longer exists, rename the folder C:\gocode to C:\gocodeBAK and repeat the unzip operation of file  “2017-05-24 gocode.zip“.

Reassociate Vagrant with the correct virtual image identifier

Open a Windows command prompt and do command:

vboxmanage list vms

This will give us the ID we mentioned before, here between the curly braces:

14.png

Copy the value. Your value will be different, of course, than mine:

ab02bc68-7817-4654-96f0-c06c446abe9a

Next, launch Notepad++ and open file:

C:\gocode\fabric_java_latest\fabric\devenv\.vagrant\machines\default\virtualbox\id

In that file, replace the existing value with ab02bc68-7817-4654-96f0-c06c446abe9a and DO NOT add a carriage return at the end of the line (i.e. this text file must have only one line in it). Don’t forget to save:

15.png

Open a new Cygwin prompt AS AN ADMINISTRATOR and type the commands:

cd /cygdrive/c/gocode/fabric_java_latest/fabric/devenv/

vagrant up

The Virtualbox window will come up. Log in:

16.png

Again, do the command to launch the graphical user interface:

sudo startxfce4&

17.png

Test: step through the code of the Java end-to-end integration test in Eclipse

Double-click to start Eclipse Neon, accept the workspace.

Let’s check if we can still step through code. A quick check confirms our breakpoint in Chain.java is still there:

19.png

First we need to start the peers. Open a terminal and type the commands:

cd /opt/gopath/src/github.com/hyperledger/fabric/sdkintegration

docker-compose down;  rm -rf /var/hyperledger/*; docker-compose up --force-recreate

We leave this terminal window open.

Let’s try to run the end to end integration test again in Debug mode:

20.png

And it breaks at the expected line, as before:

21.png

All good!

(end of post)

Bertrand Szoghy, 2017-05, Quebec City.

Advertisements

One thought on “Backing up your Hyperledger virtual image and restoring it on another computer

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s