Novell Home

Using RSYNC to Distribute a MySQL Database to a NetWare Server

Novell Cool Solutions: Feature
By Florian Deckert

Digg This - Slashdot This

Posted: 29 Sep 2005
 

Problem:

Replicating a dynamic web server (AMP) to a NetWare box using RSYNC

Solution:

In a previous article, I described how to use RSYNC to distribute a static web server. Now I'll show you how to extend this to distribute a MySQL database. As always it's using the (yet) unsupported RSYNC.

One way would be to link the MySQL databases in master-slave mode. But I prefer distributing without changing the existing environment.

So, we're using the MySQL dump/restore commands.

On the linux box create a script dumping the database (use the crontab to schedule it) and setup RSYNC to publish this folder.

dump.sh
mysqldump -u USER -pPASSWORD mydb >/database/dump.sql

/etc/rsyncd.conf
[mysql]
      path = /database
      comment = private dump of our database
      read only = yes
      host allows = myserver.remote.corp 

On the remote NetWare server you can start a RSYNC client:

rsync -arvz --delete myserver.central.corp::INTRANET VOL1:/database

Now we will use a Cool Solutions tool to handle cleaning up and reloading the replicated DB from the dump.

We're going to use stuffkey and the following files:

sys:/tmp/init.sql
drop database if exists mydb;
create database mydb;

sys:/tmp/reload.sk
#+------------------------------
#| Clear the MySQLdump screen
#+------------------------------
<SCREEN=System Console>
mysql -u USER -pPASSWORD <\<>sys:/tmp/init.sql<cr>
<WAITFOR SCREEN=MySQL Monitor>
<3000 pause>
<cr>
<SCREEN=System Console>
mysql -u USER -pPASSWORD mydb <\<>VOL1:/database/dump.sql<cr>
<WAITFOR SCREEN=MySQL Monitor>
<3000 pause>
<cr>
#
#End

And finally we can use Stuffkey (eg in crontab)

stuffkey sys:/tmp/reload.sk

Now, with the replicated PHP files (check my previous article) and now the replicated MySQL database, we have an exact local copy of our dynamic web server.

And what is really cool, is that using this, we were able to replicate a Linux box running Apache 1.3 and MySQL 3.5 to NetWare boxes running Apache 2.0 and MySQL 4.0 :-)


Novell Cool Solutions (corporate web communities) are produced by WebWise Solutions. www.webwiseone.com

© 2014 Novell