Operating System - HP-UX
1825667 Members
4224 Online
109686 Solutions
New Discussion

Re: how to copy/backup subdirectory while retain ownership/symlink/access-rights?

 
Kevin Lai_1
Occasional Advisor

how to copy/backup subdirectory while retain ownership/symlink/access-rights?

Just mounted a directory (network storage)from a different server to my local server, and I need to copy the entire content of this mounted lvols over to my local disk.
I need to retain all the ownership, permission and symlinks within the subdirectories.

How can I achieve these?
"cp -Rp src tgt" does not achieve this.
Alternatively, I can create a tar file of the entire directory, but it would need similar storage space, not efficient for large filesystems.

Anyone know a fail-safe way of redirect tar output to this target directory?
I am not very familiar with redirection.

Or is there any other better alternative?

I am using HPUX 11.23 on Itanium.

Thanks
4 REPLIES 4
James R. Ferguson
Acclaimed Contributor

Re: how to copy/backup subdirectory while retain ownership/symlink/access-rights?

Hi Kevin:

This should meet your needs:

# cd srcdir && find . -depth -print | cpio -pudlmv dstdir

If you have largefiles in the source directory, however, you will need to use this method:

# cd srcdir && fbackup -i . -f - | ( cd dstdir && frecover -Xsrf - )

Consult the manpages for more infomration.

Regards!

...JRF...
James R. Ferguson
Acclaimed Contributor

Re: how to copy/backup subdirectory while retain ownership/symlink/access-rights?

Hi (again) Kevin:

One other notation for you. It is common for the destination directory (or mountpoint) to be smaller in size than the source directory (or mountpoint) after a successful copy. This is simply because blocks in the destination directory that were once used for files that have subsequently been removed, are not deallocated.

You may wish to verify that your source and destination directories contain an equal number of files at the copy's end. You could also compare the contents of the directories with 'dircmp' [see its manpages for more information].

If you want to be very paranoid, you can compare the checksums of the files in the source and destination directories for equality too. Of course, this could take considerable time. Personally, I have not found, nor regard, this necessary.

Regards!

...JRF...
Victor Fridyev
Honored Contributor

Re: how to copy/backup subdirectory while retain ownership/symlink/access-rights?

Hi,

Tar is also a good solution, just run it as root:

cd srcdir; tar cf - *|(cd target; tar xf - )

HTH
Entities are not to be multiplied beyond necessity - RTFM
Bill Hassell
Honored Contributor

Re: how to copy/backup subdirectory while retain ownership/symlink/access-rights?

Note that tar had the same limitation as cpio -- no largefile support. Although the newest version handles up to 8Gb files, that i sfar from supporting really large files like terabyte files. But be careful with copying using *. This is a shell special character. It does not match every file (files starting with . are not found) and the list can exceed the maximum command line length (arg list too long). James' fbackup solution is the best -- it works for every possible filesystem. It is also the fastest method due to the multiple processes and use of shared memory.


Bill Hassell, sysadmin