问题
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?
回答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.
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
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
来源:https://stackoverflow.com/questions/60286908/how-can-i-recover-my-mysql-databases-from-a-homestead-vagrant-virtualbox