Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I recover my MySQL databases from a Homestead Vagrant VirtualBox?

I was running Homestead v8.2.0 and laravel/homestead (virtualbox, 7.1.0) and Vagrant 2.2.4. I needed to upgrade because I wanted PHP 7.4 support.

Laravel docs said that destroying the vagrant box first would be necessary, but I knew I didn't want to destroy my original box since I still had valuable data in there. So I figured I'd try merely "updating" it, just in case that might work.

(I was very careful not to use destroy because I didn't want to lose any of my MySQL databases.)

When I ran vagrant global-status I saw:

id       name          provider   state   directory
------------------------------------------------------------------------------
5620b14  vboxHomestead virtualbox running C:/code/Homestead

So I used git to checkout v10.2.0 of Homestead.

And I ran vagrant box update. I was not surprised that this approach didn't work, given the Laravel docs.

So then I figured: instead of updating my current box, I'll just create a new box alongside it (still not destroying the old box).

So I copied C:/code/Homestead to a new directory C:/code/HomesteadB.

I upgraded to Vagrant 2.2.7. I ran vagrant box add laravel/homestead and saw the new laravel/homestead (virtualbox, 9.2.0) (notice the higher version number). I ran vagrant up, and I continued to enjoy my new box running PHP 7.4. Everything seemed to be going to plan.

Later, when I felt inspired to go back to my old box and recover all the old data there, I noticed that the MySQL databases are missing!

But this doesn't make any sense because I never deleted them. And I never destroyed the box (I'm still able to run vagrant up in the old C:/code/Homestead and then vagrant ssh). And I wouldn't think that vagrant box update would have deleted MySQL databases either.

Where are they, and how can I recover them?

UPDATE in response to https://stackoverflow.com/a/60411945/470749

myuser@ABCDESK MINGW64 /c/code/Homestead ((v10.2.0))
$ vagrant box list
laravel/homestead (virtualbox, 5.2.0)
laravel/homestead (virtualbox, 6.0.0)
laravel/homestead (virtualbox, 7.1.0)
laravel/homestead (virtualbox, 9.2.0)
redash/dev        (virtualbox, 0.1.0)

$ VBoxManage list vms
"Redash" {29166fde-e0bf-4f31-8efc-58a66afd78e5}
"redash_default_1502117350190_63240" {0b5935af-288a-4e4d-aa8a-ee04f42e3235}
"macOS 10.12 High Sierra" {37b09cb2-10cd-4e1a-8e2c-aefdb1a348c6}
"macOS Sierra" {f010233b-d058-4a6e-9493-5c4d68e99ef1}
"macOS High Sierra 10.13" {741f0d4d-7f16-4f42-993b-4d301ef68125}
"default" {f3e8f33d-0ca3-452d-9ae6-d93e5e412fbb}
"vboxHomestead" {0706d0b0-d31b-4137-9e97-f86b827f1530}
"vboxHomestead2020-01-31" {1ef6f202-9d81-4d41-a4b9-adaab7b12014}

$ ls -lah /c/code/Homestead/.vagrant/machines/
total 0
drwxr-xr-x 1 myuser 197121 0 Aug 27  2017 ./
drwxr-xr-x 1 myuser 197121 0 Apr  8  2019 ../
drwxr-xr-x 1 myuser 197121 0 Apr  4  2017 homestead-7/
drwxr-xr-x 1 myuser 197121 0 Aug 27  2017 vboxHomestead/

$ ls -lah /c/code/HomesteadB/.vagrant/machines/
total 0
drwxr-xr-x 1 myuser 197121 0 Jan 31 09:36 ./
drwxr-xr-x 1 myuser 197121 0 Jan 31 09:25 ../
drwxr-xr-x 1 myuser 197121 0 Jan 31 09:25 homestead-7/
drwxr-xr-x 1 myuser 197121 0 Jan 31 09:25 vboxHomestead/
drwxr-xr-x 1 myuser 197121 0 Jan 31 09:36 vboxHomestead2020-01-31/

$ ls -lah /c/code/Homestead/.vagrant/machines/vboxHomestead/virtualbox/
total 19K
drwxr-xr-x 1 myuser 197121    0 Apr  8  2019 ./
drwxr-xr-x 1 myuser 197121    0 Aug 27  2017 ../
-rw-r--r-- 1 myuser 197121   40 Apr  8  2019 action_provision
-rw-r--r-- 1 myuser 197121   10 Feb 18 12:20 action_set_name
-rw-r--r-- 1 myuser 197121  138 Feb 18 11:44 box_meta
-rw-r--r-- 1 myuser 197121    1 Apr  8  2019 creator_uid
-rw-r--r-- 1 myuser 197121   36 Apr  8  2019 id
-rw-r--r-- 1 myuser 197121   32 Apr  8  2019 index_uuid
-rw-r--r-- 1 myuser 197121 1.7K Apr  8  2019 private_key
-rw-r--r-- 1 myuser 197121  653 Feb 18 12:22 synced_folders
-rw-r--r-- 1 myuser 197121   17 Apr  8  2019 vagrant_cwd

