0% found this document useful (0 votes)
40 views

Bologna Mirroring of Catania Production Status: R. Barbera, M.L. Luvisetto, F. Pierella July 25, 2001

This document describes the process for mirroring a MySQL database from a remote server to a local server in 5 steps: 1. Dump all tables from the remote database and compress them into a file locally. 2. Automatically dump all log files from the remote server via FTP. 3. Update the local database by deleting the previous version, recreating the database, and importing the dumped table data. 4. Update dates displayed on the local website by reading the modification time of the dumped data file. 5. Configure automatic periodic execution of steps 1-3 via a cronjob running a shell script every 2 hours.

Uploaded by

postscript
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PS, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views

Bologna Mirroring of Catania Production Status: R. Barbera, M.L. Luvisetto, F. Pierella July 25, 2001

This document describes the process for mirroring a MySQL database from a remote server to a local server in 5 steps: 1. Dump all tables from the remote database and compress them into a file locally. 2. Automatically dump all log files from the remote server via FTP. 3. Update the local database by deleting the previous version, recreating the database, and importing the dumped table data. 4. Update dates displayed on the local website by reading the modification time of the dumped data file. 5. Configure automatic periodic execution of steps 1-3 via a cronjob running a shell script every 2 hours.

Uploaded by

postscript
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PS, PDF, TXT or read online on Scribd
You are on page 1/ 6

Bologna mirroring of Catania Production Status

R. Barbera, M.L. Luvisetto, F. Pierella

July 25, 2001


Contents

1 DB mirroring using MySQL 2


1.1 Step 0: Prerequisites . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.2 Step 1: Dumping all tables of a remote DB . . . . . . . . . . . . 2
1.3 Step 2: Dumping all log files via ftp . . . . . . . . . . . . . . . . 3
1.4 Step 3: Updating the local DB . . . . . . . . . . . . . . . . . . . 3
1.5 Step 4: Updating the date in PHP and the server URL . . . . . . 3
1.6 Step 5: Automatic execution of Steps 1-2-3 via a cronjob . . . . 4

1
Chapter 1

DB mirroring using MySQL

1.1 Step 0: Prerequisites


In the following we assume MySQL to be installed in your bookkeeping server
with the PHP module1 .

1.2 Step 1: Dumping all tables of a remote DB


In order to dump all the tables of a database from a remote host assuming that
e.g.
• the remote database name is ppr;
• the remote host is alipc1.ct.infn.it;
• the username to access the database is username;
• the password to access the database is password;
• the file where you get locally a gz file containing all database tables will
named ppr.contents.gz 2
on the local server where you want to copy the remote database, execute the
following mysql command:
shell> mysqldump --host=alipc1.ct.infn.it --user=username
--password=password ppr | gzip > ppr.contents.gz
N.B.: the previous command must be typed on one single line.
1 You can download all MySQL Server/Client versions and the PHP MySQL module

mod php3-mysql-3.0.18-8cl.i386.rpm from ftp://alipc1.ct.infn.it/pub/grid/test/mysql.


2 Observe that for a database named db name, the gz file have to be named

db name.contents.gz.

2
1.3 Step 2: Dumping all log files via ftp
In order to dump automatically all log files via ftp we created for our example
the following csh script:
#!/bin/csh
echo "open aliserv2.ct.infn.it \\
user username password \\
bin \\
lcd /home/pierella/public_html/TOFWEB/DBMIRRORING/pprlog \\
cd /home/log \\
mget * \\
quit" | ftp -n -i -v > ftpbarbera.log

1.4 Step 3: Updating the local DB


In order to update your local database after dumping the remote database
(Step1), you have first to delete the previous version of your outdated local
copy, then recreate another one with the same name and then fill it with the
contents of the dump from Step1. In our example
shell> mysqladmin drop -f ppr
shell> mysqladmin create ppr
shell> gunzip < ppr.contents.gz | mysql ppr

1.5 Step 4: Updating the date in PHP and the


server URL
In order to put the date from the last update on your mirror site you have to
insert the following HTML-PHP code on your main local page or on all php
files, in our example this is the added code:
<h1 class="page-header"><center>Bologna Mirroring of
<a href="http://alipc1.ct.infn.it/PPR/PPRmain.php?off=0&nrow=20&rev=1">
Catania Production Status</a> <br>
<?php $filemod = filemtime("ppr.contents.gz");
$filemodtime = date("F j Y h:i:s A", $filemod);
Print("Last database tables and log files update $filemodtime");
?>
</center>
</h1>
The PHP code gets the creation date of file ppr.contents.gz - i.e. the re-
sult of Step1 dump- and in our example this file is in the same directory of
PPRmain.php file. Remember also to change the php variable $myurl. In our
case we changed in PPRsimul.php the line

3
$myurl="http://aliserv2.ct.infn.it/pprlog/";
into
$myurl="http://bogrid1.bo.infn.it/~pierella/TOFWEB/DBMIRRORING/pprlog/";

1.6 Step 5: Automatic execution of Steps 1-2-3


via a cronjob
In order to automatically - and periodically - perform steps 1, 2 and 3, create a
cronjob by inserting an appropriate crontab line that executes a mirror script
as described below.

• first create the shell script - in our case named mirroring.sh and stored
in /home/pierella/public html/TOFWEB/DBMIRRORING- as reported
below

#!/bin/sh
# go to the working dir
cd /home/pierella/public_html/TOFWEB/DBMIRRORING
# copy the previous version of the database into a save copy named ppr.prev.gz
cp -p ppr.contents.gz ppr.prev.gz
# dumping of the remote DB
mysqldump --host=alipc1.ct.infn.it --user=username \
--password=password ppr | gzip > ppr.contents.gz
# delete the previous outdated DB
mysqladmin drop -f ppr
# recreate another one containing no tables
mysqladmin create ppr
# fill the new DB with the tables of the dumping
gunzip < ppr.contents.gz | mysql ppr
# it is all for database updating, now we transfer the log files
# via ftp and we produce a log file
/home/pierella/private/ftplogsmirror.csh > \
/home/pierella/private/ftplogsmirror.log

• the user must create a crontab entry as follows - in our case it run every
2 hours -

0 0,2,4,6,8,10,12,14,16,18,20,22 * * *
/home/pierella/public_html/newtofwww/DBMIRRORING/mirroring.sh

N.B.: the crontab entry must be on one single line.

If more than one site performs the mirroring task, sites may agree on the starting
minute, so that the first field of crontab line may have the following values

4
0 , 30 , 60 , 90
and if 4 sites are mirroring with such different minute values then mirroring is
performed every 30 minutes.

You might also like