We’re migrating home folders to a new filesystem, and I am looking for a way to automate it using Perl or a shell script. I don’t have much choice in programming languages as the systems are proprietary storage clusters that should remain as unchanged as possible.
Task: Under directory /home/ I have various users’ home folders aaa, bbb, ccc, … and they have certain permissions and user/group ownership that need to remain intact upon migration to /newhome/. Here’s example of what needs to be migrated from /home:
drwxr-xr-x 3 aaaaa xxxxxxxxx 4096 Feb 26 2008 aaaaa/ drwxrwxrwx 88 bbbbbbb yyyyyy 8192 Dec 16 16:32 bbbbbbb/ drwxr-xr-x 6 ccccc yyyyyy 4096 Nov 24 04:38 ccccc/ drwxr-xrwx 36 dddddd yyyyyy 4096 Jun 20 2008 dddddd/ drwxr-xr-x 27 eee yyyyyy 4096 Dec 16 02:56 eee/
So, exact same folders with permissions and ownerships should be created under /newhome. Copying/moving files should not be a concern, as it will be handled later.
Anyone has worked on such script? I am really new to Perl, so I need help.
cp‘s -a flag will maintain permission, modification times etc. You should for be able to do something like:Try it with one directory to see if does what you need before automating it.
EDIT: You can disable recursive file copying by using rsync or tar as mentioned by Paul. With rsync, subdirectories are still preserved, but files aren’t copied:
I haven’t tried tar’s –no-recursion, so can’t comment on it.
EDIT 2: Another way
Reference