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

前端 未结 2 1851
梦谈多话
梦谈多话 2021-01-18 08:48

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.

Larave

相关标签:
2条回答
  • 2021-01-18 09:28

    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

    0 讨论(0)
  • 2021-01-18 09:28

    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 :(

    0 讨论(0)
提交回复
热议问题