This article explains how to move or migrate the following from old Linux server to new Linux server.

A few days ago I purchased a new system and I wanted to migrate a working server system to this new system. Rather than reinstalling the server or swapping the hard drive, I transferred only a small amount of files and I was up and running with a functional server in a matter of minutes !!

The following is to be moved/migrated to new system

  • Existing user accounts
  • Service data with configurations (in my case apache, sshd and vsftpd)
  • Application data with permissions (in my case /home and /srv/www)

I am using an OpenSuse system in this article, however you may use any LSB compliant system for a similar result.

Install the new system with similar operating system of your choice. Also include service applications such as Apache etc as part of the installation, or post-installation configuration. Prefer using a similar operating system to avoid further complications. For example, if you are migrating from Fedora to an Ubuntu system, you will encounter a lot of complications because both system, however LSB compliant, have entirely different approach to application layout. One may require more experience than the scope of this document to accomplish it.

Note : Create a functional backup before proceeding to execute any command that follow. Also make sure that the backups are working in case of a disaster.

Migrate the existing user account to new system

User account information is stored in three files on a Linux system:

  • /etc/passwd : Basic information about the account login
  • /etc/shadow : Contains encrypted password information of user accounts and optinally the password aging information
  • /etc/group : Defines the user and service groups on the system
  • /etc/gshadow : The group shadow file (contains encrypted password for group)

We need to create a directory to keep all the migrated data into one place and move all at once restoring them on new system.

create a migration directory on the old server
# mkdir /root/MIGRATE

set up a UID limit variable
# export UGIDLIMIT=500

copy the filles with a filter using awk :
# awk -v LIMIT=$UGIDLIMIT -F: ‘($3>=LIMIT) && ($3!=65534)’ /etc/passwd > /root/MIGRATE/passwd.mig

# awk -v LIMIT=$UGIDLIMIT -F: ‘($3>=LIMIT) && ($3!=65534)’ /etc/group > /root/MIGRATE/group.mig

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

This is rarely used nowadays
# cp /etc/gshadow /root/MIGRATE/gshadow.mig

You need to manually edit these copied files to remove all the accounts and groups that you do not want to transfer.

Transfer the directory /root/MIGRATE on the new server with correct permission with either using tarball , or using rsync etc:

Tarball method :

# tar -cvzf /root/MIGRATE.tar /root/MIGRATE
# scp /root/MIGRATE.tar NEW_SERVER_IP:/root

Log into the New Server (if its remote the use ssh etc.)
# ssh NEW_SERVER_IP

Extract the Tarball
# tar -xvzf /MIGRATE.tar
# cd /root/MIGRATE

Rsync Method :

# rsync -avz /root/MIGRATE NEW_SERVER_IP:/root/

Restoring user account information is a straight forward method to concatenate the new data into new system using the simple cat >> append feature. Additional safely would be to keep a backup of existing user account info in case something goes wrong.

 Execute the following command into the new system:

# mkdir /root/MIG_BKP
# cp /etc/passwd /etc/shadow /etc/group /etc/gshadow /root/MIG_BKP
# cd /root/MIGRATE
# for i in passwd shadow group gshadow ; do cat $i >> /etc/$i ; done

This completes the user account transfer. Do not reboot the system now. We will reboot after all the steps are complete.

Copy Service data with configurations to new system

Configuration data depends on the service that your run on the system. In my case, I use my old server for web-hosting, so the most important services for me are Apache, sshd and Vsftpd. I simply copy the config files onto the new server and start the services.

Backup the existing service directories in /etc. When on the new server execute the following commands

# cd /etc
# tar -cvzf apache2-`date –iso`.tar.gz apache2
# tar -cvzf sshd-`date –iso`.tar.gz sshd
# tar -cvzf vsftpd-`date –iso`.tar.gz vsftpd

Copy the config files from the old server. From the old server execute the commands

# cd /etc
# rsync -avz /etc/apache2/ NEW_SERVER_IP:/etc/apache2/
# rsync -avz /etc/sshd/ NEW_SERVER_IP:/etc/sshd/
# rsync -avz /etc/vsftpd/ NEW_SERVER_IP:/etc/vsftpd/

You dont need to start the services as of now. We will do it later after application data moves to the new server.

Transfer Application Data with correct permissions

Application data could include a number of components, however I would only transfer /home and /srv/www on my new server. We would again use rsync for the purpose:

From the Old Server Execute the commands:

# rsync -avz /home/ NEW_SERVER_IP:/home
# rsync -avz /srv/www/ NEW_SERVER_IP:/srv/www

Finalization of the Migration and Troubleshooting

To check if the user accounts has been created, log into the system with some other user from the old server into the new server.

To check if the services function, try the following command on new server

# /etc/init.d/apache2 restart
# /etc/init.d/sshd restart
# /ect/init.d/vsftpd restart

.. and finally reboot the system with command

# /sbin/reboot

If everything is correctly followed, you should be able to run the new system will all the migrated accounts and services.

Feel free to post comments and questions. Cheers !!

  1. chirag Pankhaniya

    Respected Sir;

    I am chirag Pankhaniya

    Mobile No Is 08971563079
    Thanks

  2. John

    Nice article. Was a great help. Thanks.

Leave a Reply

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