I have a database and webserver set up on one machine, and I want to mirror the system onto another machine. The original database is running ubuntu 9.1, the new system has ubuntu 11.04 installed (but can be wiped, it's a completely new box). I'm imagining that I plug both systems on to my router, have them become aware of each other somehow, and then data would move magically from one to another. What can I do to get started with this process?

EDIT: I think I'm using the word 'mirror' incorrectly. What I want to do is to copy the working system onto the new system. Then, I want to periodically copy data back and forth to make sure that the two are kept in sync. The periodic copying is secondary; initially, I just want to move the data from one to the next (including the mysql database, website, all patches, etc). I'll worry about later copies later.

EDIT2 for more clarity, I guess the best description of what I want to do is to make a time machine backup of one machine and then restore to the other. Ideally, I would skip the intermediate step of going to an external hard drive.

  • It doesn't work that way. Keeping DBs in sync depends on what the DB is, and keeping the web content in sync will probably involve rsync or other copy methods. – mfinni Jun 23 '11 at 18:05
  • so there's no way, for some kind of initial setup at least, to just copy bits over? – mmr Jun 23 '11 at 18:06
  • perhaps 'mirror' is the wrong word. What I want to do is make a copy of one system on the other, and then come up with some way to make them synchronize. Editing to reflect that... – mmr Jun 23 '11 at 18:09

To just do a straight mirror of the bits, use dd. Its a bit stream duplicator. Fairly standard stuff.

Here is some more info to get you started:


Keeping it in sync is a different story. You could just redo the initial copy every so often if that meets your needs. Or you can do some combo of rsync to keep the webroot synced, and then use one of the many available methods for mysql synchronization. That is a whole different can of worms which you'll want to research independently. I'm sure there are some old questions about that already existing on server fault.


Based on your comments and updates, you should focus on getting one box fully working. Either move the mysql dumps and web root files to the ubuntu 11 box, then configure it so it functions the same, get it to a working stable state. To get those files over, use SCP, it allows you to easily transfer files over SSH. Or you can try to get the ubuntu 9 box in completely working shape.

Then when whatever server you chose is in a good place, you can use DD and netcat, or ssh or any number of ways to do a straight bit by bit mirror copy to the other machine.

Then... for future sync, you can use rsync for webroot and config files. And choose your own method for mysql, you can script dumps, scp transfers, and imports, or you can go with something more complicated, it really depends on what your needs are.

  • one of the impeti for this copy is that the 9.10 server is showing some problems when running fsck. Won't dd just replicate those problems? – mmr Jun 23 '11 at 18:28
  • @mmr In your comment you said you wanted to copy bits, that's what DD does.. a straight bit copy one for one. Problems and all will transfer. If you are trying to do a production/development type setup, you're going to want EVERYTHING to be identical. So I'd move things around as needed to get one system working perfectly, then DD it to the other, and then go for partial syncs of just the data in the future. – profitphp Jun 23 '11 at 18:32
  • @profitphp-- that's exactly what I'm trying to do. I think the problem is that our one system is showing issues, so maybe bitwise copying isn't the solution, but more that we copy over the relevant files. If dd is the right way to do this, then I suppose I'll go for that. I guess the first thing is to make sure that the one system doesn't have these issues. – mmr Jun 23 '11 at 18:37
  • Are you seriously suggesting using 'dd' to keep a MySQL database in sync? If the database is active, that will not work. – mfinni Jun 23 '11 at 18:41
  • Sorry - I see at the end you point out that mysql is not covered by this. -1 for my reading comprehension. – mfinni Jun 23 '11 at 18:41

You CAN accomplish this, though I'm not sold that how you'd have to do it would be entirely useful to you. It mostly depends on your mastery of DNS within your network and now you want to use everything.

I've actually been toying with the idea of setting something similar to this up for myself.

The key things to know is that once you've got the two boxes configured similarly enough (all the necessary Apache modules, etc).. Then you've got a few things you need to keep in line for this all to work:

  1. Web root - you've got some files, Apache's config calls these your DocumentRoot - this is where the files that are hosted on your website are stored. You'll need to sync this directory. By default, this should be /var/www/ (though if you get in to virtual hosts, then you have to give other locations, I put mine in /www/[domain name]/.

  2. Database - you said you've got a database involved.. Obviously you'll need this copied over accordingly. Provided you're on MySQL, you COULD use mysqldump to get the database out. Google around to learn how to backup & restore with mysqldump.

  3. Configuration files - if your case is really simple, then you'd probably only need to do this once. Your website is configured in your web server software (which I've assumed is Apache) through a config file (possibly several depending). If you're in to Virtual Hosting on Apache 2.x, then you'll likely have a config file for each site you're hosting on that server. You may need/want to sync that. Keep in mind that'll at least have to "reload" your apache config after replacing it on a machine.

So, the process as I see it would involve using something like rsync to copy over the files. You can make ssh calls that execute something and terminate that you'd also need (possibly to call some script on the receiving end to do whatever else you may need).

Now, as I've explained this the machine running with the copy would totally just be a mirror that if anyone changed any data on it, that'd just get clobbered on the next sync. If you want to have multiple servers hosting the same site for load balancing purposes.. Then I think you'd want to get in to having a separate database server that your web servers talk to and you'd want to use something like NFS to provide a single copy of the web root to the servers. You could then look in to configuring a reverse proxy to transparently load balance the servers for you. "pound" is a reasonably simple reverse proxy you could use.


For the initial mirrors:

  1. Configuration files for Apahce and MySql - most probably you will need to do this manually, as there might be some changes in their structure between the versions
  2. Web site - just copy over the directory/file structure
  3. Database - depends ot the engine, but if its MySql - mysqldump and then import in the new one

For the periodic update:

  1. Config files - again it might be done manually. But usually it is not so common to frequently change config files, or even if so, the changes are minor
  2. Web site - I would put some effort to place all the files in some source control system - lets say svn, and update both servers out of it, not directly on the server1 and then copy over to server2
  3. Database - either again mysqldump, and then restore on server2, or setup some master/slave configuration, so the data is always in sync.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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