HowTo backup/Restore with dd / bzip2 and using split as optional.

#!/usr/bin/perl
#
#
#
#1. backup/restore
#2. block device from/whereto
#3. backup file storage
#4. split size in MBs(only when make backup).

my $type = $ARGV[0];
my $blockDev = $ARGV[1];
my $pathAndFile = $ARGV[2];
my $splitSize = $ARGV[3];

my $cmd;

if($#ARGV < 1)
  {
  print "Usage: dbackup <type> <blockDev> <path> [splitSize]\n";
  print "\n";
  print "<type> - can be \"backup\" or \"restore\"\n";
  print "\n";
  print "<blockDev> - it's the source for the backup or destination for
restore\n";
  print "  ie. /dev/sda for full backup of sas/sata.\n";
  print "  ie. /dev/hda for full backup of IDE/ATA\n";
  print "  ie. /dev/hda1 for first partition backup etc.\n";
  print "\n";
  print "<path> -  it's the destionation for backup or source for the
restore.\n";
  print "  ie. /mnt/gentoo/backup-2012-01-08\n";
  print "  if backup is splitted into the parts, use basename without
subpart suffixes\n";
  print "  ie. /mnt/gentoo/backup-2012-01-08  is the base, but parts are
named like:\n";
  print "  1. /mnt/gentoo/backup-2012-01-08aa\n";
  print "  2. /mnt/gentoo/backup-2012-01-08ab\n";
  print "  3. /mnt/gentoo/backup-2012-01-08ac\n";
  print "\n";
  print "[splitSize] - it's optional argument and used only when
type=backup. It defines\n";
  print "  the maximum size (in MegaBytes) of parts used for split
process.\n";
  }

if($splitSize)
  {
  $splitSize = $splitSize * 1000 * 1000;
  }

if($type eq "backup")
  {
  if($splitSize)
    {
    $cmd = "dd if=$blockDev |bzip2 -c |split -b $splitSize -
$pathAndFile";
    }
  else
    {
    $cmd = "dd if=$blockDev |bzip2 -c |dd of=$pathAndFile";
    }
  system($cmd);
  }

if($type eq "restore")
  {
  $pathAndFile .= "*";
  $cmd = "cat $pathAndFile |bzip2 -c -d |dd of=$blockDev";
  system($cmd);
  }