#!/usr/bin/perl

### Copyright 2003 AcornSoft ###

# Turn off buffering
$|=1;

$d = '';   # option variable with default value (false)
$r = '';       # option variable with default value (false)
$f = '';       # option variable with default value (false)

$ARGV_length=scalar @ARGV;
if(@ARGV) {
$f=$ARGV[0];
$d=$ARGV[1];
$r=$ARGV[2];
$mainHD=$ARGV[3];
$secondHD=$ARGV[4];
}

if($d) {
$d="$d";
}
else {
$d="";
}
if($f) {
$f="$f";
}
else {
$f="";
}
if($r) {
$r="$r";
}
else {
$r="";
}

if((substr($mainHD,0,1)) eq " ") {
$mainHD=~s/ //;
}

if(-d $mainHD && -d $secondHD) {

print `touch /var/log/psync.log`;
open(STDOUT, "| tee /var/log/psync.log");
$now=localtime();
print "Backup begun $now\n";
open(INPUT, "/usr/local/bin/psync $d $f $r '$mainHD' '$secondHD'|");

while(<INPUT>) {
print $_;
}
$now=localtime();
print "Backup completed: $now";
close INPUT;
close STDOUT;
} # end if
else {
open(FILE, ">/var/log/psync.log");
$now=localtime;
print FILE "$now\n";
print "$now\n";
print FILE "Backup drive wasn't connected\n\n";
print "One of the folders specified wasn't there (was your backup drive connected?)\n";
close FILE;
}
