Excluding files in CFEngine copies

I frequently encounter people trying to do a recursive copy with CFEngine, but want to ignore some subdirectories or files.

A typical example is that /var/cfengine/masterfiles is under version control on the policy server, and a lot of meta-data is copied down to the clients during policy updates. Fortunately, it is very easy to ignore certain subdirectories during copies with CFEngine. Consider the following example.

bundle agent test_copy
{
files:

“/tmp/dest”
copy_from => local_cp(“/tmp/src”),
depth_search => recurse_ignore(“inf”, “.svn”);
}

This will copy everything recursively, except the Subversion meta-directories. A self-contained example is available for download.

A sample run is shown below.

$ find /tmp/src/
/tmp/src/
/tmp/src/subdir
/tmp/src/subdir/file3
/tmp/src/subdir/.svn
/tmp/src/file2
/tmp/src/.svn
/tmp/src/file1

$ cf-agent -KIf ./nosvn.cf

-> Copying from localhost:/tmp/src/subdir/file3
-> Copying from localhost:/tmp/src/file2
-> Copying from localhost:/tmp/src/file1

$ find /tmp/dest/
/tmp/dest/
/tmp/dest/subdir
/tmp/dest/subdir/file3
/tmp/dest/file2
/tmp/dest/file1

Of course, this can be integrated into your update.cf in order to avoid getting those pesky .svn directories everywhere.

Happy hacking!

This entry was posted in CFEngine and tagged , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *


× six = 54

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>