#!/usr/local/bin/perl -w

$program="counter";
$cgibinsrc = "/home/httpd/cgi-bin/www-servers/$program";
$docssrc = "/home/httpd/docs/www-servers/$program";


# month-day-hour-minute-sec
$date=((localtime)[4]+1)."-".(localtime)[3]."-".(localtime)[2]."-".(localtime)[1]."-".(localtime)[0];
$trg = "$cgibinsrc/backup/$date";
system("mkdir $trg");

# Copy cgi-bin area
foreach $file (`ls $cgibinsrc/`){
chomp $file;
 if ($file =~ /backup/) {next;}
 if (-d "$cgibinsrc/$file") {system "cp -r $cgibinsrc/$file $trg";next}
 system "cp  $cgibinsrc/$file $trg";
}

# Copy plain html files
  system("cp -r $docssrc $trg");

chdir  "$cgibinsrc/backup";
system("tar -cvf $date.tar $date");
system("gzip $date.tar");
system("mv $date.tar.gz $program-$date.tgz");

# Now destroy the whole directory since we have the backup packed tgz
system("rm -r $date")
