Running a backup script on a server system as a webhosting server can produce high load and longer latencys for other processes  or php pages load slow during backup because the backup script takes too much  CPU resources.

On Linux systems there are many utilities available for the programming to set the CPU for a appliaction or a script.

In this tutorial we will use nice.

To reduce the CPU priority, use the following command:

/usr/bin/nice -n 19 /location/of/your/script/

The -n parameter can be in the range from -20 to 19.  Lower numbers means higher priority.


Rsync is often used for backup systems, with options such as:

-A --acls       : preserve the ACL, if used

-X --xattrs     : preserve extended attributes, if used

-H --hard-links : detect and preserve hard links

-a --archive    : resources and preserve the usual attributes: symbolic links, devices and special files,
user and group ownership, permissions and schedules

In addition to these stock options, rsync has many other.

Each has its own recipe, but I’d like to share two useful features :

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

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


There is a better, quicker way to do this which is to clone your entire drive onto a new drive.

You can do this with a tool like GParted, but there is also a command line tool that will get the job done as well. This tool is ddrescue. Now with ddrescue you will have to have your new disc partitioned (it will not partition for you). In this article I am going to show you how to get your dying Linux drive cloned onto a new drive.

Installation of ddrescue:

apt-get install ddrescue gparted

Paritioning your new drive:

After you installed the new drive reboot your server. Then do the following:

  1. Start GParted.
  2. Create a partition scheme on the new drive  identical with the old drive.
  3. Save the new partition scheme and you are ready to clone.

Continue Reading…

Page 1 of 11