If you’re joining me from part 1thank you. If you are just joining you may want to check out part 1.

    When I last left you I had just installed MySql and setup a root user with a strong password. Now I need to get all the domain web files and MySql Databases to my new server,  perserving permissions and ownership, hopefully. Before I accomplish any of this I need to create users and all their directories that hold the public web files for each domain. I am then going to create all the same databases and import all the database dumps. Lastly, I want to start Nginx and test all my old configuration files before activating them all.

I created new users first using useradd.

$useradd jabo

I then rsync’d each users files one at a time to try and preserve permissions. Notice I said “try” I later had to chmod each users web directory so they could have the correct ownership. The more advanced Linux users will know why, the UID # of each user didn’t match the UID on the old server but that is another post. So Rsync is awesome. I mirrored all my web files and sent them via ssh to my new server. In verbose mode of course.

$ rsync -r -a -v -e "ssh -l root" --delete /old/Server/path/ newserver.net:/webroot/path/

MySql is not my favorite from the command line but since this is a new server and I was in a rush I didn’t have time to install and setup PHPAdmin. Now this did not work for me as root. I had to make a dump using each database users username and password. That also meant I had to go rooting around in some of my users WordPress installs. not to tough.

$ /usr/bin/mysqldump -u root -p --opt >/web/root/alldatabases.sql

After a quick rsync of all the database files. I logged into MySQL from the command prompt then created new databases with the same passwords and usernames. Lastly, I restored each database with their respective user.

$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 162
Server version: 5.1.41-3ubuntu12.6 (Ubuntu)
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> create database testdb;
Query OK, 1 row affected (0.00 sec)
mysql> grant all on testdb.* to 'dbuser1' identified by 'db_user_pw';
Query OK, 0 rows affected (0.00 sec)
mysql> quit
Bye

Restore each database with the appropriate username and password.

$/bin/mysql -u username -ppassword databasename < /tmp/databasename.sql

With all that said and done I was finally ready to test if this all worked. I checked my Ngnix configuration files visually to make sure they made sense. I almost rubber ducked them but it was 3 am at the time, so the prospect of my girlfriend waking up to me talking to myself in front of a dim lit monitor was not appealing. I ran Nginx with the -t option and everything worked out. I then started Nginx and BEHOLD I have CONQUERED!

Now it didn’t work all gravy right out of the box. I was spawning like 100 PHP processes and my VPS Memory was zooming! With some help from Google and the Nginx Wiki I was able to trim Nginx to pre-migration levels. I still have lots of tweaking to do to make it run leaner and allowing MySQL to run for a few weeks before I tune. After all that I still stayed with MediaTemple. I really didn’t want to go through all that again with another hosts control panel I am not familiar with or worse C-panel.

UPDATE

Funny thing but two weeks later Media Temple decided to migrate the “new” VPS they gave me. Luckily, I got some attention from support, the next migration went well, and had no issues this time around. I know now what went wrong and I know how to prevent it in the future.