The POSIX 'cp' command provides '
cp -pPR source-dir target-dir' to copy file hierarchies around. This preserves most of the meta-data. If run by root, then the copy will have the owner and group of the original owner. If run by mere mortals (not root), then the person running the script will own the files, and generally, the group for the files will be the effective group of the person running the script. (The exception there would be if the target directory has the SGID bit set - or you are running on MacOS X.)
The other way of doing it, which can be beneficial, is to use
cpio. The primary benefit of these is that they handle hard links better. The
cp command treats each file name as a separate file, even if it is a hard link to another file already copied. By contrast, the archivers recognize the commonality and preserve the hard links, reducing the amount of data to be transferred. One other advantage of the archivers is that you can move the files between machines.
You'll need to check that your machine's copy of
tar is capable of doing what you need, but with GNU tar (and BSD/MacOS tar), you can do:
tar -cf - . | tar -xf - -C target-dir
cpio you can do:
find . | cpio -pdmuB target-dir
Note that '
find | cpio' could run into issues with exotic file names with newlines in the file names (other characters don't cause trouble AFAIK).