Migrate/Move accounts to new Linux Server

One of our client had a CentOS Server with no control panel and we were managing it. Now he bought a new powerful server and wanted us to migrate all the data to new server. So we did some research and were able to successfully able to migrate all his data to new server.

First of all we installed the exact same version of Apache, PHP and MySQL on the new server with all the modules that were present on his old server. Then we followed the below steps to do the migration.

Create a temporary directory for migration contents.
[bash]
mkdir /root/migration
[/bash]

The normal user starts with UID and GID of 500. So copy only users with uid greater than 500. For debian and ubuntu the value is 1000. UID 65534 is usually used for the nfsnobody account

[bash]
export USERIDLIMIT=500
awk -F: ‘($3>=USERIDLIMIT) && ($3!=65534)’ /etc/passwd > /root/migration/passwd.mig
awk -F: ‘($3>=USERIDLIMIT) && ($3!=65534)’ /etc/group > /root/migration/group.mig
awk -F: ‘($3>=USERIDLIMIT) && ($3!=65534) { print($1)}’ /etc/passwd | tee – | egrep -f – /etc/shadow > /root/migration/group.mig
cp -a /etc/gshadow /root/migration/gshadow.mig
[/bash]
Now copy migration folder to new server
[bash]
scp -r /root/migration root@new_server_ip:/root/
[/bash]

Now login to new server and perform the below task.

First make backup of existing files in case something went wrong.
[bash]
mkdir /root/backup
cp -a /etc/passwd /etc/shadow /etc/group /etc/gshadow /root/backup/
[/bash]

Now append passwd.mig , shadow.mig and other files to passwd, shadow and other files respectively
[bash]
cd /root/migration/
cat passwd.mig >> /etc/passwd
cat group.mig >> /etc/group
cat shadow.mig >> /etc/shadow
cp gshadow.mig /etc/gshadow
[/bash]

Now go back to old server and rsync the /home, mails, cron jobs and MySQL to the new server.
Note: Make sure MySQL server is stopped on new server and it’s the same version as the old server.
[bash]
rsync -vrplogDtH /home/* root@new_server_ip:/home/
rsync -vrplogDtH /var/spool/mail/* root@new_server_ip:/var/spool/mail/
rsync -vrplogDtH /var/spool/cron/* root@new_server_ip:/var/spool/cron/
rsync -vrplogDtH /var/lib/mysql/* root@new_server_ip:/var/lib/mysql/
[/bash]
Now Copy the apache configuration files
[bash]
rsync -vrplogDtH /etc/httpd/conf.d/* root@new_server_ip:/etc/httpd/conf.d/
[/bash]
Now reboot the new server and it’s done.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *


three − = 1