Tutorials, Uncategorized, WordPress

Using Dropbox To Keep VVV In Sync on Multiple Computers

Updated November 3, 2014 See below for a few issues we’ve come across.

I’ve been plotting for a while now to get a kick-ass desktop for development. Since I work once or twice a week at a co-working space and travel for WordCamps or to visit family fairly regularly, I’m going to need to keep my laptop for those situations. One of the things, besides clients owing me money that has kept me from getting said kick-ass desktop machine  is worrying about how to keep my development environment in sync between the two machines.

Lucky for me Scott Kingsley Clark, figured out how easy it is to keep VVV in sync between his shiny new iMac and his laptop. Scott was kind enough to share his strategy with me, which I have tested with a loaner computer and found to work very well.

Before We Get Started

I’m assuming that you’re already using VVV and are familiar with it. If you’re not, you should probably be reading my guide to getting started with VVV for local WordPress development instead.

Since you’re familiar with VVV, it’s a safe assumption that you know to install Vagrant itself and a Virtual Box or some other VM software on both computers. Right?

You can either use an existing VVV setup or create a new one for this. In this guide, I will be starting from scratch, but you could also do the same thing by temporarily moving your existing one into your Dropbox folder instead of creating a new one.

Also, for this guide, I will be calling the vagrant folder dvv, for Dropbox Varying Vagrants. You can call it whatever you want.

Setting It Up

Install VVV In Dropbox

The first step is to clone VVV itself into Dropbox:
cd ~/dropbox
git clone https://github.com/Varying-Vagrant-Vagrants/VVV dvv
You could also download the ZIP and extract it in Dropbox.

Symlink VVV Folder

On both computers you are going to want to symlink the VVV folder with a folder in your user root. This is mildly optional, as you could just work out of Dropbox. Personally, I agree with Scott on symlinking, as I love the ease of being able to cd directly into my VVV from a new bash shell. It’s a little thing, but I have to do it after every restart.

If you’re using an existing install, this step is extra important as it let’s you put the install back where you found it on the originating computer.

You must do the symlink on both computers:
ln -s ~/dropbox/dvv ~/dvv

Vagrant Up

On the remote machine you do a new vagrant provision and that’s it you’re good to go.

What This Doesn’t Do

This does not keep the virtual machines themselves in sync. I don’t think it makes any sense to do so, though I’m sure it’s possible. That means whenever you make changes to your configuration or add a new site, you will need to do a new vagrant up on the other computer.

Also, since the database is in the virtual machine. It does not keep the database in sync. If you have the Vagrant Triggers plugin installed you get a database backup every time you vagrant halt. You can use that to rebuild the DB when doing a new vagrant up or vagrant provision.

That’s Actually Very Simple

That’s it. Turns out this is very simple,  Scott’s pretty good at creating ways of making WordPress simpler.

OK, Maybe Not That Simple

Here are some caveats that Scott has discovered since starting to use this strategy since implementing Dropbox to sync his VVV between two computers:

1. My virtual machine tends to be recreated from time to time, forcing 100% install over again when doing a `vagrant up`, this is likely because some files synced by Dropbox are unique to the computer, and keep changing between ‘up’s on the different vagrants.

2. Because of the virtual machine recreation, DB changes can disappear and most commonly be restored by Vagrant during it’s provisioning. It’s important to note that when you use `vagrant halt`, it will backup the databases on the current virtual machine, and on `vagrant up` (first, or `vagrant provision`) it will attempt to restore those DB .sql files on the other machine.

Approach with caution, I currently now believe the best way to sync VVV is to limit the sync to the `www` folder, not the entire VVV folder contents.

