Thursday, February 21, 2013

Mysql backup using php script

When you make backup using mysqldump, you will get one big file in your backup folder. If you want to move the backup file to another server or just want to save it in your local computer, it will take time because of the size of the file. Indeed, you can split it per table. This script can help you to backup your mysql database, and splits the backup file every 10 tables.

Wednesday, February 20, 2013

Simple bash script to kill stalled application

Sometimes, your application was stalled and stay in memory and never exit. For this, you can create a simple bash script to define whether the application is worth to be killed. This example will kill wkhtmltopdf-amd application that has state Sl and have been running for more than 1 hour. You can then call this script via cron, to call it periodically.
get_proc=`ps -C wkhtmltopdf-amd -o pid=,stat=,etime= | awk '{if ($2 == "Sl" && !(substr($3,0,2)+0 < 1) ) print $1; }'`
for i in $get_proc
 kill -9 $i

Monday, February 18, 2013

MySQL Apache Failover System with DRBD, Pacemaker, Corosync


To setup a failover system with Pacemaker, Corosync and DRBD, we need 2 servers, 3 IP address in the same subnet and one partition with same size in both server. In this setup, mysql and apache are already configured
Software requirement:
  1. DRBD & drbdlinks
  2. Pacemaker & Corosync
  3. psmisc package (needed by pacemaker)

It is highly recommended to use separate network adapters for synchronization but it is also work with 1 network adapter.
In this example, we use below configuration:
  • Node 1, hostname: fo2, ip:, synchronization partition: /dev/sdb1
  • Node 2, hostname: fo3, ip:, synchronization partition: /dev/sdb1
  • IP Cluster:
  • Domain: test.ok
  • Synchronization folder: /sync