# Capistrano: copying directory from previous release

**URL:** <https://www.ruby-forum.com/t/capistrano-copying-directory-from-previous-release/120843>\
**Category:** Deployment\
**Created:** [November 21, 2007, 1:32am UTC](https://www.ruby-forum.com/t/capistrano-copying-directory-from-previous-release/120843 "2007-11-21T01:32:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![leonb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/22d042/32.png) [@leonb](https://www.ruby-forum.com/u/leonb)\
**Post date:** [November 21, 2007, 1:32am UTC](https://www.ruby-forum.com/t/capistrano-copying-directory-from-previous-release/120843/1 "2007-11-21T01:32:39Z")

</div>

Hi all,

I’m using capistrano to deploy my application. But I have to copy the  
images/\* directory manually each time to the current release. Is there a  
way to make capistrano do this for me?

Something like:  
run "cp -r ~/#{previous\_release}/public/images/users/\*  
~/current/public/images/users/

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![leonb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/22d042/32.png) [@leonb](https://www.ruby-forum.com/u/leonb)\
**Post date:** [November 21, 2007, 8:49am UTC](https://www.ruby-forum.com/t/capistrano-copying-directory-from-previous-release/120843/2 "2007-11-21T08:49:31Z")

</div>

Leon B. wrote:

> Thanks in advance!

The usual way of solving this (for images generated by the app, rather  
than ones for the layout, which may be in the svn repository) is to put  
the images in the shared folder with a symlink to them, and then add  
have capistrano add the symlink after updating the code. I also do the  
same for fragment cach files.

Something like:  
run \<\<-EOF  
cd #{release\_path} &&  
ln -s #{shared\_path}/photos #{release\_path}/public/photos  
EOF

Hope this helps,  
Chris

## –

Autopendium :: Stuff about old cars  
[http://autopendium.com](http://autopendium.com)

---

<div class="post-metadata">

**Author:** ![leonb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/22d042/32.png) [@leonb](https://www.ruby-forum.com/u/leonb)\
**Post date:** [November 21, 2007, 9:20am UTC](https://www.ruby-forum.com/t/capistrano-copying-directory-from-previous-release/120843/3 "2007-11-21T09:20:19Z")

</div>

Chris T. wrote:

> Leon B. wrote:
> 
> > Thanks in advance!
> 
> The usual way of solving this (for images generated by the app, rather  
> than ones for the layout, which may be in the svn repository) is to put  
> the images in the shared folder with a symlink to them, and then add  
> have capistrano add the symlink after updating the code. I also do the  
> same for fragment cach files.
> 
> Something like:  
> run \<\<-EOF  
> cd #{release\_path} &&  
> ln -s #{shared\_path}/photos #{release\_path}/public/photos  
> EOF
> 
> Hope this helps,  
> Chris
> 
> ## –
> 
> Autopendium :: Stuff about old cars  
> [http://autopendium.com](http://autopendium.com)  
> Ah thanks, gonna try that. I now have something like:

namespace :deploy do  
task :copy\_user\_images do  
run “cp #{previous\_release}/public/images/users/\*.jpg  
current/public/images/users/”  
end

task :after\_deploy do  
copy\_user\_images  
end  
end

---

<div class="post-metadata">

**Author:** ![leonb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/22d042/32.png) [@leonb](https://www.ruby-forum.com/u/leonb)\
**Post date:** [November 21, 2007, 6:57pm UTC](https://www.ruby-forum.com/t/capistrano-copying-directory-from-previous-release/120843/4 "2007-11-21T18:57:03Z")

</div>

On Nov 21, 2007, at 12:20 AM, Leon B. wrote:

> > have capistrano add the symlink after updating the code. I also do  
> > Chris  
> > current/public/images/users/"  
> > end
> 
> task :after\_deploy do  
> copy\_user\_images  
> end  
> end

I’d really discourage you to continue doing that. This slows down your  
deployment process as your image directory gets larger.

You do have a shared directory somewhere right? For logs, database.yml  
and the like? This is where you should store images as well and then  
you just symlink it, which is instantaneous and doesn’t unnecessarily  
duplicate images on your filesystem.

Hope that helps…

Cheers,  
Robby

–  
Robby R.  
Founder and Executive Director

PLANET ARGON, LLC  
Design, Development, and Hosting with Ruby on Rails

> **[Planet Argon](https://www.planetargon.com/)**
>
> Planet Argon is a Ruby on Rails development agency specializing in maintenance and support for existing Rails apps. Based in Portland, OR, Planet Argon has been a member of the Rails community since 2004.

[http://www.robbyonrails.com/](http://www.robbyonrails.com/)

+1 503 445 2457  
+1 877 55 ARGON [toll free]  
+1 815 642 4068 [fax]
