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.
- 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:
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…
On my machine, I can’t save a zip file to C: so click the button and choose C:\temp
Click the Open button.
I choose to add today’s date to my zip file name:
I finally click the OK button and my folder is zipped. It takes a while.
Next, we open Oracle Virtualbox:
It’s important NOT to start the virtual machine at this point.
Select the Hyperledger virtual machine by clicking on it, then do menu File > Export Appliance :
In the Virtual machines to export window that comes up, select the hyperledger vm and click the Next > button:
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:
In the Appliance Settings window that comes up, click the Export button:
It will take a while:
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
VirtualBox appears (here it is empty, with no vms):
menu File > Import Appliance…
Select file “C:\Temp\2017-05-24 hyperledger-bert.ova” and click the Next button:
Change nothing in the Appliance Settings window that comes up and click the Import button:
This takes a while:
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:
Next, click the Start button:
Ignore the following warning and click OK:
Close the annoying messages that are preventing you from logging in by clicking the X buttons:
Now you can see the login prompt. Login as user “ubuntu”:
Next, do the command to launch the graphical user interface:
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:
Now let’s log out:
In VirtualBox > menu File > Close > Power off the machine > OK button
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:
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:
Copy the value. Your value will be different, of course, than mine:
Next, launch Notepad++ and open file:
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:
Open a new Cygwin prompt AS AN ADMINISTRATOR and type the commands:
The Virtualbox window will come up. Log in:
Again, do the command to launch the graphical user interface:
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:
First we need to start the peers. Open a terminal and type the commands:
docker-compose down; rm -rf /var/hyperledger/*; docker-compose up
We leave this terminal window open.
Let’s try to run the end to end integration test again in Debug mode:
And it breaks at the expected line, as before:
(end of post)
Bertrand Szoghy, 2017-05, Quebec City.