On a remote production server I have a directory that has more than 15 Terabytes of data. Also, in addition to Linux permission, ACLs are heavily used to allow departments, users, and daemons fine tuned access.
For our CI/CD pipeline and automated testing, I need to test how changes to these permissions affect the system, but before I can do that, I need a clone of what's on production in the test environment.
I obviously can't clone 15 Terabyte of data, and I really don't care about the data, I just care about the meta data (filenames, permissions, timestamps - basically all the info ls -lah
returns.)
It's easy to see what I'm trying to do with how I'm using rsync
:
rsync -aAr --include='*/' --exclude='*' [email protected]:/my/directory/ /test/directory/
This gives me exactly what I need from a directory standpoint. If rsync
had an option to allow files to be copied over with 0 content but filenames and attributes intact, problem solved. (Does it?)
For now, after I run the above rsync command for the directories, here is how I'm approaching this.
ssh [email protected] 'find /my/directory -type f -exec ls -lah {} \;' > my.production.directory.files.txt
This gives me a local file where the contents contain lines of data like this:
-rwxrwxrwx 1 owner group 15K Oct 13 10:07 /my/directory/jobs.txt
That has 9 fields, and I'm passing it to awk and bash:
cat my.production.directory.files.txt | awk '{print "touch " $9 " && chown "$3":"$4" "$9}' | bash
I feel like there has to be a better way. before I filter that file through other commands to apply chmod
and the original timestamps, isn't there a more efficient way to do this? Something like cp
has with --attributes-only
like touch
and chown
can do with --reference, except against a remote file system?
Note, the answer must be executed directly on the command line. I cannot upload or rely on any scripts. Also, I know getfacl -R and setfacl will restore the permissions, but it does not restore timestamp and non-permissions related file data (that I'm aware.)
cp --attributes-only
within the remote system and then download the copy to the local?