1. Configure The Master
First we have to edit /etc/mysql/my.cnf

We have to enable networking for MySQL, and MySQL should listen on all IP addresses, therefore we comment out these lines (if existant):

#bind-address            =

Furthermorewe have to tell MySQL for which database it should write logs,which log file it should use, and we have to specify that this MySQLserver is the master. We want to replicate the database exampledb, so we put the following lines into /etc/mysql/my.cnf:

log-bin = /var/log/mysql/mysql-bin.log

# what database you want to replication



Then we restart MySQL:

/etc/init.d/mysql restart

Then we log into the MySQL database as root and create a user with replication privileges:

mysql -u root -p
Enter password:

GRANT REPLICATION SLAVE ON *.* TO ‘slave_user’@’%’ IDENTIFIED BY ‘<your_password>’;

Next do this:


Now leave the MySQL shell:

Continue Reading…

dd is a common Unix program whose primary purpose is the low-level copying and conversion of raw data.

dd is used to copy a specified number of bytes or blocks, performing on-the-fly byte order conversions, as well as more esoteric EBCDIC to ASCII conversions. dd can also be used to copy regions of raw device files, e.g. backing up the boot sector of a hard disk, or to read fixed amounts of data from special files like /dev/zero or /dev/random.

In this article i will provide you some practical examples on using dd command to backup the Linux system. dd is a powerful UNIX utility, which is used by the Linux kernel makefiles to make boot images. It can also be used to copy data.

1. Backup Entire Harddisk

dd if=/dev/sda of=/dev/sdb

  • “if” represents inputfile, and “of” represents output file. So the exact copy of /dev/sda will be available in /dev/sdb.
  • If there are any errors, the above command will fail. If you give the parameter “conv=noerror” then it will continue to copy if there are read errors.
  • Input file and output file should be mentioned very carefully, if you mention source device in the target and vice versa, you might loss all your data.

In the copy of hard drive to hard drive using dd command given below, sync option allows you to copy everything using synchronized I/O.

# dd if=/dev/sda of=/dev/sdb conv=noerror,sync

2. Create an Image of a Hard Disk

 dd if=/dev/hda of=~/hdadisk.img

3. Restore using Hard Disk Image

To restore a hard disk with the image file of an another hard disk, use the following dd command example.

 dd if=hdadisk.img of=/dev/hdb

The image file hdadisk.img file, is the image of a /dev/hda, so the above command will restore the image of /dev/hda to /dev/hdb.

4. Backup a Partition

dd if=/dev/hda1 of=~/partition1.img

5. CDROM Backup

dd command allows you to create an iso file from a source file. So we can insert the CD and enter dd command to create an iso file of a CD content.

 dd if=/dev/cdrom of=tgsservice.iso bs=2048

Fixing an unbootable computer after a failed grub installation can be a bit tricky.
Here’s what I ended up doing.

First of all, boot the machine up and get access to the root partition:

Step 1. Get a Debian installation CD for the same architecture
The distro version doesn’t matter too much: a lenny CD will boot squeeze just fine.

Step 2.Boot the install CD and select Rescue mode under Advanced options.

Step 3. Answer the language, keyboard and network questions any way you want and provide the decryption passphrases for any of the encrypted partitions you need to mount.

Step 4.When prompted, request a shell on the root partition:
If you need to upgrade the version of the grub package

a) Make sure that the network interface is up (ifup eth0).
b) Make sure that /etc/resolv.conf has at least one nameserver line, otherwise add one.
c) Install the latest version using apt-get or dpkg.

Step 5.Now that you have the right grub version, run the following


grub-install /dev/hda


Step 6.Finally, reboot.


In this example, each database will be stored separately and like earlier example we will save all databases and we will have the last 4 copies.

#Simple mySQL backup script for cron – updated version

# Modify the following to suit your environment
export DB_BACKUP=”/home/user/mysql_backup”
export DB_USER=”root”
export DB_PASSWD=”***********”
export DATE=”`date +”%d%b”`”
export MYSQL=”/usr/bin/mysql”
export MYSQLDUMP=”/usr/bin/mysqldump”

# Backup part
echo “mySQL_backup”
echo “———————-”
echo “* Rotating backups…”
rm -rf $DB_BACKUP/04
mkdir $DB_BACKUP/01

cd $DB_BACKUP/ && cd $DB_BACKUP/01
$MYSQL -u $DB_USER –password=$DB_PASSWD -Bse ‘show databases’ |while read m; \
do $MYSQLDUMP -u $DB_USER –password=$DB_PASSWD `echo $m` > `echo $m`.sql;done
bzip2 *sql

echo “* Creating new backup…”
echo “Backup done! `date`” > /tmp/my_report.log

# You can set the script to send you mail when backup it’s finished.
mail -s “MySql Backup report” [email protected] < /tmp/my_report.log
echo "----------------------"
echo "Done"
exit 0


Backs up all databases, saves the last 4 copies.


# modify the following :
export DB_BACKUP=”/home/user/mysql_backup/”
export DB_USER=”root”
export DB_PASSWD=”********”

echo “MySQL_Backup”
echo “———————-”
echo “* Rotating 4 backups…”
rm -rf $DB_BACKUP/04
mkdir $DB_BACKUP/01

echo “* Creating new backup…”
mysqldump –user=$DB_USER –password=$DB_PASSWD –all-databases | bzip2 > $DB_BACKUP/01/mysql-`date +%Y-%m-%d`.bz2
echo “———————-”
echo “Done”
exit 0

Page 2 of 3123