How to create a copy of a directory in Linux with links

I have a series of directories on Linux, and each directory contains a lot of files and data. Data in these directories is automatically generated, but several users will need to do more analysis of this data and generate more files, change the structure, etc.

Since these data directories are very large, I do not want several people to make a copy of the source data, so I would like to make a copy of the catalog and a link to the original from a new one. However, I would like for any changes to be saved only in the new directory and leave only the original reading. I would prefer not to link only certain files that I define, because the data in these directories is so diverse.

So, I am wondering if there is a way to create a copy of the directory by contacting the original, but saving any modified files only in the new directory.

+6
source share
2 answers

Turns out this is what I wanted:

cp -al <origdir> <newdir> 

It will copy the entire directory and create hard links to the source files. If the original file is deleted, the copied file still exists and vice versa. This will work fine, but I found that newdir does not exist yet. As long as the source files are read-only, you can create an identical, secure copy of the source directory.

+21
source

However, since you are looking for a way people can write changes, UnionFS is probably what you are looking for. It provides a means to combine read-only and read-write points into one.

Unionfs allows you to use any combination of read-only, read-write sections, as well as inserting and deleting branches at any branch location.


Initially, I was going to recommend this (I use it a lot):

Assuming permissions are not a problem (for example, only reading is required), I suggest binding them to a place.

 mount -B <original> <new-location> # or mount --bind <original> <new-location> 

<new-location> must exist as a folder.

+2
source

Source: https://habr.com/ru/post/920345/


All Articles