Skip to main content

Reassociating Databases in Vagrant

Backstory

After using local development stacks like Wamp, Lamp and Mamp, I found myself frustrated by the numerous times that they would buckle and break under my use.  This may have been due to carelessness, but regardless, I found myself looking for more.  I discovered Vagrant and the idea of creating virtual environments so that breakages could be more easily contained and the possibility of accessing my virtual environments on multiple machines seemed a better way forward.

Admittedly far from an expert, I decided to use a base Drupal Vagrant environment and manipulate that.  So I started with the download found here: https://www.drupal.org/project/vdd.

How I Encountered the Problem

Recently I tried to connect a second machine to my remote vagrant files on Dropbox, but I noticed that when I did this, the vagrant instance rebuilt from the ground up on the second machine.  Strange I thought, but maybe that is how it works.  However, when I then tried to connect my initial machine back to the Vagrant files, I found that it did not connect to the original virtual environment, but created a new one, and lo and behold, all of my databases had gone! 🙁

I looked around the Internet for solutions to my dilemma and managed to cobble together a solution.

The Solution (Note That I am Using a Mac)

In a Terminal window, type: VBoxManage list vms

This should bring back a list of environments that you have created, this may look something like:

“drupal_default_1450942564332_75455” {7a90b041-d051-52d2-ae26-90a52aed3c16}

“wordpress_default_1451926386055_31236” {a9e62352-18a8-46f5-b014-6071d88a20f1}

“joomla_default_1454740887730_78173” {c719ed8e-2f6e-237e-8b22-0ec5320becc6}

Go to {vagrant project dir}/.vagrant/machines/default/virtualbox, and in this directory there should exist a file called id.  This file contains a record of the virtual environment that it is linked to Vagrant project that you are in.  Note that this identification will take the form of the second part of the above strings, e.g. “joomla_default_1454740827730_78173” {c719ed8e-2f6e-437e-8b22-0ec5320becc6} will look like c719ed8e-2f6e-437e-8b22-0ec5320becc6 as the first line of the file (note that no characters, including a new line should appear after this).  Identify the correct value, and place this in the id file.

I did this and I got numerous errors: default: Warning: Authentication failure. Retrying…

To resolve this it is necessary to place the correct private_key file into the {vagrant project dir}/.vagrant/machines/default/virtualbox directory.  This I recovered from Dropbox versioning and was a file that was a number of weeks old.  Having replaced that file, I was then able to use vagrant up to instantiate my environment and I was able to see all of the databases once again!  

Glory be! 🙂


jj

Mantra: live as much as you can in the short time we're on this awesome planet, but try to leave our shared home as nice as when you arrived, perhaps even nicer.

Leave a Reply

Your email address will not be published. Required fields are marked *