7

I'm trying to speed up the process of synchronizing my production site down to my local install. Currently, it is: Back up database, wipe local database, import database backup. It's not perfect, but it is pretty fast.

But synchronizing the assets down is still a pain. Is there a process or plugin that makes it easy/easier to synchronize assets (uploaded photos, etc.) between installs?

7 Answers 7

8

I use rsync with grunt. There is a grunt rsync task, which is just a wrapper for raw rsync. If all I used grunt for was the rsync I don't think it would be worth it, but I use it to compile my sass, and to reload my browser (grunt-contrib-sass, grunt-contrib-watch) among other things.

2
  • Fantastic. This is really helpful. Thanks! Commented Jul 27, 2014 at 11:16
  • 1
    I think of rsync as a really sharp knife - super useful, but it will cut... Commented Jul 27, 2014 at 16:45
7

Another alternative to grunt is to use http://gulpjs.com/. This is what I use for minifying css js and assets etc. I've been meaning to setup a way of syncing folders so I've put together gulp task to do it. I have roughly tested it but you might want to look over the code before you use it on a production site :) Be aware that it is setup to sync the folder so it will remove any local files that are not present on your staging/production server.

To use gulp you need to have node.js installed with npm. First install gulp globally:

npm install -g gulp

you might need to run that as sudo.

Next, in the root of your craft project create a gulpfile.js that looks something like this:

// Gulp
var gulp = require('gulp');

// Plugins
var rsync = require("rsyncwrapper").rsync;

// Pull down assets and sync local folder
gulp.task('synclocal', function(){
    rsync({
        src: "[email protected]:/path/to/assets",
        dest: "assets",
        ssh: true,
        recursive: true,
        syncDest: true,
        compareMode: "checksum"
    },function (error,stdout,stderr,cmd) {
        if ( error ) {
            // failed
            console.log(error.message);
        } else {
            // success
            console.log("folder synced!")
        }
    });
});

Finally we need to make sure rsyncwrapper is install. You can do this by running:

npm install rsyncwrapper

You should now be able to run the task by typing:

gulp synclocal
1
  • Brilliant! Great idea! Commented Jul 27, 2014 at 11:15
7

I made a simple script to do this. It's much, much less powerful than Capistrano, but with a few tweaks I think it'll be more flexible (for starters, not requiring Ruby or learning Cap).

https://github.com/mattstauffer/syncCraft

My Original solution, pre-syncCraft:

FYI, this is what I'm doing right now. It's not good enough, but I'll put it up for reference... I run this from the command line:

scp myuser@myhost:/path/to/site/public/assets/images/content/* /local/path/to/site/public/assets/images/content/

But it's manual, and not smart enough to avoid overwriting stuff locally. I think I could use rsync to avoid overwriting locally, but again, I feel like a Craft plugin might(?) be a better option.

Here's the rsync version:

rsync -auv myuser@myhost:/path/to/site/public/assets/images/content/* /local/path/to/site/public/assets/images/content/
6
  • Probably depends on how many Assets you'll be pulling down. If it's gigs and gigs, you'll bump into memory and execution time limits with PHP. Something like rsync (even if triggered from PHP), might be more reliable then.
    – Brad Bell
    Commented Jul 26, 2014 at 1:47
  • Ahhh--ok, good thought. I'll probably try an rsync-based version, and just do my best to make it as simple to install as possible (trying to get the workflow so simple that it's not a huge pain to add to a new site). Commented Jul 26, 2014 at 1:49
  • OK, rsync version is a ton better, but it's still super manual to add it. Might have to make something happen. Commented Jul 26, 2014 at 1:58
  • If you've got a script that handles the other stuff (pulling db down, nuking local, reinstalling), why not have the script trigger rsync?
    – Brad Bell
    Commented Jul 26, 2014 at 2:00
  • I don't. I do the rest manually now. But I think this is my motivation to throw it all into a script. There wouldn't be an easy method I could run from my shell script to trigger a backup, would there? :hopeful: :) Commented Jul 26, 2014 at 2:01
4

I think this might be the plugin you are looking for:

https://github.com/boboldehampsink/zipassets

It allows you to download a zip of selected assets, might be easy to specify all assets within the plugin.

3
  • Hm, maybe hooking that up to a "get all asset IDs" request and then making it a control panel button might be the ticket--thanks! I'll take a look further into it. Commented Jul 26, 2014 at 1:44
  • Would love to see what you end up doing! You are referring to local assets and not S3 correct? Commented Jul 26, 2014 at 1:46
  • Yep, just for local assets at the moment. Commented Jul 26, 2014 at 1:46
4

You might want to take a look at capistrano if your looking at ways to automate sync mutliple environments:

http://capistranorb.com/

Not sure what your local environment is like but if you have ruby installed, capistrano might be be something to consider for automation. There are plenty examples across the web of how to use it to sync databases and folders. It used to be heavily tied to rails app but as of recent versions I believe it is more agnostic. I know I'll be looking into this in the coming weeks once I get some spare time.

2
  • Thanks Dave! I've been itching to learn Capistrano for a while. I'd prefer an option that doesn't require Ruby so we had a community wide standard method, but this is definitely a route to go for more complex needs. Thanks!! Commented Jul 27, 2014 at 0:44
  • Hi Matt, if you'd prefer php take a look at deployer.in I haven't tried it myself but it looks promising. I'm sure there is another one I stumbled across a while ago but I can't seem to find it. I'll let you know if I do though. Commented Jul 27, 2014 at 2:49
3

Just updating this thread with another option. Also using Rsync but through the Mac app Dropsync3 http://mudflatsoftware.com/

Pretty cool, I'm currently getting the "dump" plugin to make a daily db backup via Cron and then getting Dropsync to sync the "storage" folder with a folder on my computer (that is version controlled).

Also doing similarly with assets and just debating the best way to handle system updates.

1

In case it's of use to anyone coming to this thread, I maintain a project called Crafty Vagrant, which is intended to be a handy dev environment / boilerplate starting point for Craft projects, and which has (among other things) both asset-syncing, in the form of a Gulp task (eg. gulp rsync:fromstage), and simplified database provisioning (vagrant provision --provision-with shell drops the current local database and replaces it with the most recent backup from Craft's backups directory).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.