Nasser Heidari

2010-07-20

Move user accounts from old Linux server to a new Linux server

Filed under: Linux — Nasser Heidari @ 16:37

Following files/dirs are required for traditional Linux user management:

/etc/passwd – contains various pieces of information for each user account
/etc/shadow – contains the encrypted password information for user’s accounts and optional the password aging information.
/etc/group – defines the groups to which users belong
/etc/gshadow – group shadow file (contains the encrypted password for group)
/var/spool/mail – Generally user emails are stored here.
/home – All Users data is stored here.

————-
Backup Routine:
————-

# mkdir /root/move/
# export UGIDLIMIT=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
# tar -zcvpf /root/move/home.tar.gz /home
# tar -zcvpf /root/move/mail.tar.gz /var/spool/mail

————- Move Backup Files to New Linux Server: ————-

scp -r /root/move/*  nasser@linax.wordpress.com:/var/tmp

————- Restore : ————-

# mkdir /root/newsusers.bak

# cp /etc/passwd /etc/shadow /etc/group /etc/gshadow /root/newsusers.bak

# cd /var/tmp

# cat passwd.mig >> /etc/passwd

# cat group.mig >> /etc/group

# cat shadow.mig >> /etc/shadow

# /bin/cp gshadow.mig /etc/gshadow

# cd /

# tar -zxvf /var/tmp/home.tar.gz

# tar -zxvf /var/tmp/mail.tar.gz

Advertisements

4 Comments »

  1. Quick, exact and useful as same as always buddy

    Comment by Hamed Kazemian — 2010-07-21 @ 21:09

  2. :-)

    Comment by Nasser Heidari — 2010-07-22 @ 09:17

  3. fix
    tar -zcvpf /root/move/mail.tar.gz /var/spool/mail
    should be
    tar -zcvpf /root/move/mail.tar.gz /var/spool/mail/*
    Thank you very much for this guide!

    Comment by Dmitry Paskal — 2012-05-12 @ 10:24

  4. […] статья о переносе пользователей со старого linux сервера…. Вместо tar -zcvpf /root/move/mail.tar.gz /var/spool/mail читать tar -zcvpf […]

    Pingback by Перенос пользователей со старого linux сервера на новый » Paskal's notes — 2012-05-12 @ 12:44


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: