Prepare to migrate a Linux server

This article provides recommended actions that you can perform before you migrate your server to mitigate common issues and optimize your server for a faster transition. These recommendations are based on common issues identified by our support technicians and are not required operations. Some of these recommendations can cause significant downtime, so you should schedule them accordingly.

Back up your data

Before you perform any migration, create a file-level backup of important data. You can use Rackspace Cloud Backup to automate the storing and retrieving of backup data from Cloud Files, or you can use rsync to copy your data to another server.

General preparation

The following tasks help to avoid issues with server time and the size of the disk space on the server.

Set accurate time via NTP

Some older cloud servers pull time from their host machine instead of keeping time independently from the host. Unfortunately, the time set on these hosts can be inaccurate. To avoid migration issues related to the server date or file time stamps, set up and configure Network Time Protocol (NTP) on your server.

For details on setting up NTP on your server, see Using NTP to sync time.

Establish a log rotation policy

Large log files can potentially increase the time for a migration or the size of a created image. Application and virtual host logs aren't generally rotated unless you specifically set up rotation for them.

Use a utility like logrotate to ensure that your log files stay at a reasonable size.

Prune and archive old data

Look for and remove archived log files, application cache files, and old tables or entries in databases. The more you can remove the less there will be to copy to the new server.

Ruby on Rails applications in particular can create a large number of session files and never delete them. Before a migration, find out where your applications might store those session and cache files.

For more information about locating and pruning old session and cache files, see Migrating a Linux Server from the Command Line - Tips for Speeding Up Rsync.

Check for large files

Removing other large files from the server can also cut down on the overall copy time or image size.

Use the find utility to look for the largest files on your system.

sudo find / -mount -type f -ls|sort -rnk7 |head -30|awk '{printf "%10d MB\t%s\n",($7/1024)/1024,$NF}'

The output shows the largest files on your cloud server. Determine whether any of these files can be deleted or archived elsewhere.

Right before the migration

You can reduce the time required for a migration and improve the reliability of a resulting image by reducing the number and size of files that might change during the migration operation.

Force log rotations

Applications that are running during a migration might generate new log entries. If you force a log rotation beforehand you can ensure that any changes to log files will be relatively small. Most log rotation utilities enable you to force rotations manually.

For example, if you're using logrotate to manage your application logs you can force a rotation by using the command:

sudo logrotate -f /etc/logrotate.conf

Lock databases

If a database changes during a migration, data could be lost data or the database in the image could be corrupted.

We recommend that you bring the database down entirely for the migration. If that isn't practical, however, make your tables read-only so that they won't be written to during the operation.

To lock your tables in MySQL, run the following command:

mysql -u root -p --execute="FLUSH TABLES WITH READ LOCK"

Flush application caches

Clearing out old, unneeded session and cache files can prevent them from slowing down the migration. Copying many very small cache or data files can take more time than copying one file of the same total size.

After a migration

After a migration is complete and your new server starts, you should test your web sites and applications. Ensure that applications are responsive and that they can write information to their databases.

If you have any services that need to communicate to other servers, explicitly test their connectivity to ensure that they still talk to each other.

Further reading

For migrations that use rsync to transfer files, see the more detailed advice in Migrating a Linux Server From the Command Line - Tips For Speeding Up Rsync.

Was this content helpful?

© 2015 Rackspace US, Inc.

Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License

See license specifics and DISCLAIMER