0

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.)

3
  • 2
    Can you cp --attributes-only within the remote system and then download the copy to the local? Commented Oct 16, 2022 at 15:39
  • Does this answer your question? Create tar file that stores filenames, but not file contents
    – larsks
    Commented Oct 16, 2022 at 16:14
  • ah, both of these are creative approaches. The only folder I'd possibly have write access to is /tmp. The only gotcha I can think of is if / when the production image is fully immutable. I don't have star on the system in question and can't install it, but I like the idea of forcing all this to happen on the remote machine and just dl'ing the compressed structure. I'll test and update.
    – user658182
    Commented Oct 16, 2022 at 16:25

1 Answer 1

1

Here's a crazy idea: what if you use sshfs?

  1. Mount the remote directory locally using sshfs:

    sshfs remoteuser@remotehost:/my/directory /mountpoint
    
  2. Use the --attributes-only option to cp to recreate the file structure:

    cp -a --attributes-only /mountpoint /test/directory
    
  3. Unmount the sshfs filesystem:

    fusermount -u /mountpoint
    

This doesn't require installing any additional software on the remote host.

1
  • I like this a lot. Currently the images that are used in testing duplicate the prod infrastructure where sshfs isn't installed. But I'll see if I can alter the devops job to include it. On a related note, I often pipe or redirect remote stdout data to local (ssh remote@host "my command outout" > localfile), and I'm wondering if cp can be used similarly, especially if I use the <(command) convention which gives stdout its own device file descriptor as if it's manipulating on-disk files. Thanks for the creative thinking, and let me know if you have ideas in those directions too.
    – user658182
    Commented Oct 26, 2022 at 14:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .