一: 目的.

   现有服务器用户,完整迁移到一台新服务器.

二: 环境:

源: 117

cat /etc/redhat-release

CentOS release 6.9 (Final)

rpm -qa rsync

rsync-3.0.6-12.el6.x86_64

目的114

cat /etc/redhat-release

CentOS Linux release 7.2.1511 (Core)

三:

117:


export UGIDLIMIT=500    //设置一个变量, 新建的uid 从500开始.

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

awk -v LIMIT=$UGIDLIMIT -F: '($3>=LIMIT) && ($3!=65534)' /etc/group > /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

cp /etc/gshadow /root/move/gshadow.mig

rsync -e ssh -avpr /root/move/ [email protected]:/tmp/temp    //  把旧服务器的4个文件, copy至新服务器上.

rsync -e ssh -avpr /home [email protected]:/              //把旧服务器上的home整个目录,copy到新服务器上.

本例不考虑/var/spool/mail

四:  114:

30  cat passwd.mig >> /etc/passwd

31  cat group.mig >> /etc/group

33  cat shadow.mig >> /etc/shadow

34  cp gshadow.mig /etc/gshadow

[root@localhost home]#  ls -sail /etc/{passwd,group,shadow,gshadow}

135184942 4 -rw-r--r--. 1 root root  731 Aug 15 12:38 /etc/group

135184896 4 ----------. 1 root root  509 Aug 15 12:39 /etc/gshadow

135411669 4 -rw-r--r--. 1 root root 1598 Aug 15 12:38 /etc/passwd

135411670 4 ----------. 1 root root 1854 Aug 15 12:38 /etc/shadow