# \[SOLVED\] Copy directory recursively

**URL:** <https://discourse.chef.io/t/solved-copy-directory-recursively/13706>\
**Category:** Chef Infra (archive)\
**Created:** [September 20, 2018, 8:30am UTC](https://discourse.chef.io/t/solved-copy-directory-recursively/13706 "2018-09-20T08:30:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![israel](https://avatars.discourse-cdn.com/v4/letter/i/b77776/32.png) [@israel](https://discourse.chef.io/u/israel)\
**Post date:** [September 20, 2018, 8:30am UTC](https://discourse.chef.io/t/solved-copy-directory-recursively/13706/1 "2018-09-20T08:30:26Z")

</div>

Hi,  
Sorry for the stupid question but i can't find resource for copy recursive files.  
I want to copy files from /opt/source to /tmp/backup.  
I tried remote\_directory "#{node['backup']['analysis']}" do  
source '/tmp/backup'  
owner 'root'  
group 'root'  
mode '0755'  
action :create  
recursive true  
end  
But i've got error "Chef::Exceptions::FileNotFound  
------------------------------  
cookbook centos7 has no directory files/default//tmp  
Please help.  
Thanks!

---

<div class="post-metadata">

**Author:** ![jvossler](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/jvossler/32/2336_2.png) [@jvossler](https://discourse.chef.io/u/jvossler)\
**Post date:** [September 20, 2018, 11:57am UTC](https://discourse.chef.io/t/solved-copy-directory-recursively/13706/2 "2018-09-20T11:57:11Z")

</div>

The remote\_directory resource is used to transfer a directory from a cookbook to a node. It will not recursively transfer file from one location on a node to another.

The usual way to do this is with a bash resource or a ruby block.

Here is a bash block example.

bash "backup source folder" do  
code \<\<-EOL  
mkdir /tmp/backup  
cp -rp /opt/source /tmp/backup/

EOL  
end

You can create the directory in the bash resource or use a chef resource to create the directory. The resource is idempotent whereas the bash command is not.

---

<div class="post-metadata">

**Author:** ![israel](https://avatars.discourse-cdn.com/v4/letter/i/b77776/32.png) [@israel](https://discourse.chef.io/u/israel)\
**Post date:** [September 20, 2018, 12:08pm UTC](https://discourse.chef.io/t/solved-copy-directory-recursively/13706/3 "2018-09-20T12:08:28Z")

</div>

I thought it will be much more easy with a resource for copying multiple files.  
Now I know there is no such thing...  
Thanks for your help!

---

<div class="post-metadata">

**Author:** ![Larryc](https://avatars.discourse-cdn.com/v4/letter/l/c6cbf5/32.png) [@Larryc](https://discourse.chef.io/u/Larryc)\
**Post date:** [September 20, 2018, 4:44pm UTC](https://discourse.chef.io/t/solved-copy-directory-recursively/13706/4 "2018-09-20T16:44:31Z")

</div>

you could use the execute resource

[https://docs.chef.io/resource\_execute.html](https://docs.chef.io/resource_execute.html)
