HOWTO: Copy a filesystem on AIX PDF Print E-mail
User Rating: / 27
Written by Michael Felt   
There are probably other ways to copy a filesystem on AIX. However, this is the way I have done it for years. The basic process to first specify filenames thru a pipe, then stream the files thru a pipe, and conclude by moving to the new location and writing the files in the new location including a accurate copy of the inode information.

Command or script?

I usually just type the command from the prompt, but if I were to write it as a script it would look something like this:


if [ $# != 2 ]
   echo Syntax: ${cmd} "<src_directory>" "<new_directory>"
   exit 1

# since the directory names might be entered as relative to current directory
# change to each of the directories and set a full path name for each

#verify source directory exists
cd $old
if [ $? != 0 ]
   echo ${cmd}: cannot change directory to ${old}
   exit 1
cd -

#verify target/destination directory exists
cd $new
if [ $? != 0 ]
   echo ${cmd}: cannot change directory to ${new}
   exit 1
cd -

# perform copy
cd ${src}
find . | backup -if - | (cd ${target}; restore -xqf -)

# return the exit value of the command above
exit $?

Short Discussion:

I use the AIX tools backup and restore for the actual streaming, or copy process because these commands are fully aware of any special information in the inode such as ACL information. Commands such as cpio and tar might work fine, but you can not be sure as they are generic or POSIX standard compliant tools.
The last commands are done between the characters ( and ) which create a sub-shell. In this sub-shell the cd and restore are performed. The sub-shell, or child process, receives the stream in the new location while the parent process performs the find and backup in the source directory.

What I have not included in the script above is a test for effective userid of root - which is a requirement for a copy or move operation when files, directories or devices are owned by multiple users. In such a case, some files will either not be read, or the owner will change to the effective userid doing the copy. Also not included is a test that the target is not a sub-directory of the src.

As I said before I generally just run the command from the command line:

find . | backup -if - | ( cd <NEW>; restore -xqf - )

< Prev   Next >