Posted by Marius Voila
on January 22, 2011
in London, U.K .
— 0 comments This post contains 1098 words
I wrote a shell script to assist in migrating an entire Linux CentOS 5.X server. The script should work with most Red Hat based Linux distributions such as Fedora, but I have not officially tested it. I only tested with CentOS and Ubuntu. The shell script can be used to move a server instance to a different physical server, or even move a server to a completely new data center or provider. I recently tested the script by moving a server instance of CentOS 5.5 x64 on Slicehost to Rackspace Cloud Servers successfully. It should also work migrating to Linode or Amazon Elastic Compute Cloud.
The script takes the entire source server and rsyncs everything that is important, to a destination server, excluding certain naughty directories such as /boot, /proc, /sys, /tmp, and /dev which should not be transferred. Make sure the destination server is a completely fresh install of the exact same operating system as the source. Also, the source and destination servers should be running the exact same kernel version, or else you may experience strange things like “Could not load /lib/modules/SOME-KERNEL-VERSION/SOME-MODULE-NAME”. The script automatically handles housekeeping such as installing rsync on both the source and destination servers. It also attempts to stop services on the source that should not be running when rsyncing to provide a consistent snapshot. You may modify the services the script stops on the source, currently it handles all the major popular services; Lighttpd, Apache, Nginx, MySQL, PostgreSQL, ProFTP, and Postfix.
The script tries its best to not copy any of the network configuration, but I found that one file must be modified on the destination once the rsync has completed. You must modify the gateway address in the file /etc/sysconfig/network on the destination server to the proper default gateway BEFORE REBOOTING. Once that is complete, simply reboot the destination server, and you should be completely migrated successfully.
Here is the script for everybody to use and enjoy. Simply copy it to your source server and run it with: sh migrateMe.sh. Let me know in the comments or shoot me an E-mail if you have any questions/comments or if you discover any bugs or weirdness.