Copy users from one unix box to anoth...

Copy users from one unix box to another (RedHat 4/5 example)

 

On source server:

export UGIDLIMIT=500

mkdir /root/move

awk -v LIMIT=$UGIDLIMIT -F: '($3>=LIMIT) && ($3!=65534)' /etc/passwd > /root/move/passwd.mig

cat /root/move/passwd.mig


awk -v LIMIT=$UGIDLIMIT -F: '($3>=LIMIT) && ($3!=65534)' /etc/group > /root/move/group.mig

cat /root/move/group.mig

awk -v LIMIT=$UGIDLIMIT -F: '($3>=LIMIT) && ($3!=65534) {print $1}' /etc/passwd | tee - |egrep -f - /etc/shadow > /root/move/shadow.mig

cat /root/move/shadow.mig


rsync the data over provided you've setup new host with an alternate IP with and temporarily permitted root ssh in sshd_config:

rsync -avz oldserver:/home/  /home

rsync -avz oldserver:/path/  /path


or:

tar zcvf /tmp/homes.tgz /home

tar zcvf /tmp/mail.tgz /var/spool/mail


use scp or sftp to move backup *.mig and *.gz files over to the new server /tmp directory then delete the *.gz files from the source server to free up space


On the target server:

cd /tmp
cat passwd.mig >> /etc/passwd

vi /etc/passwd  # to verify things look correct
vi passwd.img

cat group.mig >> /etc/group

vi /etc/group

cat shadow.mig >> /etc/shadow
vi /etc/shadow

cd /
tar -zxvf /tmp/home.tgz
rm -rf /tmp/home.tgz

cd /
tar -zxvf /tmp/mail.tgz
rm -rf /tmp/mail.tgz

reboot the server once all files have been verified and are correctly formatted


No comments: