General questions about Bedrock-Ansible vs. VVV

These may be more general Vagrant questions, but I was working with Varying Vagrant Vagrants and it raised a couple of questions.

VVV keeps databases in a synced folder–but where are Bedrock’s DBs? Isn’t it really easy to wipe out a DB by accident if they aren’t in a synced folder? Are persistent DBs something you guys will be implementing in Bedrock?

More generally, where is Bedrock’s data stored (besides the www folder)? Does all that exist in the VM itself (which, on my computer, is under ~/VirtualBox VMs or something of that sort)?

Just curious.

The DB is persistent because it’s stored on disk technically. It’s stored on the VM’s disk which is then stored on your local disk. It’s not that transparent since the entire VM is in a .vmdk format (I believe).

But yeah, the VM’s are stored under ~/VirtualBox VMs. How exactly does VVV keep “databases” in a synced folder. You mean exports/dumps of them?

Anyway, I haven’t looked at VVV much lately but I don’t like their solution since it’s all shell scripts and not a proper provisioning system.

Yeah I think that’s accurate–there’s not a real provisioner in there.

The relevant part of their Vagrantfile that covers DB stuff:

  if File.exists?(File.join(vagrant_dir,'database/data/mysql_upgrade_info')) then
    if vagrant_version >= "1.3.0"
      config.vm.synced_folder "database/data/", "/var/lib/mysql", :mount_options => [ "dmode=777", "fmode=777" ]
    else
      config.vm.synced_folder "database/data/", "/var/lib/mysql", :extra => 'dmode=777,fmode=777'
    end
end

There’s also a backup folder in there that, if enabled, databases are dumped into on halt/suspend (or destroy) and then restored from on up. (This is all part of their provision.sh script.)

I haven’t personally used the DB backup/restore feature in VVV, but it’s nice to know that if I accidentally --provision, there’s a place where my working DBs are stored outside the VM.

Re-provisioning with bedrock-ansible shouldn’t overwrite the db. Ansible is idempotent and we’re using state=present: https://github.com/roots/bedrock-ansible/blob/master/roles/wordpress-sites/tasks/database.yml#L8

Meaning if the db is already present, it doesn’t do anything. And since wp core is-installed is true, it won’t re-install and overwrite it.

This is a new one for me. See that? This project is making me smarter.

Anyway–good to know. I was experimenting with using Bedrock as a MAMP replacement, but VVV was a little easier to wrap my brain around since it’s just Vagrant with some scripts. I guess having easy access to DB files is moot anyway (they weren’t particularly easy to get to the individual files under my previous XAMPP setup on Windows without PHPMyAdmin), but Vagrant boxes still feel a bit like black boxes to me, so it’s comforting to know where all the data is and that it’s backed up somewhere (even if it serves no practical purpose).

Basically, with VVV, it links the actual databases (the raw MySQL files) to a shared folder. So if you do delete the VM, your database technically isn’t lost, but it’s not very easy to work with those files… much better to get a plain MySQL dump.

Forgive me if this is a dumb question, but databases are a bit mystical to me:

Couldn’t you (theoretically) just copy whatever is the root of the DB in question to the DB folder of another VM, instead of importing/exporting? Or is there some metadata in the MySQL software itself that would prevent a raw DB from being recognized?

I can’t say for sure. It’s binary files, nothing readable… I haven’t tried, so it might be possible, but I don’t know for sure.