Keep database synced between computers in Trellis/Bedrock/Sage setup

I haven’t tried syncing raw database files and it sounds like those who have tried saw corrupted tables. Maybe someone else will have better ideas, but you may just have to do an sql dump to a dropbox folder when you leave one work location, then import the db when you arrive at the other location. You could dump/import with Sequel Pro, WP CLI, WP Migrate DB Pro, etc. Maybe you could automate it.

Maybe someone familiar with RDS could comment on whether an RDS setup would work, but maybe that’s overkill for syncing two dev DBs.

All that said, yes, you need to manage owership on sync folders using vagrant-bindfs, as is used with site_path. I think the user:group of the raw db is root:root (you could double-check if you haven’t already), but again, it’s probably best to not sync the raw db files. You tried root:root and it failed, but I suspect it would work once you add in the bind folder. For reference on implementation, here is where Trellis began using vagrant-bindfs to handle permissions: roots/trellis#82

As for how to access variables from wordpress_sites in the Vagrantfile, you could use wordpress_sites['example.com']['env']['db_name'], but maybe there is a smarter way. Replace example.com with whatever your site key is. site['env']['db_name'] would work if you were looping over the sites, each site represented by the site object.

1 Like