$ ls -lah /c/code/HomesteadB/.vagrant/machines/vboxHomestead/virtualbox/
total 19K
drwxr-xr-x 1 myuser 197121    0 Jan 31 09:25 ./
drwxr-xr-x 1 myuser 197121    0 Jan 31 09:25 ../
-rw-r--r-- 1 myuser 197121   40 Jan 31 09:25 action_provision
-rw-r--r-- 1 myuser 197121   10 Jan 31 09:26 action_set_name
-rw-r--r-- 1 myuser 197121  138 Jan 31 09:25 box_meta
-rw-r--r-- 1 myuser 197121    1 Jan 31 09:25 creator_uid
-rw-r--r-- 1 myuser 197121   36 Jan 31 09:25 id
-rw-r--r-- 1 myuser 197121   32 Jan 31 09:25 index_uuid
-rw-r--r-- 1 myuser 197121 1.7K Jan 31 09:25 private_key
-rw-r--r-- 1 myuser 197121  653 Jan 31 09:25 synced_folders
-rw-r--r-- 1 myuser 197121   18 Jan 31 09:25 vagrant_cwd

$ ls -lah /c/code/HomesteadB/.vagrant/machines/vboxHomestead2020-01-31/virtualbox/
total 19K
drwxr-xr-x 1 myuser 197121    0 Jan 31 09:37 ./
drwxr-xr-x 1 myuser 197121    0 Jan 31 09:36 ../
-rw-r--r-- 1 myuser 197121   40 Jan 31 09:37 action_provision
-rw-r--r-- 1 myuser 197121   10 Feb 24 18:45 action_set_name
-rw-r--r-- 1 myuser 197121  138 Feb  4 11:56 box_meta
-rw-r--r-- 1 myuser 197121    1 Jan 31 09:36 creator_uid
-rw-r--r-- 1 myuser 197121   36 Jan 31 09:36 id
-rw-r--r-- 1 myuser 197121   32 Jan 31 09:36 index_uuid
-rw-r--r-- 1 myuser 197121 1.7K Jan 31 09:37 private_key
-rw-r--r-- 1 myuser 197121  654 Feb 24 18:46 synced_folders
-rw-r--r-- 1 myuser 197121   18 Jan 31 09:36 vagrant_cwd

$ cat /c/code/HomesteadB/.vagrant/machines/vboxHomestead2020-01-31/virtualbox/id
1ef6f202-9d81-4d41-a4b9-adaab7b12014

$ cat /c/code/HomesteadB/.vagrant/machines/vboxHomestead/virtualbox/id
0706d0b0-d31b-4137-9e97-f86b827f1530

$ cat /c/code/Homestead/.vagrant/machines/vboxHomestead/virtualbox/id
0706d0b0-d31b-4137-9e97-f86b827f1530
like image 983
Ryan Avatar asked Feb 18 '20 17:02

Ryan


People also ask

How do I access MySQL in Homestead?

To connect to your MySQL or Postgres database from your main machine via Navicat or Sequel Pro, you should connect to 127.0. 0.1 and port 33060 (MySQL) or 54320 (Postgres). The username and password for both databases is homestead / secret .

What is Homestead VM?

Laravel Homestead is an official, pre-packaged Vagrant box that provides you a wonderful development environment without requiring you to install PHP, a web server, and any other server software on your local machine. Vagrant provides a simple, elegant way to manage and provision Virtual Machines.


1 Answers

I think you're mixing the box and the VM - I made an answer here to explain the differences but basically once you have created a VM (Virtual Box resource) vagrant is not using the box.

The issue might that you made a copy but did not remove the reference to the VM from your poject folder, so vagrant did continue to operate on the same VM but using new box reference.

What you need to check is that in your copy of your project (C:/code/HomesteadB) the .vagrant/machines/<default>/virtualbox/id - this is the id of your VirtualBox VM corresponding to your project before update with all your data in.

Open Virtualbox and check that this VM is still there - (you can check in the VirtualBox folder of all VM) If its not there, your VM is gone and you cannot get your data back, unless you have some Hard Drive backup with the reference of the VM and copy of your VirtualBox directory

I am still unsure how it would happen, because vagrant up after the vagrant box update should not have rebuilt the VM. If it is so, the issue has been that when you copied your project, you did not remove reference of the VM from the .vagrant directory so it was still interacting with the existing VM. If you did remove the vagrant id reference after you copied your project, you would have been safe and vagrant would not have been able to touch the existing VM because there was no link.

You should open VirtualBox and check the following 2 VMs

  • "vboxHomestead" {0706d0b0-d31b-4137-9e97-f86b827f1530}
  • "vboxHomestead2020-01-31" {1ef6f202-9d81-4d41-a4b9-adaab7b12014}

open them and check if you can find your MySQL data in those VM, if not in those VM, then it will be lost.

I am a bit afraid (for you) that the VM 0706d0b0-d31b-4137-9e97-f86b827f1530 is the one you want but it has been recreated from the new laravel folder

like image 199
Frederic Henri Avatar answered Nov 15 '22 11:11

Frederic Henri