Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I want to transfer my site to new host, moved everything there, but want to minimize database loss while DNS is pointing to the new name servers,

How can I do that?

More details:

Trasnfered files and database to the new host.

Changed DNS records tp the new name servers, witch will take sometime to update !

What I need: pointing the site on the old server to the new database in the new server so any new data won't be lost !

share|improve this question
3  
You tell us nothing in this question - how could we possibly help you with such little (non-existent actually) information. Read our FAQ and look around the site to see how the site works before posting again please. –  Chopper3 Apr 20 '12 at 10:58
    
Just updated my question –  phpjunky Apr 20 '12 at 11:03

4 Answers 4

up vote 6 down vote accepted

I do those migrations regularly. No downtime is hard, but low or allmost un-noticeable downtime is possible. The general idea is :

  • Do a hot backup of the origin server to the new one; that's a complete working copy while your origin is still working (on a LAMP server: run mysqldump on the origin then transfer the whole filesystem via rsync onto the target)
  • Either 1/ put the origin in read-only mode (shell> mount -remount o,ro /path/to/fs + mysql> flush tables with read lock) if the app handles it well, or 2/ display a maintenance page
  • Do a cold incremental backup, ie. re-dump your SQL and only transfer what was modified since the hot backup. With rsync, the cost merely depends on the number of inodes (files) on your target because they must all be tested for modification; it's rarely a bandwidth problem. On 1 - 10 GB sites with 100 - 500k inodes this incremental backup takes 1 sec to 1 min in my experience.
  • Setup a reverse proxy on the origin that redirects all trafic to the new target. You're done, and you can rollback in a few seconds if there's a problem (drop the reverse proxy part on the origin server). Obviously you have prepared the configuration in order a simple call to apachectl graceful is sufficient to apply it.
  • If everything went smoothly, you may finalize the migration and update your DNS (I usually do this 24h later). Then wait for the trafic to stop flowing from your origin server (usually another 24-48h).

Details are more tricky, but when it's your job and you're used to it it's actually easy. Besides knowing how to run 'rsync', 'mysqldump' and setting up a reverse proxy with a few lines in Apache, you're done.

Quite often you have to adjust a few things which are different from the origin and target server (like the hostname). In this case I write a small script that automates the backup part and the 'fixes' (using sed, perl, etc.). With rsync -a --delete you can use the same script for hot and cold backups.

The nice thing about this is that you don't depend on the DNS. In my experience DNS hosting is always awful or barely in control of the site owner. DNS updates from many DNS providers are unpredictable and un-debuggable. The TTL is ignored or mangled by most caching DNS servers. You run into this funny time window where many people don't see the same server using the same name, and it makes for very bad client relationships. Putting DNS out of the equation is a big win for me (unless I can directly host the DNS zone and then I'm 100% in control, but that's another story).

share|improve this answer

How I've done this before is to do master↔master replication between the 2 databases. This way, whichever actual server your incoming traffic is hitting, the database updates occur on both.

Replication is a pretty in-depth subject that can't be fully covered here, and you won't have enough time now before your DNS updates anyway, but it's a good idea for whenever the next move may be.

share|improve this answer
    
The domain name is in namecheap.com, and they are slow in dns updating !!, that's why I need to know how to do that :) –  phpjunky Apr 20 '12 at 11:12
1  
DNS provider is irrelevant - even if you can change the DNS immediately it will take varying amounts of time for every other DNS server to get the new values - setting a very low TTL doesn't help. –  symcbean Apr 20 '12 at 11:17

It's difficult to do without downtime but it is relatively simple to minimise the downtime.

  • Set up the sites to run concurrently with seperate data storage, take a snapshot of the old system switch the DNS records, then when you're happy that the DNS changes have propogated, migrate the data accumulated since the snapshot on the old site across to the new.

  • Allow access to the data storage of the new system from the old system, background sync up the new sites storage, disable processing on both old and new, resync the data to bring them back inline, switch the DNS to point to the new site and (at the same time) change the old site to use the new storage

  • set up an alternate domain name for the new site (e.g. new.example.com as well as www.example.com) but don't allow any transaction processing on the new name. Background sync the storage to the new box or copy over a snapshot. Disable all transaction procesing on the old machine, and resync the data. Enable transaction procesing on the new machine (both names) Configure the old machine to send a redirect to the new name on the new machine for all HTTP requests, and rewrite all hard coded URLs in the HTML / logic tier of both systems to use new.example.com in place of www.example.com. Once the old machine is no longer being used, revert the URLs back to www.example.com

It's not trivial but using the right tools, it should be able to automate most of this. If you're using database sequence generators / MySQL's auto-increment columns then you'll need a plan for preventing collisions.

share|improve this answer

This is how I did it:

  • Full back up on old host
  • Upload that back up to the new host.
  • Just before changing nameservers, I uploaded the database from the old to the new host.
  • Changed nameservers.
  • Made "under construction Home Page" on the old host.

In about 2 hours the domain name was pointing to the new host.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.