skip to Main Content

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

2

Answers


  1. Your only chance is to hope that vagrant box update does not do a fresh, clean install of mysql. I would try out a few things before giving up all hope:

    1) check your vm provider (VirtualBox??) see how many vms are listed there. IF there are more then you expect, boot up the odd ones from the VirtualBox interface and see if your data exists on the odd machine that you think shouldn’t be there. This has very low chances of working to be honest, but it’s worth a shot. It should cover you in the case that your old box still exists somewhere in its old state. If you find anything, do mysqldump and then restore in the new
    box.

    2) vagrant ssh in your new machine and cd /var/lib/ look for folders related to mysql. This should cover you in case the vagrant update command hasn’t cleared your mysql data dir entirely. I fear it might have 🙁 but do check if there’s files that look like your old tables names or schema names. Id you find anything, change the mysql data dir to point to that folder, see this https://dba.stackexchange.com/questions/14320/how-can-i-move-a-mysql-database-to-another-drive . Do a mysqldump and restore in the new box

    3) use VBoxManage list vms to get a list of vagrant box ids. If the old one is still there, you may be able to point vagrant to it. Check this post: https://stackoverflow.com/a/37963066/4183810 . If you get access to your data, do a mysqldump of your data and restore it on the new box.

    There are some chances this could work, but unfortunately if you can’t find your data, it’s either gone or unreachable, so you might have to accept your fate 🙁

    Login or Signup to reply.
  2. 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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search