7 Comments

  1. “Approach with caution, I currently now believe the best way to sync VVV is to limit the sync to the `www` folder, not the entire VVV folder contents.”

    Thanks for the update. I probably save a few hours from that. Now I will sync only the www folder. 🙂

  2. Hey Josh,
    I didn’t think to use DropBox to do this. I think this works great if you’re syncing between two systems that you have though it becomes a bit tough when there are a few more devs involved (especially with GIT and stuff).

    Anyway, we came up with a little script that handles the DB backup through GIT. We wrote on it here: http://y-designs.com/blog/wordpress-development-consistency-and-deployments/

    I was thinking that in the future the smart thing would be to have a remote MySQL database that VVV instances can connect to. That way, your local changes can be stored remotely. That method does have its setbacks too though.

    Anyway, cool write up!
    R

  3. I currently only have my /vvv/config/, /vvv/database/, /vvv/www/ folders symlinked into my Dropbox, the main VVV being in Dropbox caused some issues for me that made it very difficult to work with between computers after a while, mainly differing virtual machine IDs and some of the VVV local config stuff.

  4. Luís R.

    Just a heads-up if you use Git: the .git directory can become seriously b0rked if Dropbox fails to sync it completely and conflicts are allowed to emerge. The thousands of tiny files Git creates took me a long time to sync, and that opened the door to conflicting changes whenever I shut down one machine before it had the chance to push every file (especially common on a slow network). You should be fine 99% of the time, but I was forced to re-clone a clean version of a project at least a couple of times already.

  5. Hi Josh

    Thanks for the write up. I’m relatively new to vvv – have been syncing mamp (vanilla version) between machines for a couple of years but the limitations of that setup are starting to become a bit of an issue hence the switch to vagrant/vvv.

    Possibly a bit of a n00b question, but as well as keeping the www folder synced in dropbox via symlink, could I do the same with the ‘database’ folder in my dvv folder (or whatever I choose to call it)?

    Not au fait enough with vvv yet to know if this is how it works, but when I ‘vagrant halt’ do the .sql files in database>backups get updated? If so then this would seem like a good way to keep both files (in www) and data in (database) in sync and leave all the VM stuff to the separate machines. Would that work or am I missing something?

    • John-

      Glad you liked it. The database folder does not house your actual database. The database is in the virtual machine, which is not in the VVV folder and is not synced via dropbox in this setup. That said, if you installed the vagrant triggers plugin, and you should, then the database folder has a folder called backups, with backups of your database that get updated on each vagrant halt. So you could write a script to import from those backups.

      Take care,
      Josh

      • Hi Josh

        Thanks for the reply – been toying with vvv since that comment and basically concluded what you confirmed above. The triggers plugin seems to do a grand job of backup on halt and then importing those DB files on up which is pretty much exactly want I want. As it turned out syncing the DB via dropbox is really quite straightforward. Just move the database folder into dropbox and symlink back to vagrant local on both machines.

        However, I spent pretty much three days banging my head against a brick wall with syncing project files though. I’ll outline my solution here for the benefit of anyone else who comes across your article.

        I initially tried your solution of moving the www folder into dropbox but I didn’t like the way it would (naturally) backup every last file in the www folder. All of the WP core of each project plus all the thousands of files for things like bower_components / node_modules / unit test dependencies etc which I tend to use in themes and plugins add up very quickly when you have several projects.

        Basically all I wanted to do is sync the plugins and uploads folder for each WP install – the rest is easy to replicate on the other machine and I can just pull down my theme from version control so no need to sync that too.

        I did this in the past with mamp by having the plugin/upload folders for each project (encased in their own project-named folder) in a directory called project-sync in dropbox. I’d then symlink uploads and plugins for any given project into the correct WP install on each local machine. Worked a charm.

        It didn’t work so well on VVV unfortunately. Whilst you can see and work with the files on your host machine, the guest machine can’t follow the symlinks (which equals very broken site as WP thinks all your plugins and uploads have evaporated…).

        Took me forever to figure out a way around this but turns out the solution is quite simple – just have the original folders in vvv on your host machine and put symlinks to them in dropbox. As dropbox sync the contents of a symlinked folder and not the symlink itself your files still end up in the cloud. As long as you set up a symlink with the exact same name on all other machines you should be good to go. This article explains things more neatly than I can for the actual ‘how to’ (it’s approach #2 that you want to try).

        http://www.pxc.me.uk/misc/dropbox_mac_use.html

        Right, sorry for rambling on Josh – thanks again for the article – really helped me on the right path to figuring things out!

        John

Leave a Reply

Theme by Anders Norén