Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
migrating 300 users from old to new install
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Networking & Security
View previous topic :: View next topic  
Author Message
IWBCMAN
Guru
Guru


Joined: 25 Jun 2002
Posts: 474

PostPosted: Wed Sep 10, 2003 4:53 pm    Post subject: migrating 300 users from old to new install Reply with quote

I am re-implementing a ltsp server w/ 300 users. I have ~300 directories under home and I need to recursively enter and copy personal files into a new home directory structure on a fresh install. I also need to transfer pam passwords and shadow for each of these users(using adduser and pwconvert).

I know I can do this stuff manually- one user and one directory at a time. But perhaps one of the gifted BASH gods could come to my resuce and give me a few command line examples which would illustrate how one can cd into a directory, copy files w/ specific exentions(ie. .swx), preserving permissions, to a new directory-recursively-running through all sub directories in one shot......

I know BASH has variables with which one can use the output of one command as the input of another-but BASH defies me, I have yet to grasp the essence of scripting,being stuck in the stone-age of super simple scripts(ie. without recursion, variables etc)

my dream would look like this :
for "sub" in "home"; do: cd "sub"; mkdir /newdrive/newhome/"(new)sub"; cp -ax *.sxw/*.mpg/*.pdf/*.doc/*.avi/*.txt/*.xls (to) /newdrive/newhome/"(new)sub";

I don't actually want to copy the entire directories over-just the documents......


Any help would really be appreciated.....
Back to top
View user's profile Send private message
grooveman
Veteran
Veteran


Joined: 24 Feb 2003
Posts: 1217

PostPosted: Wed Sep 10, 2003 5:19 pm    Post subject: Reply with quote

Ok.

I have never used pwconvert. You are on your own there.

I don't think this will need to be as verbose as you are thinking.

Try this:

First, make your new home directory, nfsmount it or whatever you need to do.

then execute this:
find /home/ -name "*.doc" -exec cp -pPvf {} /new_root_dir \;

Let it do its work, and I think you will be pleased. Then execute it again, but change the "*.doc" to "*.sxw" or whatever file extension you are concerned with. Do that until you get everything you need. Yes, you could script this with looping and the whole bit, but I don't think it will be worth your time since it is pretty much a one-shot deal. If you need to run it unattended, then just write a script putting that command on each line, chaning the "*.xxx" for each corresponding file type. It is not pretty, but it is quick and easy with vi.

It should retain ownerships and perms. It will overwrite any files or directories with identical names in the destination directory

Good luck!


Chris
_________________
To look without without looking within is like looking without without looking at all.
Back to top
View user's profile Send private message
IWBCMAN
Guru
Guru


Joined: 25 Jun 2002
Posts: 474

PostPosted: Thu Sep 11, 2003 12:11 am    Post subject: Reply with quote

grooveman,


First off thanks for the tip. The command you showed *almost* did what I wanted.
Code:

find /home/ -name "*.doc" -exec cp -pPvf {} /new_root_dir \;


But it copied all the files I searched for in all of the subdirectories into one single directory-whereas I need to reproduce the sub-directory structure too.

So I did the RTFM thing and found the "--parents" option in 'cp'. Voila- with this option your example works *perfectly*-well actually almost....
Code:
find /home/ -name "*.doc" -exec cp -pPvf --parents {} /new_root_dir \;


unfortunately this also copies /home into the new directory as a sub-directory. But this is no big deal to rectify after the fact(ie. run the command, switch to the new 'home' dir(in your example 'new_root-dir'), then switch to the 'home' sub-directory and do a cp -ax *.* ..' to move all the sub-dirs back to the parent-ie. the new 'home' directory.....)

perhaps there is also a way around this nuissance. ie. '--parents' copies /home/subdirs to the new 'home' whereas I just need to copie /subdirs to the new 'home'. Like I said, however, that is no big problem....

now my question is:
when I add the new users, using useradd and pwconvert, will it use the subdirs already created or overwrite them ? Perhaps I should migrate the users first and then copy the files......

thanks for your help...your example just saved me many,many hours.....
Back to top
View user's profile Send private message
grooveman
Veteran
Veteran


Joined: 24 Feb 2003
Posts: 1217

PostPosted: Thu Sep 11, 2003 1:28 am    Post subject: Reply with quote

umm no...

The -P option should take care of replicating the subdirectories as it does the same thing as --parents.

I tried it out a few times before I posted it, and I have used it many times before, and it works nicely.

Are you certain you did it as I had written it? I think you forgot the - capitol P. That would dump them all to the same directory rather than replicating the directory tree. That is bad form, of course, because files will almost certainly be over-written as the find progresses.

If you don't want the 'home' level replicated, you can start in home and do a "find . -name blah blah blah".... that will start with the subdirectories under home. ..But then again, that is why I said "/new_root_dir" and not "/new_home_dir", what I had written should have dumped things appropriately --assuming you were trying to put the files in a new "/home" directory and not somewhere else.

Again, I cannot help you with pwconvert, although I would suggest you take care to make certain that the uid and gid of each home directory matches the intended uid/gid of each user, and that the perms are appropriate. Users without the appropriate perms/ownership will find themselves without an env ;).

Hope it works out for you.

Chris
_________________
To look without without looking within is like looking without without looking at all.
Back to top
View user's profile Send private message
M.A.
Apprentice
Apprentice


Joined: 21 Mar 2003
Posts: 168
Location: /home/España/Valencia

PostPosted: Thu Sep 11, 2003 1:52 am    Post subject: Reply with quote

For solving the password users problem, why can't you just copy /etc/passwd and /etc/shadow into your new system? Then you will only have to delete the not valid users (for example, some qmail user and you are not using qmail anymore).
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Networking & Security All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum