Backup/Restore All Databases In Laravel Homestead

While destroying a Vagrant box can be a necessary evil, dealing with the repercussions of losing all your databases in the process can be a real pain in the butt. Especially if you are developing many sites under a single Homestead box.

I use TextExpander to expand these commands complete with a dynamic timestamp, which is nice. I use ;mysqlb and ;mysqlr as shortcuts to make the process quick and easy.

Be sure you run these commands while ssh’d into your Homestead box or they won't work.

It’s also worth noting that it’s best to run this command from within a shared folder you have setup to be synced with your local machine. In my case, that folder is /home/vagrant/Sites.

Backup All Databases

mysqldump -u homestead -psecret --all-databases > homestead-20150727_0913.sql

Restore All Databases

mysql -u homestead -psecret < homestead-20150727_0913.sql