6

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
Ryan
  • 22,332
  • 31
  • 176
  • 357
  • Check your box db with some gui tools like SequelPro. If exists, export data to safe place, then upgrade box and import db. I'm not homestead user, but on daily task I use vagrant boxes where we add before destroy command to backup db. – Salines Feb 18 '20 at 21:45
  • Do you have a db backup? – Tarasovych Feb 19 '20 at 11:03
  • @Tarasovych No, hence my question. – Ryan Feb 19 '20 at 14:00
  • Do you have your db in the old box? – Tarasovych Feb 20 '20 at 07:11
  • @Tarasovych No, which is why I posted this question and why it says "I noticed that the MySQL databases are missing". – Ryan Feb 20 '20 at 15:59
  • @Ryan so, if you don't have a backup, and you don't have a source you can get a backup from, how do you want to get your database back? – Tarasovych Feb 21 '20 at 09:48
  • @Tarasovych The reason I posted this question is because the database must exist *somewhere*, given that I never ran `destroy`, and I never dropped the databases, and I never deleted files. So I'm hoping someone will teach me why they *seem* to be missing and where I can find them. – Ryan Feb 21 '20 at 18:13
  • When you say that you _noticed_ that your databases are missing, exactly how did you notice that? Did you use `mysql CLI` client? – linuxartisan Feb 23 '20 at 03:39
  • @linuxartisan Yes. When I use `vagrant ssh` into my original box and then go into MySQL in the command line and run `show databases;`. – Ryan Feb 23 '20 at 13:52
  • If you hadn't your database mapped to the host machine, or you didn't use separate VM for the database, your database is gone. – Tarasovych Feb 24 '20 at 07:16
  • @Tarasovych `vagrant box update` deletes the databases? Are you sure? Why would it do that? – Ryan Feb 24 '20 at 13:56
  • `vagrant box update` does not know anything about what's inside your box. So, no, it does not delete databases. Probably the issue does not relate to `vagrant box update` – Tarasovych Feb 24 '20 at 14:38

2 Answers2

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

Frederic Henri
  • 51,761
  • 10
  • 113
  • 139
  • Thanks for your response. I updated my question to add more information. I think I *may* have run `/c/code/HomesteadB vagrant up` one time before remembering to edit my `C:\code\HomesteadB\Homestead.yaml` to say `name: vboxHomestead2020-01-31` instead of `name: vboxHomestead`. And it also says `mysql8: true`. https://laravel.com/docs/6.x/homestead#installing-optional-features I wonder if that caused it to nuke my existing MySQL databases. – Ryan Feb 26 '20 at 20:29
  • Thanks for your thoughts so far. Do you have any new thoughts before the bounty expires tomorrow (now that I've added more information)? Thanks. – Ryan Feb 28 '20 at 15:43
  • It doesn't need to rebuold the vm it just needs to reprovision it with new software and run the postinstall scripts. (defined by whoever makes the box) – liviu blidar Mar 02 '20 at 08:03
  • I didn't notice your edit to your answer, and SO didn't notify me! I just tried `vim /c/code/HomesteadB/Homestead.yaml` and edited `name: vboxHomestead2020-01-31` back to `name: vboxHomestead`. Then `vagrant up` (I also tried with `vagrant reload --provision`), `vagrant ssh`, and `mysql`, `show databases`. No luck. Thanks though. Really mysterious and frustrating that I somehow dropped databases during an upgrade. – Ryan Mar 04 '20 at 16:25
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 :(

liviu blidar
  • 351
  • 4
  • 16
  • Thanks for your response. I updated my question to add more information. I think I *may* have run `/c/code/HomesteadB vagrant up` one time before remembering to edit my `C:\code\HomesteadB\Homestead.yaml` to say `name: vboxHomestead2020-01-31` instead of `name: vboxHomestead`. And it also says `mysql8: true`. https://laravel.com/docs/6.x/homestead#installing-optional-features I wonder if that caused it to nuke my existing MySQL databases. – Ryan Feb 26 '20 at 20:29
  • Thanks for your thoughts so far. Do you have any new thoughts before the bounty expires tomorrow (now that I've added more information)? Thanks. – Ryan Feb 28 '20 at 15:44