Migrating from Rackspace Cloud to Cpanel

From djlab.com

Fed up with cloud hosting? You’re not alone. Just recently, I assisted a mass exodus of over 50 mysql/joomla based sites. After the migration to just a modest dedicated server with Cpanel, MySQL queries improved by 200% on average. Some longer queries and page loading times saw improvement of over 1000%. Additionally, the dedicated server won’t fall on its face when a single script such as a DB backup process consumes ‘too many’ resources and the Cloud decides to put your whole site in the timeout corner.

Here are some scripts to migrate all your files and db’s from a RackSpace Cloud Sites instance to a Cpanel account quickly and easily. Run this script as the Cpanel user you’re migrating to to avoid ownership issues. If you run this as root, you’ll need to run the ownership repair script referenced below.

In addition to the correct chmod of files and folders (see part 1), you must ensure that all public_html files and folders have the correct (user and group) ownership. The following Perl code will eliminate nobody/root ownership. Place the Perl script into your /home directory and execute it.

#!/usr/bin/perl -w

my @dirs = grep -d,< *>;

foreach my $user (@dirs) {
`chown -R $user:$user $user/public_html/*`;
}

I was able to pull from 10-20 sites simultaneously and even .htaccess and other ‘hidden’ files came across intact.

The progress will be saved in /home/cpanel_user/xferlog.txt so you can monitor it in realtime. You can launch multiple scripts simultaneously to transfer many sites at once.

#!/bin/sh

RACKSPACE_CLOUD_FTP_USERNAME="rackspace_ftp_user"
RACKSPACE_CLOUD_FTP_PASSWORD="rackspace_ftp_password"
DOMAIN="www.myrackspacedomain.com"

LOCAL_CPANEL_USERNAME=cpanel_username

wget -rc --level=0 --no-parent --cut-dirs=3 -nH \
--directory-prefix=/home/$LOCAL_CPANEL_USERNAME/public_html/ \
--user="$RACKSPACE_CLOUD_FTP_USERNAME" \
--ftp-password="$RACKSPACE_CLOUD_FTP_PASSWORD" \
ftp://$RACKSPACE_CLOUD_FTP_IP/$DOMAIN/web/content/* \
-o /home/$LOCAL_CPANEL_USERNAME/xferlog.txt -nv &

Now, let’s migrate a mysql database (this can actually be used for migrating from any host, not just Rackspace). Place the file in the Cpanel user’s home folder so it can be run again right before your DNS switch so your records are totally up to date. You can run it as many times as you wish.

#!/bin/sh
# Rackspace Cloud to Cpanel DB copy

REMOTE_HOST="rackspace_cloud_mysql_ip"
REMOTE_DB="rackspace_cloud_mysql_db"
REMOTE_USER="rackspace_cloud_mysql_user"
REMOTE_PASS="rackspace_cloud_mysql_pass"

LOCAL_HOST="127.0.0.1"
LOCAL_DB="local_cpanel_mysql_db"
LOCAL_USER="local_cpanel_mysql_user"
LOCAL_PASS="local_cpanel_mysql_pass"

MYSQL="$(which mysql)"
MYSQLDUMP="$(which mysqldump)"

CMD="$MYSQLDUMP --lock-tables --add-drop-table \
-h'$REMOTE_HOST' -u'$REMOTE_USER' -p'$REMOTE_PASS' $REMOTE_DB \
| $MYSQL -h'$LOCAL_HOST' -u'$LOCAL_USER' -p'$LOCAL_PASS' --database $LOCAL_DB"

echo "Running: $CMD"
echo
eval $CMD

g33kadmin

I am a g33k, Linux blogger, developer, student and Tech Writer for Liquidweb.com/kb. My passion for all things tech drives my hunt for all the coolz. I often need a vacation after I get back from vacation....