Tag Archive - mysql

rsnapshot and mysqldump

rsnapshot is a nifty little perl script for managing rsync backups in an easy way. rsync is great for backing up almost everything, but MySQL databases is an exception, since the files could get corrupted if data is not flushed and locked prior to backup.

To use mysqldump with rsnapshot the following script can be placed on the target machine (the machine being backed up). The script can of course be modified to use mysqlhotcopy instead of mysqldump, the principle is still the same.

#!/bin/bash
 
PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
 
backupdir="/tmp/mysqldump"
 
if [ ! -d $backupdir ]; then
        mkdir -p $backupdir
fi
 
chmod -R 700 $backupdir
 
case $1 in
        run)
                for db in `mysql --defaults-file=.my.cnf -e 'show databases' |tr -d '| ' |grep -v 'Database' |grep -v 'information_schema'`; do
                        mysqldump --defaults-file=.my.cnf $db |gzip > $backupdir/$db.sql.gz
                done
        ;;
 
        clean)
                rm -f $backupdir/*.sql.gz
        ;;
esac

A .my.cnf file also needs to be created on the target machine in the home folder of the backup user (probably root), with the following content. This is because we dont wont to pass the password as a command line argument (visible to other users).

[client]
user=root
password=<password>

Then use the following configuration for rsnapshot.

backup_script   /usr/bin/ssh root@example.com "/root/backup.sh run"   unused0/
backup          root@example.com:/tmp/mysqldump/                      example.com/
backup_script   /usr/bin/ssh root@example.com "/root/backup.sh clean" unused1/

This assumes that SSH key authentication is already configured. Adjust path and user names accordingly.

Comparison of APC and XCache

APC
Alternative PHP Cache, will be included in the core of PHP 6.

XCache
Developed by one of the developers of Lighttpd.

Benchmarks where done on a small Amazon EC2 instance, running official Ubuntu 9.10 image. Benchmarks where done on two different occasions, average results are used. The following packages are installed from APT.

  • libapache2-mod-php5
  • php5-mysql
  • php-apc
  • php5-xcache
  • mysql-server

The following web sites will be tested

  • Hello World script
  • WordPress 2.9.1
  • Joomla 1.5.15

Benchmarking itself is done with ab (Apache benchmarking tool) on localhost, doing 1000 requests over 10 connections (-n 1000 -c 10). Interesting numbers are request per second.

Here’s the results, numbers are requests per second, the percent is the improvement.

Without accelerator With APC With XCache
Hello World 1499 1602 (7%) 1563 (4%)
WordPress 2,82 12,61 (347%) 12,97 (360%)
Joomla 2,25 3,60 (60%) 3,48 (55%)

The big increase in WordPress performance could be because not much sample data is installed in the default installation (compared to the option in the Joomla install, which i used), which could mean that the large bottleneck in Joomla is MySQL not PHP, while being the other way around for WordPress. But even with large amount of data, the performance improvement should be good.

Conclusion
Since there isn’t any big difference in performance between the two, I would choose APC. Mainly because it will be included in the core of PHP 6.