Server Migration Process

This is a tutorial for moving of server data from one server to another. i consider you have setup the server using guide http://zain.pk/setup-of-ubuntu-server-or-ubuntu-desktop-on-virtualbox/ The link shows how to install server on virtualbox. Production server is not much different then running server on virtual machine. Things we will consider moving from server are user home directory, databases, websites, svn. i have divided server migration tasks into two main categories.

  • Commands will run on old server which will take backup of data.
  • Commands will run on new server which will import data.

OLD SERVER

We will clean all unnecessary data from ‘/home’, ‘/var/www/ directory or any other directory which has backups or garbage files.

Now its time to take backup of databases but before we move forward its good to repair all databases.

Database Backup Option1: Take backup of all databases except few mysql specific databases. Replace USERNAME, PASSWORD in the command below.

Database Backup Option2: You can take backup of databases by listing databases in commands. Replace USERNAME, DATABASE_NAME with real information.

Database Backup Option3: If your mysql version is same and you don’t take about importing of mysql internal tables you can run this command to backup databases. Replace USERNAME with real username.

Now we need to take backup of cronjobs. Cronjobs are user specific and we will take backup of each user cronjobs. Replace USERNAME with logged in user.

Change the user with command below and run the above command again for that user.

We need to take backup of svn database.

Now we will zip the svn repo

Delete the svn dump file as we would be moving all things from folder /home/backup-2014-05-26 and svn dump without zip will increase folder size.

 

 

NEW SERVER

We will start rsync from newly created server and import data. You can learn more about rsync on “rsync command examples

You should have rsync installed on both machines to get rsync working

Copy data website’s data which in my case is in /var/www/

Copy backup of old server data which include database sql zipped file, cronjobs, etc.

Unzip sql file on new server

Import database file into MySql

We will now import cronjob for each user. Change the user with command below.

Run the command to import cronjob for that user. Replace USERNAME with actual user.

Repeat the process for each user cronjob.

Once done you should restart cron.

Create a virtual host file for the websites by creating a file in apache sites available folder

You now need to activate apache virtual hosts

Now reload  apache server to load new configurations

Now you need to change domian dns to see the effect but  you can replicate that scenario by changing your machine host file. You can bluff your system to point a domain to different server IP. Open file on windows machine C:\Windows\System32\drivers\etc\host and add a line. First segment will be your IP and second is your domain.

Check if your website is working properly and not giving any errors. If all is good. Comment the line above or delete it.

Now go to your domain registrar and under manage DNS change A record for your domain-name.com to new server IP. It will take some time to propagate. you can open command prompt and ping your domain to see new IP change.

you can check status on website “Whats My DNS” for A recrod change. https://www.whatsmydns.net/ or open command prompt and type the following command to see IP change.

All websites are live and one thing is left to imported which is svn. Run the command to unzip svn data.

Now we will import data into svn repo