Take the 2-minute tour ×
Craft CMS Stack Exchange is a question and answer site for administrators, end users, developers and designers for Craft CMS. It's 100% free, no registration required.

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?

share|improve this question

5 Answers 5

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.

share|improve this answer
    
Fantastic. This is really helpful. Thanks! –  Matt Stauffer Jul 27 at 11:16
1  
I think of rsync as a really sharp knife - super useful, but it will cut... –  Marion Newlevant Jul 27 at 16:45

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: "username@hostname.com:/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
share|improve this answer
    
Brilliant! Great idea! –  Matt Stauffer Jul 27 at 11:15

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/
share|improve this answer
    
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 Jul 26 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). –  Matt Stauffer Jul 26 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. –  Matt Stauffer Jul 26 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 Jul 26 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: :) –  Matt Stauffer Jul 26 at 2:01

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.

share|improve this answer
    
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. –  Matt Stauffer Jul 26 at 1:44
    
Would love to see what you end up doing! You are referring to local assets and not S3 correct? –  Jason McCallister Jul 26 at 1:46
    
Yep, just for local assets at the moment. –  Matt Stauffer Jul 26 at 1:46

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.

share|improve this answer
    
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!! –  Matt Stauffer Jul 27 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. –  Dave Coggins Jul 27 at 2:49

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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