I'm thinking of a situation where I would have something that creates a copy of a directory, tweaks a few files, and then does some processing on the result. This wold be done fairly often, maybe a few dozen times a day. (The exact use case is testing patch submissions; dupe the code, patch it, build/test/report/etc.)
What I'm looking for could be done by creating a new directory structure and populating it with hard links from the origonal. However this only works if all the tools you use delete and recreate files rather than edit them in place.
Is there a way to have the file system do copy-on-write for a file?
Note: I'm aware that many FSs use COW at a block level (all updates are done via writes to new blocks) but this is not what I want.
If you have your choice of platform for your fileserver, I'd go with a recent OpenSolaris build and use the deduplication feature of ZFS. This way copies of files would take up no additional space, and even common segments between files would not be replicated.
You can read all about ZFS deduplication at this post on Jeff Bonwick's Blog.
Most linux virtualization solutions offer file-level COW among virtualized OSes (copied from the WP):
I find this question while searching a better solution instead of my current, which is like:
cp -al SOURCEDIRNAME copy.SOURCEDIRNAME
orAt this point i have a copy of the structure with a bunch of hardlinks. This works relative fast, and don't need one time more disk space, cause we do not rly copy all files. Now i can do some ''stuff'' (like
patch
or build) on the copy directory. If they do not modify the original files, only rename them and/or create new files. After the work, i have some results and can remove the copy directory and start over.If you use more complicated tools and dont trust them (or you know they try to overwrite existing files) you may need cowdancer.
Try use one of UniouFS, AUFS or Overlay Filesystem (depends on which supported in Your distro)
For example OverlayFS used by docker as one of drivers to merge layers
Overlay Filesystem
May be SVN or other versioning tool (git, cvs)?