# A switchtower recipe to copy rather than checkout

**URL:** <https://www.ruby-forum.com/t/a-switchtower-recipe-to-copy-rather-than-checkout/54183>\
**Category:** Rails\
**Created:** [February 25, 2006, 11:29pm UTC](https://www.ruby-forum.com/t/a-switchtower-recipe-to-copy-rather-than-checkout/54183 "2006-02-25T23:29:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![wolfmanjm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/3da27b/32.png) [@wolfmanjm](https://www.ruby-forum.com/u/wolfmanjm)\
**Post date:** [February 25, 2006, 11:29pm UTC](https://www.ruby-forum.com/t/a-switchtower-recipe-to-copy-rather-than-checkout/54183/1 "2006-02-25T23:29:52Z")

</div>

For those who want use switchtower to deploy to a remote server that  
does not have  
access to the main subversion repository, here is a task I just hacked  
up to use  
switchtower to deploy to my servers by copying a local directory to the  
servers, rather  
than have the servers use svn checkout.

I actually create my local directory using an svn export, but you can do  
whatever you  
like here, and just deploy a local copy of your development directory  
tree if you like.

You can also exclude whatever directories or files you want using tar’s  
–exclude FILE option.

I include my after\_update\_code as this seems something most people need  
to do.

This could be done a lot better but it works 🙂

desc “fix up database and .htaccess”  
task :after\_update\_code do  
run “cp #{release\_path}/config/database.yml.templ  
#{release\_path}/config/database.yml”  
run “cp #{release\_path}/public/dot.htaccess.deploy  
#{release\_path}/public/.htaccess”  
end

desc \<\<DESC  
Update all servers with the latest release of the source code.  
This is a modified version that copies a local copy to the remote site  
DESC

task :update\_code, :roles =\> [:app, :db, :web] do  
on\_rollback { delete release\_path, :recursive =\> true }

```
#puts "doing my update_code"
temp_dest= "tmp_code"

#puts "...get a local copy of the code into #{temp_dest} from local 

```

svn"  
# but this could also just be your local development folder  
system(“svn export -q #{configuration.repository} #{temp\_dest}”)

```
#puts "...tar the folder"
# you could exclude files here that you don't want on your 

```

production server  
system(“tar -C #{temp\_dest} -c -z -f code\_update.tar.gz .”)

```
#puts "...Sending tar file to remote server"
put(File.read("code_update.tar.gz"), "code_update.tar.gz")

#puts "...detar code on server"
run <<-CMD
    mkdir -p #{release_path} &&
    tar -C #{release_path} -x -z -f code_update.tar.gz &&
    rm -rf code_update.tar.gz &&
    rm -rf #{release_path}/log #{release_path}/public/system &&
    ln -nfs #{shared_path}/log #{release_path}/log &&
    ln -nfs #{shared_path}/system #{release_path}/public/system
CMD

#puts "...cleanup"
system("rm -rf #{temp_dest} code_update.tar.gz")

```

end

---

<div class="post-metadata">

**Author:** ![wolfmanjm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/3da27b/32.png) [@wolfmanjm](https://www.ruby-forum.com/u/wolfmanjm)\
**Post date:** [February 26, 2006, 11:01am UTC](https://www.ruby-forum.com/t/a-switchtower-recipe-to-copy-rather-than-checkout/54183/2 "2006-02-26T11:01:29Z")

</div>

Jim,

Great stuff! I never really liked the idea of having the production  
machines have direct access to the source control. Thanks for sharing.

-Curtis
